macOS: Add "Show hidden files" button to native file chooser

This commit is contained in:
ManoloFLTK 2022-12-15 12:10:41 +01:00
parent 64d8c913be
commit 2fd1866f49

View File

@ -551,12 +551,48 @@ static char *prepareMacFilter(int count, const char *filter, char **patterns) {
}
@end
@interface FLHiddenFilesAction : NSObject
{
@public
NSSavePanel *panel;
NSButton *button;
}
- (void)action;
@end
@implementation FLHiddenFilesAction
- (void)action {
[panel setShowsHiddenFiles:[button intValue]];
}
@end
static NSPopUpButton *createPopupAccessory(NSSavePanel *panel, const char *filter, const char *title, int rank)
{
NSPopUpButton *popup;
NSRect rectview = NSMakeRect(5, 5, 350, 30 );
NSRect rectview = NSMakeRect(5, 5, 350, filter ? 60 : 30);
NSView *view = [[[NSView alloc] initWithFrame:rectview] autorelease];
NSRect rectbox = NSMakeRect(0, 3, 140, 20 );
// the "Show hidden files" button
NSRect hidden_files_rect = {{150, (filter ? 35 : 0)}, {80, 30}};
NSButton *hidden_files = [[[NSButton alloc] initWithFrame:hidden_files_rect] autorelease];
[hidden_files setButtonType:
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
NSButtonTypeSwitch
#else
NSSwitchButton
#endif
];
[hidden_files setTitle:[NSString stringWithUTF8String:Fl_File_Chooser::hidden_label]];
[hidden_files sizeToFit];
[hidden_files setIntValue:0];
[view addSubview:hidden_files];
static FLHiddenFilesAction *target = [[FLHiddenFilesAction alloc] init]; // never released
target->panel = panel;
target->button = hidden_files;
[hidden_files setAction:@selector(action)];
[hidden_files setTarget:target];
if (filter) {
NSBox *box = [[[NSBox alloc] initWithFrame:rectbox] autorelease];
NSRect rectpop = NSMakeRect(105, 0, 246, 30 );
popup = [[[NSPopUpButton alloc ] initWithFrame:rectpop pullsDown:NO] autorelease];
@ -585,6 +621,7 @@ static NSPopUpButton *createPopupAccessory(NSSavePanel *panel, const char *filte
if (item) [popup removeItemWithTitle:@""];
CFRelease(array);
[popup selectItemAtIndex:rank];
}
[panel setAccessoryView:view];
return popup;
}
@ -710,7 +747,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() {
FLopenDelegate *openDelegate = [[[FLopenDelegate alloc] init] autorelease];
[openDelegate setPopup:popup filter_pattern:_filt_patt];
[_panel setDelegate:openDelegate];
}
} else createPopupAccessory(_panel, NULL, Fl_File_Chooser::show_label, 0);
}
else {
FLsaveDelegate *saveDelegate = [[[FLsaveDelegate alloc] init] autorelease];
@ -738,7 +775,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() {
}
[_panel setCanSelectHiddenExtension:YES];
[_panel setExtensionHidden:NO];
}
} else createPopupAccessory(_panel, NULL, Fl_File_Chooser::show_label, 0);
}
int retval = runmodal();
if (_filt_total) {