From 43b492c64130d50351587df05e234dfa201112dd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Sep 2013 19:36:52 +0800 Subject: [PATCH] mac: make ShowSaveDialog accept no parent window. --- browser/ui/file_dialog_mac.mm | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/browser/ui/file_dialog_mac.mm b/browser/ui/file_dialog_mac.mm index 539fe91..0770d0e 100644 --- a/browser/ui/file_dialog_mac.mm +++ b/browser/ui/file_dialog_mac.mm @@ -120,11 +120,10 @@ void ShowOpenDialog(atom::NativeWindow* parent_window, }]; } -bool ShowSaveDialog(atom::NativeWindow* window, +bool ShowSaveDialog(atom::NativeWindow* parent_window, const std::string& title, const base::FilePath& default_path, base::FilePath* path) { - DCHECK(window); DCHECK(path); NSSavePanel* dialog = [NSSavePanel savePanel]; @@ -132,25 +131,26 @@ bool ShowSaveDialog(atom::NativeWindow* window, [dialog setCanSelectHiddenExtension:YES]; - __block bool result = false; - __block base::FilePath ret_path; - [dialog beginSheetModalForWindow:window->GetNativeWindow() - completionHandler:^(NSInteger chosen) { - if (chosen == NSFileHandlingPanelCancelButton || - ![[dialog URL] isFileURL]) { - result = false; - } else { - result = true; - ret_path = base::FilePath(base::SysNSStringToUTF8([[dialog URL] path])); - } + __block int chosen = -1; - [NSApp stopModal]; - }]; + if (parent_window == NULL) { + chosen = [dialog runModal]; + } else { + NSWindow* window = parent_window->GetNativeWindow(); - [NSApp runModalForWindow:window->GetNativeWindow()]; + [dialog beginSheetModalForWindow:window + completionHandler:^(NSInteger c) { + chosen = c; + [NSApp stopModal]; + }]; + [NSApp runModalForWindow:window]; + } + + if (chosen == NSFileHandlingPanelCancelButton || ![[dialog URL] isFileURL]) + return false; - *path = ret_path; - return result; + *path = base::FilePath(base::SysNSStringToUTF8([[dialog URL] path])); + return true; } } // namespace file_dialog -- 2.7.4