Add "icon" option for message box

This commit is contained in:
Cheng Zhao 2015-01-05 15:08:42 -08:00
parent 513052de87
commit 8457090b18
5 changed files with 64 additions and 29 deletions

View file

@ -11,6 +11,7 @@
#include "atom/browser/ui/file_dialog.h"
#include "atom/browser/ui/message_box.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "native_mate/callback.h"
#include "native_mate/dictionary.h"
@ -40,21 +41,27 @@ namespace {
void ShowMessageBox(int type,
const std::vector<std::string>& buttons,
const std::string& title,
const std::string& message,
const std::string& detail,
const std::vector<std::string>& texts,
const gfx::ImageSkia& icon,
atom::NativeWindow* window,
mate::Arguments* args) {
// FIXME We are exceeding the parameters limit of base::Bind here, so we have
// to pass some parameters in an array. We should remove this once we have
// variadic template support in base::Bind.
const std::string& title = texts[0];
const std::string& message = texts[1];
const std::string& detail = texts[2];
v8::Handle<v8::Value> peek = args->PeekNext();
atom::MessageBoxCallback callback;
if (mate::Converter<atom::MessageBoxCallback>::FromV8(args->isolate(),
peek,
&callback)) {
atom::ShowMessageBox(window, (atom::MessageBoxType)type, buttons, title,
message, detail, callback);
message, detail, icon, callback);
} else {
int chosen = atom::ShowMessageBox(window, (atom::MessageBoxType)type,
buttons, title, message, detail);
buttons, title, message, detail, icon);
args->Return(chosen);
}
}
@ -62,6 +69,7 @@ void ShowMessageBox(int type,
void ShowOpenDialog(const std::string& title,
const base::FilePath& default_path,
const file_dialog::Filters& filters,
const gfx::ImageSkia& icon,
int properties,
atom::NativeWindow* window,
mate::Arguments* args) {
@ -83,6 +91,7 @@ void ShowOpenDialog(const std::string& title,
void ShowSaveDialog(const std::string& title,
const base::FilePath& default_path,
const file_dialog::Filters& filters,
const gfx::ImageSkia& icon,
atom::NativeWindow* window,
mate::Arguments* args) {
v8::Handle<v8::Value> peek = args->PeekNext();

View file

@ -42,6 +42,7 @@ module.exports =
options.title ?= ''
options.defaultPath ?= ''
options.filters ?= []
options.icon ?= null
wrappedCallback =
if typeof callback is 'function'
@ -64,6 +65,7 @@ module.exports =
options.title ?= ''
options.defaultPath ?= ''
options.filters ?= []
options.icon ?= null
wrappedCallback =
if typeof callback is 'function'
@ -91,12 +93,12 @@ module.exports =
options.title ?= ''
options.message ?= ''
options.detail ?= ''
options.icon ?= null
binding.showMessageBox options.type,
options.buttons,
String(options.title),
String(options.message),
String(options.detail),
[options.title, options.message, options.detail],
options.icon,
window,
callback

View file

@ -11,6 +11,10 @@
#include "base/callback_forward.h"
#include "base/strings/string16.h"
namespace gfx {
class ImageSkia;
}
namespace atom {
class NativeWindow;
@ -28,7 +32,8 @@ int ShowMessageBox(NativeWindow* parent_window,
const std::vector<std::string>& buttons,
const std::string& title,
const std::string& message,
const std::string& detail);
const std::string& detail,
const gfx::ImageSkia& icon);
void ShowMessageBox(NativeWindow* parent_window,
MessageBoxType type,
@ -36,6 +41,7 @@ void ShowMessageBox(NativeWindow* parent_window,
const std::string& title,
const std::string& message,
const std::string& detail,
const gfx::ImageSkia& icon,
const MessageBoxCallback& callback);
// Like ShowMessageBox with simplest settings, but safe to call at very early

View file

@ -96,7 +96,8 @@ int ShowMessageBox(NativeWindow* parent_window,
const std::vector<std::string>& buttons,
const std::string& title,
const std::string& message,
const std::string& detail) {
const std::string& detail,
const gfx::ImageSkia& icon) {
NSAlert* alert = CreateNSAlert(
parent_window, type, buttons, title, message, detail);
@ -127,6 +128,7 @@ void ShowMessageBox(NativeWindow* parent_window,
const std::string& title,
const std::string& message,
const std::string& detail,
const gfx::ImageSkia& icon,
const MessageBoxCallback& callback) {
NSAlert* alert = CreateNSAlert(
parent_window, type, buttons, title, message, detail);

View file

@ -60,7 +60,8 @@ class MessageDialog : public views::WidgetDelegate,
const std::vector<std::string>& buttons,
const std::string& title,
const std::string& message,
const std::string& detail);
const std::string& detail,
const gfx::ImageSkia& icon);
virtual ~MessageDialog();
void Show(base::RunLoop* run_loop = NULL);
@ -75,24 +76,27 @@ class MessageDialog : public views::WidgetDelegate,
private:
// Overridden from views::WidgetDelegate:
virtual base::string16 GetWindowTitle() const;
virtual views::Widget* GetWidget() OVERRIDE;
virtual const views::Widget* GetWidget() const OVERRIDE;
virtual views::View* GetContentsView() OVERRIDE;
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
virtual ui::ModalType GetModalType() const OVERRIDE;
virtual views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) OVERRIDE;
virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
base::string16 GetWindowTitle() const override;
gfx::ImageSkia GetWindowAppIcon() override;
gfx::ImageSkia GetWindowIcon() override;
views::Widget* GetWidget() override;
const views::Widget* GetWidget() const override;
views::View* GetContentsView() override;
views::View* GetInitiallyFocusedView() override;
ui::ModalType GetModalType() const override;
views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) override;
views::ClientView* CreateClientView(views::Widget* widget) override;
// Overridden from views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE;
virtual void Layout() OVERRIDE;
virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
gfx::Size GetPreferredSize() const override;
void Layout() override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
// Overridden from views::ButtonListener:
virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE;
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
gfx::ImageSkia icon_;
bool delete_on_close_;
int result_;
@ -118,7 +122,7 @@ class MessageDialogClientView : public views::ClientView {
}
// views::ClientView:
virtual bool CanClose() OVERRIDE {
bool CanClose() override {
dialog_->Close();
return false;
}
@ -137,8 +141,10 @@ MessageDialog::MessageDialog(NativeWindow* parent_window,
const std::vector<std::string>& buttons,
const std::string& title,
const std::string& message,
const std::string& detail)
: delete_on_close_(false),
const std::string& detail,
const gfx::ImageSkia& icon)
: icon_(icon),
delete_on_close_(false),
result_(-1),
title_(base::UTF8ToUTF16(title)),
parent_(parent_window),
@ -226,6 +232,14 @@ int MessageDialog::GetResult() const {
////////////////////////////////////////////////////////////////////////////////
// MessageDialog, private:
gfx::ImageSkia MessageDialog::GetWindowAppIcon() {
return icon_;
}
gfx::ImageSkia MessageDialog::GetWindowIcon() {
return icon_;
}
base::string16 MessageDialog::GetWindowTitle() const {
return title_;
}
@ -338,7 +352,8 @@ int ShowMessageBox(NativeWindow* parent_window,
const std::vector<std::string>& buttons,
const std::string& title,
const std::string& message,
const std::string& detail) {
const std::string& detail,
const gfx::ImageSkia& icon) {
MessageDialog dialog(parent_window, type, buttons, title, message, detail);
{
base::MessageLoop::ScopedNestableTaskAllower allow(
@ -357,6 +372,7 @@ void ShowMessageBox(NativeWindow* parent_window,
const std::string& title,
const std::string& message,
const std::string& detail,
const gfx::ImageSkia& icon,
const MessageBoxCallback& callback) {
// The dialog would be deleted when the dialog is closed.
MessageDialog* dialog = new MessageDialog(