Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep an NSPathControl updated with the path of the selected cell in an NSBrowser

I need to keep an NSPathControl updated with the currently selected path in an NSBrowser, but I'm having trouble figuring out a way of getting notifications when the path has changed from the NSBrowser. The ideal way to do this would just to be to observe the path key path in the NSBrowser, but that gives a KVO can only observe set<key> methods which return void message and no updates (setPath returns a bool success value).

I also tried observing the selectedCell key path, but I'm not getting notifications when the selection there is changed.

Is there some other really obvious way to do this that I'm missing?

like image 888
Lawrence Johnston Avatar asked Dec 09 '08 23:12

Lawrence Johnston


1 Answers

Courtesy of Rob Keniger over at Cocoa Dev:

Have you looked at the SimpleBrowser example in /Developer/Examples? It shows how to get the current selection when it is changed by the user, basically by just setting up the action of the NSBrowser.

That is indeed the way to do it. Just implement a method like - (void)browserClicked: in your controller and map it to the NSBrowser's action in interface builder with whatever you want to happen each time the selection changes inside that method, e.g.

- (void)browserClicked:(id)browser {
    self.pathToSelectedCell = [browser path]; // NSPathControl is bound to pathToSelectedCell
}
like image 115
Lawrence Johnston Avatar answered Nov 03 '22 23:11

Lawrence Johnston