From 914ec8a904800e9fe478217b49797a8e77514260 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 24 Jun 2008 21:32:31 +0200 Subject: [PATCH] Add "show hidden files" checkbox to open file dialog --- src/MacVim/MMAppController.h | 2 ++ src/MacVim/MMAppController.m | 30 ++++++++++++++++++++++++++++++ src/MacVim/MMVimController.m | 3 +++ src/MacVim/MacVim.h | 8 ++++++++ src/MacVim/MacVim.m | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+) diff --git a/src/MacVim/MMAppController.h b/src/MacVim/MMAppController.h index fcec67f6..cef65b43 100644 --- a/src/MacVim/MMAppController.h +++ b/src/MacVim/MMAppController.h @@ -41,4 +41,6 @@ - (IBAction)showVimHelp:(id)sender; - (IBAction)zoomAll:(id)sender; +- (NSView *)accessoryView; + @end diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index a1244168..8831b43d 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -701,6 +701,8 @@ static int executeInLoginShell(NSString *path, NSArray *args); NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setAllowsMultipleSelection:YES]; + [panel setAccessoryView:[self accessoryView]]; + int result = [panel runModalForDirectory:dir file:nil types:nil]; if (NSOKButton == result) [self application:NSApp openFiles:[panel filenames]]; @@ -772,6 +774,34 @@ static int executeInLoginShell(NSString *path, NSArray *args); [NSApp makeWindowsPerform:@selector(performZoom:) inOrder:YES]; } +- (NSView *)accessoryView +{ + // Return a new button object for each NSOpenPanel -- several of them + // could be displayed at once. + // If the accessory view should get more complex, it should probably be + // loaded from a nib file. + NSButton *button = [[[NSButton alloc] + initWithFrame:NSMakeRect(0, 0, 140, 18)] autorelease]; + [button setTitle: + NSLocalizedString(@"Show Hidden Files", @"Open File Dialog")]; + [button setButtonType:NSSwitchButton]; + + [button setTarget:nil]; + [button setAction:@selector(hiddenFilesButtonToggled:)]; + + // use the regular control size (checkbox is a bit smaller without this) + NSControlSize buttonSize = NSRegularControlSize; + float fontSize = [NSFont systemFontSizeForControlSize:buttonSize]; + NSCell *theCell = [button cell]; + NSFont *theFont = [NSFont fontWithName:[[theCell font] fontName] + size:fontSize]; + [theCell setFont:theFont]; + [theCell setControlSize:buttonSize]; + [button sizeToFit]; + + return button; +} + - (byref id ) connectBackend:(byref in id )backend pid:(int)pid diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 130a5104..8ccd902c 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -414,6 +414,9 @@ static BOOL isUnsafeMessage(int msgid); } else { NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setAllowsMultipleSelection:NO]; + [panel setAccessoryView: + [[MMAppController sharedInstance] accessoryView]]; + [panel beginSheetForDirectory:dir file:nil types:nil modalForWindow:[windowController window] modalDelegate:self diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 1d398689..0a4148be 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -301,6 +301,14 @@ NSString *buildSearchTextCommand(NSString *searchText); +@interface NSOpenPanel (MMExtras) +- (void)hiddenFilesButtonToggled:(id)sender; +- (void)setShowsHiddenFiles:(BOOL)show; +@end + + + + // ODB Editor Suite Constants (taken from ODBEditorSuite.h) #define keyFileSender 'FSnd' #define keyFileSenderToken 'FTok' diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index c82d1ac7..b96af131 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -333,3 +333,37 @@ buildSearchTextCommand(NSString *searchText) } @end + + + + +@implementation NSOpenPanel (MMExtras) + +- (void)hiddenFilesButtonToggled:(id)sender +{ + [self setShowsHiddenFiles:[sender intValue]]; +} + +- (void)setShowsHiddenFiles:(BOOL)show +{ + // This is undocumented stuff, so be careful. This does the same as + // [[self _navView] setShowsHiddenFiles:show]; + // but does not produce warnings. + + if (![self respondsToSelector:@selector(_navView)]) + return; + + id navView = [self performSelector:@selector(_navView)]; + if (![navView respondsToSelector:@selector(setShowsHiddenFiles:)]) + return; + + // performSelector:withObject: does not support a BOOL + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: + [navView methodSignatureForSelector:@selector(setShowsHiddenFiles:)]]; + [invocation setTarget:navView]; + [invocation setSelector:@selector(setShowsHiddenFiles:)]; + [invocation setArgument:&show atIndex:2]; + [invocation invoke]; +} + +@end -- 2.11.4.GIT