Tracking NSBrowser selection
15/06/11 21:23
Before 10.6, it was not easy to do, subclassing the browser cell was one way to do it, but since 10.6 it's easier, here is how to…
Introduced in 10.6:
- (NSIndexSet *)browser:(NSBrowser *)browser selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes inColumn:(NSInteger)column
By implementing this method in your delegate/datasource, you can test if the selection will be empty after the processing of the proposed index will be done:
BOOL willGoNoSelection = (column == 0) && ([proposedSelectionIndexes count] == 0) ;
and then, according to your needs, turn on/off UI items. The initial state of these items remain to be set up in some "init" method: only you know if the selection is empty at start of the browsing session or not.
- (NSIndexSet *)browser:(NSBrowser *)browser selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes inColumn:(NSInteger)column
By implementing this method in your delegate/datasource, you can test if the selection will be empty after the processing of the proposed index will be done:
BOOL willGoNoSelection = (column == 0) && ([proposedSelectionIndexes count] == 0) ;
and then, according to your needs, turn on/off UI items. The initial state of these items remain to be set up in some "init" method: only you know if the selection is empty at start of the browsing session or not.