Overriding shortcut keys in the NSOpenPanel or NSSavePanel

Apple, Cocoa, Coding

It recently came up where someone needed to override some of the default shortcut keys in the NSOpenPanel or NSSavePanel. This is quite trivial to do. First off, the “easy way” would be to add a hidden NSPopUpButton in an accessory view that has the appropriate shortcuts. However, that won’t override the defaults (ie: cmd-r == reveal in finder, cmd-i == finder info window, cmd-a == select all, etc). To override these, you would subclass the appropriate panel:

@interface MyOpenPanel : NSOpenPanel

@end

@implementation MyOpenPanel

– (BOOL)performKeyEquivalent:(NSEvent *)theEvent {

NSLog(@”…test”); // an example of where you would do your key testing

return [super performKeyEquivalent:theEvent];

}

@end

You would then use it via something like:

[MyOpenPanel openPanel]


Easy to do…

Previous in programming
no_thumbnail
Leopard: PhotoSearch demo app now live
Next in programming
no_thumbnail
Cocoa: willDisplayCell delegate method of NSTableView, [NSCell setTextColor], and "source lists"

Leave a Reply

avatar
500
  Subscribe  
Notify of

(c) 2008-2019 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

72 queries. 0.338 seconds.

Log in