mac: Make ShowOpenDialog able to be shown as sheet.

This commit is contained in:
Cheng Zhao 2013-09-23 16:27:22 +08:00
parent 85d6588661
commit a4262bc39d
3 changed files with 26 additions and 5 deletions

View file

@ -124,7 +124,11 @@ v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments &args) {
int properties = args[2]->IntegerValue();
std::vector<base::FilePath> paths;
if (!file_dialog::ShowOpenDialog(title, default_path, properties, &paths))
if (!file_dialog::ShowOpenDialog(NULL,
title,
default_path,
properties,
&paths))
return v8::Undefined();
v8::Handle<v8::Array> result = v8::Array::New(paths.size());

View file

@ -23,12 +23,13 @@ enum FileDialogProperty {
FILE_DIALOG_CREATE_DIRECTORY = 8,
};
bool ShowOpenDialog(const std::string& title,
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
int properties,
std::vector<base::FilePath>* paths);
bool ShowSaveDialog(atom::NativeWindow* window,
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
base::FilePath* path);

View file

@ -43,7 +43,8 @@ void SetupDialog(NSSavePanel* dialog,
} // namespace
bool ShowOpenDialog(const std::string& title,
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
int properties,
std::vector<base::FilePath>* paths) {
@ -60,7 +61,22 @@ bool ShowOpenDialog(const std::string& title,
if (properties & FILE_DIALOG_MULTI_SELECTIONS)
[dialog setAllowsMultipleSelection:YES];
if ([dialog runModal] == NSFileHandlingPanelCancelButton)
__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)
return false;
NSArray* urls = [dialog URLs];