mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-11 15:37:29 +02:00
Add "show hidden files" checkbox to open file dialog
This commit is contained in:
committed by
Bjorn Winckler
parent
79ec8a039d
commit
b391feee88
@@ -41,4 +41,6 @@
|
||||
- (IBAction)showVimHelp:(id)sender;
|
||||
- (IBAction)zoomAll:(id)sender;
|
||||
|
||||
- (NSView *)accessoryView;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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 <MMFrontendProtocol>)
|
||||
connectBackend:(byref in id <MMBackendProtocol>)backend
|
||||
pid:(int)pid
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user