Make dialog.showSaveDialog accept a callback.

This commit is contained in:
Cheng Zhao 2013-09-23 20:08:49 +08:00
parent c7637c78d1
commit 26f0e49c9a

View file

@ -180,7 +180,7 @@ v8::Handle<v8::Value> ShowOpenDialog(const v8::Arguments &args) {
title, title,
default_path, default_path,
properties, properties,
base::Bind(&CallV8Function2<const std::vector<base::FilePath>>, base::Bind(&CallV8Function2<const std::vector<base::FilePath>&>,
callback)); callback));
return v8::Undefined(); return v8::Undefined();
} }
@ -202,17 +202,33 @@ v8::Handle<v8::Value> ShowSaveDialog(const v8::Arguments &args) {
native_window = window->window(); native_window = window->window();
} }
v8::Persistent<v8::Function> callback;
if (args[3]->IsFunction()) {
callback = v8::Persistent<v8::Function>::New(
node_isolate,
v8::Local<v8::Function>::Cast(args[3]));
}
std::string title(*v8::String::Utf8Value(args[0])); std::string title(*v8::String::Utf8Value(args[0]));
base::FilePath default_path(V8ValueToFilePath(args[1])); base::FilePath default_path(V8ValueToFilePath(args[1]));
base::FilePath path; if (callback.IsEmpty()) {
if (!file_dialog::ShowSaveDialog(native_window, base::FilePath path;
title, if (!file_dialog::ShowSaveDialog(native_window,
default_path, title,
&path)) default_path,
return v8::Undefined(); &path))
return v8::Undefined();
return scope.Close(ToV8Value(path)); return scope.Close(ToV8Value(path));
} else {
file_dialog::ShowSaveDialog(
native_window,
title,
default_path,
base::Bind(&CallV8Function2<const base::FilePath&>, callback));
return v8::Undefined();
}
} }
} // namespace api } // namespace api