From d8528cbaf59dfc205660141abf5b44d9ea76d71f Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Mon, 13 Apr 2009 13:48:54 +0200 Subject: [PATCH] Add "show hidden files" checkbox to save dialog --- src/MacVim/MMAppController.m | 2 +- src/MacVim/MMVimController.m | 25 +++++++++++++++++++++++-- src/MacVim/Miscellaneous.h | 9 +++++---- src/MacVim/Miscellaneous.m | 10 +++++----- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 0aad826f..83190055 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -998,7 +998,7 @@ fsEventCallback(ConstFSEventStreamRef streamRef, NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setAllowsMultipleSelection:YES]; - [panel setAccessoryView:openPanelAccessoryView()]; + [panel setAccessoryView:showHiddenFilesView()]; int result = [panel runModalForDirectory:dir file:nil types:nil]; if (NSOKButton == result) diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 3f677aa4..afdbfb3b 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -1252,6 +1252,18 @@ static BOOL isUnsafeMessage(int msgid); afterDelay:0]; } +// NSSavePanel delegate +- (void)panel:(id)sender willExpand:(BOOL)expanding +{ + // Show or hide the "show hidden files" button + if (expanding) { + [sender setAccessoryView:showHiddenFilesView()]; + } else { + [sender setShowsHiddenFiles:NO]; + [sender setAccessoryView:nil]; + } +} + - (void)handleBrowseForFile:(NSDictionary *)attr { if (!isInitialized) return; @@ -1269,7 +1281,16 @@ static BOOL isUnsafeMessage(int msgid); } if (saving) { - [[NSSavePanel savePanel] beginSheetForDirectory:dir file:nil + NSSavePanel *panel = [NSSavePanel savePanel]; + + // The delegate will be notified when the panel is expanded at which + // time we may hide/show the "show hidden files" button (this button is + // always visible for the open panel since it is always expanded). + [panel setDelegate:self]; + if ([panel isExpanded]) + [panel setAccessoryView:showHiddenFilesView()]; + + [panel beginSheetForDirectory:dir file:nil modalForWindow:[windowController window] modalDelegate:self didEndSelector:@selector(savePanelDidEnd:code:context:) @@ -1277,7 +1298,7 @@ static BOOL isUnsafeMessage(int msgid); } else { NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setAllowsMultipleSelection:NO]; - [panel setAccessoryView:openPanelAccessoryView()]; + [panel setAccessoryView:showHiddenFilesView()]; [panel beginSheetForDirectory:dir file:nil types:nil modalForWindow:[windowController window] diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h index d19accd7..9e8da015 100644 --- a/src/MacVim/Miscellaneous.h +++ b/src/MacVim/Miscellaneous.h @@ -95,7 +95,7 @@ enum { @end -@interface NSOpenPanel (MMExtras) +@interface NSSavePanel (MMExtras) - (void)hiddenFilesButtonToggled:(id)sender; - (void)setShowsHiddenFiles:(BOOL)show; @end @@ -130,7 +130,8 @@ enum { -// Create a view to be used as accessory for open panel. This function assumes -// ownership of the view so do not release it. -NSView *openPanelAccessoryView(); +// Create a view with a "show hidden files" button to be used as accessory for +// open/save panels. This function assumes ownership of the view so do not +// release it. +NSView *showHiddenFilesView(); diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m index 4e071300..44f66229 100644 --- a/src/MacVim/Miscellaneous.m +++ b/src/MacVim/Miscellaneous.m @@ -93,7 +93,7 @@ NSString *MMLoadDefaultFontKey = @"MMLoadDefaultFont"; -@implementation NSOpenPanel (MMExtras) +@implementation NSSavePanel (MMExtras) - (void)hiddenFilesButtonToggled:(id)sender { @@ -122,7 +122,7 @@ NSString *MMLoadDefaultFontKey = @"MMLoadDefaultFont"; [invocation invoke]; } -@end // NSOpenPanel (MMExtras) +@end // NSSavePanel (MMExtras) @@ -263,7 +263,7 @@ NSString *MMLoadDefaultFontKey = @"MMLoadDefaultFont"; NSView * -openPanelAccessoryView() +showHiddenFilesView() { // Return a new button object for each NSOpenPanel -- several of them // could be displayed at once. @@ -272,13 +272,13 @@ openPanelAccessoryView() NSButton *button = [[[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 140, 18)] autorelease]; [button setTitle: - NSLocalizedString(@"Show Hidden Files", @"Open File Dialog")]; + NSLocalizedString(@"Show Hidden Files", @"Show Hidden Files Checkbox")]; [button setButtonType:NSSwitchButton]; [button setTarget:nil]; [button setAction:@selector(hiddenFilesButtonToggled:)]; - // use the regular control size (checkbox is a bit smaller without this) + // Use the regular control size (checkbox is a bit smaller without this) NSControlSize buttonSize = NSRegularControlSize; float fontSize = [NSFont systemFontSizeForControlSize:buttonSize]; NSCell *theCell = [button cell]; -- 2.11.4.GIT