💄 Pick duplicate code together.
This commit is contained in:
parent
43b492c641
commit
e824b6c910
1 changed files with 22 additions and 32 deletions
|
@ -38,6 +38,7 @@ void SetupDialog(NSSavePanel* dialog,
|
||||||
if (default_filename)
|
if (default_filename)
|
||||||
[dialog setNameFieldStringValue:default_filename];
|
[dialog setNameFieldStringValue:default_filename];
|
||||||
|
|
||||||
|
[dialog setCanSelectHiddenExtension:YES];
|
||||||
[dialog setAllowsOtherFileTypes:YES];
|
[dialog setAllowsOtherFileTypes:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +52,25 @@ void SetupDialogForProperties(NSOpenPanel* dialog, int properties) {
|
||||||
[dialog setAllowsMultipleSelection:YES];
|
[dialog setAllowsMultipleSelection:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run modal dialog with parent window and return user's choice.
|
||||||
|
int RunModalDialog(NSSavePanel* dialog, atom::NativeWindow* parent_window) {
|
||||||
|
__block int chosen = NSFileHandlingPanelCancelButton;
|
||||||
|
if (parent_window == NULL) {
|
||||||
|
chosen = [dialog runModal];
|
||||||
|
} else {
|
||||||
|
NSWindow* window = parent_window->GetNativeWindow();
|
||||||
|
|
||||||
|
[dialog beginSheetModalForWindow:window
|
||||||
|
completionHandler:^(NSInteger c) {
|
||||||
|
chosen = c;
|
||||||
|
[NSApp stopModal];
|
||||||
|
}];
|
||||||
|
[NSApp runModalForWindow:window];
|
||||||
|
}
|
||||||
|
|
||||||
|
return chosen;
|
||||||
|
}
|
||||||
|
|
||||||
void ReadDialogPaths(NSOpenPanel* dialog, std::vector<base::FilePath>* paths) {
|
void ReadDialogPaths(NSOpenPanel* dialog, std::vector<base::FilePath>* paths) {
|
||||||
NSArray* urls = [dialog URLs];
|
NSArray* urls = [dialog URLs];
|
||||||
for (NSURL* url in urls)
|
for (NSURL* url in urls)
|
||||||
|
@ -71,21 +91,7 @@ bool ShowOpenDialog(atom::NativeWindow* parent_window,
|
||||||
SetupDialog(dialog, title, default_path);
|
SetupDialog(dialog, title, default_path);
|
||||||
SetupDialogForProperties(dialog, properties);
|
SetupDialogForProperties(dialog, properties);
|
||||||
|
|
||||||
__block int chosen = -1;
|
int chosen = RunModalDialog(dialog, parent_window);
|
||||||
|
|
||||||
if (parent_window == NULL) {
|
|
||||||
chosen = [dialog runModal];
|
|
||||||
} else {
|
|
||||||
NSWindow* window = parent_window->GetNativeWindow();
|
|
||||||
|
|
||||||
[dialog beginSheetModalForWindow:window
|
|
||||||
completionHandler:^(NSInteger c) {
|
|
||||||
chosen = c;
|
|
||||||
[NSApp stopModal];
|
|
||||||
}];
|
|
||||||
[NSApp runModalForWindow:window];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chosen == NSFileHandlingPanelCancelButton)
|
if (chosen == NSFileHandlingPanelCancelButton)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -129,23 +135,7 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
|
|
||||||
SetupDialog(dialog, title, default_path);
|
SetupDialog(dialog, title, default_path);
|
||||||
|
|
||||||
[dialog setCanSelectHiddenExtension:YES];
|
int chosen = RunModalDialog(dialog, parent_window);
|
||||||
|
|
||||||
__block int chosen = -1;
|
|
||||||
|
|
||||||
if (parent_window == NULL) {
|
|
||||||
chosen = [dialog runModal];
|
|
||||||
} else {
|
|
||||||
NSWindow* window = parent_window->GetNativeWindow();
|
|
||||||
|
|
||||||
[dialog beginSheetModalForWindow:window
|
|
||||||
completionHandler:^(NSInteger c) {
|
|
||||||
chosen = c;
|
|
||||||
[NSApp stopModal];
|
|
||||||
}];
|
|
||||||
[NSApp runModalForWindow:window];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL])
|
if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL])
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue