{"id":268,"date":"2007-12-11T10:16:38","date_gmt":"2007-12-11T17:16:38","guid":{"rendered":"http:\/\/www.corbinstreehouse.com\/blog\/?p=268"},"modified":"2018-10-23T18:09:17","modified_gmt":"2018-10-24T01:09:17","slug":"overriding-shortcut-keys-in-the-nsopenpanel-or-nssavepanel","status":"publish","type":"post","link":"https:\/\/www.corbinstreehouse.com\/blog\/2007\/12\/overriding-shortcut-keys-in-the-nsopenpanel-or-nssavepanel\/","title":{"rendered":"Overriding shortcut keys in the NSOpenPanel or NSSavePanel"},"content":{"rendered":"<p id=\"top\" \/>\n<p>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 &#8220;easy way&#8221; would be to add a hidden NSPopUpButton in an accessory view that has the appropriate shortcuts. However, that won&#8217;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:<\/p>\n<p><span style=\"font-family: Monaco; font-size: 10px;\"><\/span><span style=\"color: #aa0d91\">@interface<\/span> MyOpenPanel : NSOpenPanel<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><span style=\"color: #AA0D91;\">@end<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91\">@implementation <span style=\"color: #000000\">MyOpenPanel<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\">&#8211; (<span style=\"color: #aa0d91\">BOOL<\/span>)performKeyEquivalent:(<span style=\"color: #5c2699\">NSEvent<\/span> *)theEvent {<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #007400\"><span style=\"color: #2e0d6e\">NSLog<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #c41a16\">@&#8221;&#8230;test&#8221;<\/span><span style=\"color: #000000\">);<\/span> \/\/ an example of where you would do your key testing<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #2e0d6e\"><span style=\"color: #aa0d91\">return<\/span> <span style=\"color: #000000\">[<\/span><span style=\"color: #aa0d91\">super<\/span> performKeyEquivalent<span style=\"color: #000000\">:theEvent];<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco\">}<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px\"><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91\">@end<\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91\"><\/p>\n<p style=\"margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: 10px Monaco;\"><span style=\"font-family: Helvetica; font-size: 12px;\">You would then use it via something like:<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91\"><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #aa0d91\">\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74\"><span style=\"color: #000000\">[<\/span>MyOpenPanel <span style=\"color: #2e0d6e\">openPanel<\/span><span style=\"color: #000000\">]<\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74\"><span style=\"color: #000000;\"><br \/><\/span><\/p>\n<p style=\"margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #3f6e74\"><span style=\"color: #000000;\"><\/span><span style=\"font-family: Helvetica; font-size: 12px;\">Easy to do&#8230;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8220;easy way&#8221; would be to add&#8230; <a class=\"read-more\" href=\"https:\/\/www.corbinstreehouse.com\/blog\/2007\/12\/overriding-shortcut-keys-in-the-nsopenpanel-or-nssavepanel\/\">[read more]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[4,6,86],"tags":[72],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-apple","category-cocoa","category-coding","tag-programming"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/comments?post=268"}],"version-history":[{"count":1,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"predecessor-version":[{"id":5179,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/posts\/268\/revisions\/5179"}],"wp:attachment":[{"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.corbinstreehouse.com\/blog\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}