mac: Add asynchronous ShowSaveDialog.

This commit is contained in:
Cheng Zhao 2013-09-23 20:08:32 +08:00
parent 30ca085fd8
commit c7637c78d1
2 changed files with 31 additions and 1 deletions

View file

@ -25,7 +25,10 @@ enum FileDialogProperty {
};
typedef base::Callback<void(
bool result, std::vector<base::FilePath> paths)> OpenDialogCallback;
bool result, const std::vector<base::FilePath>& paths)> OpenDialogCallback;
typedef base::Callback<void(
bool result, const base::FilePath& path)> SaveDialogCallback;
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
@ -44,6 +47,11 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
const base::FilePath& default_path,
base::FilePath* path);
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
const SaveDialogCallback& callback);
} // namespace file_dialog
#endif // BROWSER_UI_FILE_DIALOG_H_

View file

@ -143,4 +143,26 @@ bool ShowSaveDialog(atom::NativeWindow* parent_window,
return true;
}
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
const SaveDialogCallback& c) {
NSSavePanel* dialog = [NSSavePanel savePanel];
SetupDialog(dialog, title, default_path);
__block SaveDialogCallback callback = c;
NSWindow* window = parent_window ? parent_window->GetNativeWindow() : NULL;
[dialog beginSheetModalForWindow:window
completionHandler:^(NSInteger chosen) {
if (chosen == NSFileHandlingPanelCancelButton) {
callback.Run(false, base::FilePath());
} else {
std::string path = base::SysNSStringToUTF8([[dialog URL] path]);
callback.Run(true, base::FilePath(path));
}
}];
}
} // namespace file_dialog