'browser/api/atom_api_app.h',
'browser/api/atom_api_browser_ipc.cc',
'browser/api/atom_api_browser_ipc.h',
+ 'browser/api/atom_api_dialog.cc',
+ 'browser/api/atom_api_dialog.h',
'browser/api/atom_api_event.cc',
'browser/api/atom_api_event.h',
'browser/api/atom_api_event_emitter.cc',
'browser/api/atom_api_event_emitter.h',
- 'browser/api/atom_api_file_dialog.cc',
- 'browser/api/atom_api_file_dialog.h',
'browser/api/atom_api_window.cc',
'browser/api/atom_api_window.h',
'browser/api/atom_browser_bindings.cc',
'browser/browser.h',
'browser/browser_mac.mm',
'browser/browser_observer.h',
+ 'browser/message_box.h',
+ 'browser/message_box_mac.mm',
'browser/native_window.cc',
'browser/native_window.h',
'browser/native_window_mac.h',
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "browser/api/atom_api_file_dialog.h"
+#include "browser/api/atom_api_dialog.h"
#include <string>
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "browser/message_box.h"
#include "browser/native_window.h"
namespace atom {
return base::FilePath::FromUTF8Unsafe(path_string);
}
-ui::SelectFileDialog::Type IntToDialogType(int type) {
- switch (type) {
- case ui::SelectFileDialog::SELECT_FOLDER:
- return ui::SelectFileDialog::SELECT_FOLDER;
- case ui::SelectFileDialog::SELECT_SAVEAS_FILE:
- return ui::SelectFileDialog::SELECT_SAVEAS_FILE;
- case ui::SelectFileDialog::SELECT_OPEN_FILE:
- return ui::SelectFileDialog::SELECT_OPEN_FILE;
- case ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE:
- return ui::SelectFileDialog::SELECT_OPEN_MULTI_FILE;
- default:
- return ui::SelectFileDialog::SELECT_NONE;
- }
-}
-
} // namespace
+v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments &args) {
+ v8::HandleScope scope;
+
+ if (!args[0]->IsNumber() || // process_id
+ !args[1]->IsNumber() || // routing_id
+ !args[2]->IsNumber() || // type
+ !args[3]->IsArray() || // buttons
+ !args[4]->IsString() || // title
+ !args[5]->IsString() || // message
+ !args[6]->IsString()) // detail
+ return node::ThrowTypeError("Bad argument");
+
+ int process_id = args[0]->IntegerValue();
+ int routing_id = args[1]->IntegerValue();
+ NativeWindow* window = NativeWindow::FromRenderView(process_id, routing_id);
+ if (!window)
+ return node::ThrowError("Window not found");
+
+ gfx::NativeWindow owning_window = window->GetNativeWindow();
+
+ MessageBoxType type = (MessageBoxType)(args[2]->IntegerValue());
+
+ std::vector<std::string> buttons;
+ v8::Handle<v8::Array> v8_buttons = v8::Handle<v8::Array>::Cast(args[3]);
+ for (uint32_t i = 0; i < v8_buttons->Length(); ++i)
+ buttons.push_back(*v8::String::Utf8Value(v8_buttons->Get(i)));
+
+ std::string title(*v8::String::Utf8Value(args[4]));
+ std::string message(*v8::String::Utf8Value(args[5]));
+ std::string detail(*v8::String::Utf8Value(args[6]));
+
+ int result = atom::ShowMessageBox(
+ owning_window, type, buttons, title, message, detail);
+ return v8::Integer::New(result);
+}
+
FileDialog::FileDialog(v8::Handle<v8::Object> wrapper)
: EventEmitter(wrapper),
dialog_(ui::SelectFileDialog::Create(this, NULL)) {
int callback_id = args[8]->IntegerValue();
self->dialog_->SelectFile(
- IntToDialogType(type),
+ (ui::SelectFileDialog::Type)(type),
UTF8ToUTF16(title),
default_path,
file_types.extensions.size() > 0 ? &file_types : NULL,
file_types->support_drive = true;
for (uint32_t i = 0; i < v8_file_types->Length(); ++i) {
- v8::Handle<v8::Object> element = v8_file_types->Get(i)->ToObject();
+ v8::Handle<v8::Object> element = v8_file_types->Get(i)->ToObject();
std::string description(*v8::String::Utf8Value(
element->Get(v8::String::New("description"))));
NODE_SET_PROTOTYPE_METHOD(t, "selectFile", SelectFile);
target->Set(v8::String::NewSymbol("FileDialog"), t->GetFunction());
+
+ NODE_SET_METHOD(target, "showMessageBox", ShowMessageBox);
}
} // namespace api
} // namespace atom
-NODE_MODULE(atom_browser_file_dialog, atom::api::FileDialog::Initialize)
+NODE_MODULE(atom_browser_dialog, atom::api::FileDialog::Initialize)
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef ATOM_BROWSER_API_ATOM_API_FILE_DIALOG_H_
-#define ATOM_BROWSER_API_ATOM_API_FILE_DIALOG_H_
+#ifndef ATOM_BROWSER_API_ATOM_API_DIALOG_H_
+#define ATOM_BROWSER_API_ATOM_API_DIALOG_H_
#include "browser/api/atom_api_event_emitter.h"
#include "ui/shell_dialogs/select_file_dialog.h"
namespace api {
+v8::Handle<v8::Value> ShowMessageBox(const v8::Arguments &args);
+
class FileDialog : public EventEmitter,
public ui::SelectFileDialog::Listener {
public:
} // namespace atom
-#endif // ATOM_BROWSER_API_ATOM_API_FILE_DIALOG_H_
+#endif // ATOM_BROWSER_API_ATOM_API_DIALOG_H_
+binding = process.atomBinding 'dialog'
EventEmitter = require('events').EventEmitter
ipc = require 'ipc'
-FileDialog = process.atomBinding('file_dialog').FileDialog
+FileDialog = binding.FileDialog
FileDialog.prototype.__proto__ = EventEmitter.prototype
callbacksInfo = {}
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BROWSER_MESSAGE_BOX_H_
+#define BROWSER_MESSAGE_BOX_H_
+
+#include <string>
+#include <vector>
+
+#include "ui/gfx/native_widget_types.h"
+
+namespace atom {
+
+enum MessageBoxType {
+ MESSAGE_BOX_TYPE_NONE = 0,
+ MESSAGE_BOX_TYPE_INFORMATION,
+ MESSAGE_BOX_TYPE_WARNING
+};
+
+int ShowMessageBox(gfx::NativeWindow parent,
+ MessageBoxType type,
+ const std::vector<std::string>& buttons,
+ const std::string& title,
+ const std::string& message,
+ const std::string& detail);
+
+} // namespace atom
+
+#endif // BROWSER_MESSAGE_BOX_H_
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/message_box.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/strings/sys_string_conversions.h"
+
+namespace atom {
+
+int ShowMessageBox(gfx::NativeWindow parent,
+ MessageBoxType type,
+ const std::vector<std::string>& buttons,
+ const std::string& title,
+ const std::string& message,
+ const std::string& detail) {
+ // Ignore the title; it's the window title on other platforms and ignorable.
+ NSAlert* alert = [[[NSAlert alloc] init] autorelease];
+ [alert setMessageText:base::SysUTF8ToNSString(message)];
+ [alert setInformativeText:base::SysUTF8ToNSString(detail)];
+
+ switch (type) {
+ case MESSAGE_BOX_TYPE_INFORMATION:
+ [alert setAlertStyle:NSInformationalAlertStyle];
+ break;
+ case MESSAGE_BOX_TYPE_WARNING:
+ [alert setAlertStyle:NSWarningAlertStyle];
+ break;
+ default:
+ break;
+ }
+
+ for (size_t i = 0; i < buttons.size(); ++i) {
+ NSString* title = base::SysUTF8ToNSString(buttons[i]);
+ NSButton* button = [alert addButtonWithTitle:title];
+ [button setTag:i];
+ }
+
+ return [alert runModal];
+}
+
+} // namespace atom
// Module names start with `atom_browser_` can only be used by browser process.
NODE_EXT_LIST_ITEM(atom_browser_app)
-NODE_EXT_LIST_ITEM(atom_browser_file_dialog)
+NODE_EXT_LIST_ITEM(atom_browser_dialog)
NODE_EXT_LIST_ITEM(atom_browser_ipc)
NODE_EXT_LIST_ITEM(atom_browser_window)