// found in the LICENSE file.
#include <string>
+#include <utility>
#include <vector>
#include "atom/browser/api/atom_api_window.h"
#include "atom/common/node_includes.h"
+namespace mate {
+
+template<>
+struct Converter<file_dialog::Filter> {
+ static bool FromV8(v8::Isolate* isolate,
+ v8::Handle<v8::Value> val,
+ file_dialog::Filter* out) {
+ mate::Dictionary dict(isolate);
+ if (!ConvertFromV8(isolate, val, &dict))
+ return false;
+ if (!dict.Get("name", &(out->first)))
+ return false;
+ if (!dict.Get("extensions", &(out->second)))
+ return false;
+ return true;
+ }
+};
+
+} // namespace mate
+
namespace {
void ShowMessageBox(int type,
void ShowOpenDialog(const std::string& title,
const base::FilePath& default_path,
+ const file_dialog::Filters& filters,
int properties,
atom::NativeWindow* window,
mate::Arguments* args) {
if (mate::Converter<file_dialog::OpenDialogCallback>::FromV8(args->isolate(),
peek,
&callback)) {
- file_dialog::ShowOpenDialog(window, title, default_path, properties,
- callback);
+ file_dialog::ShowOpenDialog(window, title, default_path, filters,
+ properties, callback);
} else {
std::vector<base::FilePath> paths;
- if (file_dialog::ShowOpenDialog(window, title, default_path, properties,
- &paths))
+ if (file_dialog::ShowOpenDialog(window, title, default_path, filters,
+ properties, &paths))
args->Return(paths);
}
}
void ShowSaveDialog(const std::string& title,
const base::FilePath& default_path,
+ const file_dialog::Filters& filters,
atom::NativeWindow* window,
mate::Arguments* args) {
v8::Handle<v8::Value> peek = args->PeekNext();
if (mate::Converter<file_dialog::SaveDialogCallback>::FromV8(args->isolate(),
peek,
&callback)) {
- file_dialog::ShowSaveDialog(window, title, default_path, callback);
+ file_dialog::ShowSaveDialog(window, title, default_path, filters, callback);
} else {
base::FilePath path;
- if (file_dialog::ShowSaveDialog(window, title, default_path, &path))
+ if (file_dialog::ShowSaveDialog(window, title, default_path, filters,
+ &path))
args->Return(path);
}
}
options.title ?= ''
options.defaultPath ?= ''
+ options.filters ?= []
wrappedCallback =
if typeof callback is 'function'
binding.showOpenDialog String(options.title),
String(options.defaultPath),
+ options.filters
properties,
window,
wrappedCallback
options ?= title: 'Save'
options.title ?= ''
options.defaultPath ?= ''
+ options.filter ?= []
wrappedCallback =
if typeof callback is 'function'
binding.showSaveDialog String(options.title),
String(options.defaultPath),
+ options.filters
window,
wrappedCallback
if (it != saved_files_.end() && !save_as) {
path = it->second;
} else {
+ file_dialog::Filters filters;
base::FilePath default_path(base::FilePath::FromUTF8Unsafe(url));
- if (!file_dialog::ShowSaveDialog(this, url, default_path, &path)) {
+ if (!file_dialog::ShowSaveDialog(this, url, default_path, filters, &path)) {
base::StringValue url_value(url);
CallDevToolsFunction("InspectorFrontendAPI.canceledSaveURL", &url_value);
return;
#define ATOM_BROWSER_UI_FILE_DIALOG_H_
#include <string>
+#include <utility>
#include <vector>
#include "base/callback_forward.h"
namespace file_dialog {
+// <description, extensions>
+typedef std::pair<std::string, std::vector<std::string> > Filter;
+typedef std::vector<Filter> Filters;
+
enum FileDialogProperty {
FILE_DIALOG_OPEN_FILE = 1,
FILE_DIALOG_OPEN_DIRECTORY = 2,
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
std::vector<base::FilePath>* paths);
void ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
const OpenDialogCallback& callback);
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
base::FilePath* path);
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
const SaveDialogCallback& callback);
} // namespace file_dialog
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
std::vector<base::FilePath>* paths) {
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
void ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
const OpenDialogCallback& callback) {
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
base::FilePath* path) {
FileChooserDialog save_dialog(
GTK_FILE_CHOOSER_ACTION_SAVE, parent_window, title, default_path);
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
const SaveDialogCallback& callback) {
FileChooserDialog* save_dialog = new FileChooserDialog(
GTK_FILE_CHOOSER_ACTION_SAVE, parent_window, title, default_path);
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
std::vector<base::FilePath>* paths) {
DCHECK(paths);
void ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
const OpenDialogCallback& c) {
NSOpenPanel* dialog = [NSOpenPanel openPanel];
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
base::FilePath* path) {
DCHECK(path);
NSSavePanel* dialog = [NSSavePanel savePanel];
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
const SaveDialogCallback& c) {
NSSavePanel* dialog = [NSSavePanel savePanel];
bool ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
std::vector<base::FilePath>* paths) {
int options = FOS_FORCEFILESYSTEM | FOS_FILEMUSTEXIST;
void ShowOpenDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
int properties,
const OpenDialogCallback& callback) {
std::vector<base::FilePath> paths;
title,
default_path,
properties,
+ filters,
&paths);
callback.Run(result, paths);
}
bool ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
base::FilePath* path) {
// TODO(zcbenz): Accept custom filters from caller.
std::vector<std::wstring> file_ext;
void ShowSaveDialog(atom::NativeWindow* parent_window,
const std::string& title,
const base::FilePath& default_path,
+ const Filters& filters,
const SaveDialogCallback& callback) {
base::FilePath path;
- bool result = ShowSaveDialog(parent_window, title, default_path, &path);
+ bool result = ShowSaveDialog(parent_window, title, default_path, filters,
+ &path);
callback.Run(result, path);
}