2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-07-05 01:59:53 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/ui/message_box.h"
|
2013-07-05 01:59:53 +00:00
|
|
|
|
2014-11-05 10:58:00 +00:00
|
|
|
#if defined(USE_X11)
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-16 01:37:04 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
2013-09-22 09:11:09 +00:00
|
|
|
#include "base/callback.h"
|
2013-12-17 06:01:40 +00:00
|
|
|
#include "base/message_loop/message_loop.h"
|
2013-07-24 10:34:50 +00:00
|
|
|
#include "base/run_loop.h"
|
2013-12-17 06:01:40 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
#include "base/strings/string16.h"
|
2013-12-17 06:01:40 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2014-07-03 17:30:36 +00:00
|
|
|
#include "ui/views/background.h"
|
2013-07-25 07:22:44 +00:00
|
|
|
#include "ui/views/controls/button/label_button.h"
|
2013-07-24 10:34:50 +00:00
|
|
|
#include "ui/views/controls/message_box_view.h"
|
|
|
|
#include "ui/views/layout/grid_layout.h"
|
2013-07-25 08:19:40 +00:00
|
|
|
#include "ui/views/layout/layout_constants.h"
|
2014-07-12 13:03:34 +00:00
|
|
|
#include "ui/views/bubble/bubble_border.h"
|
|
|
|
#include "ui/views/bubble/bubble_frame_view.h"
|
2013-07-24 10:34:50 +00:00
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
#include "ui/views/widget/widget_delegate.h"
|
2014-07-12 13:03:34 +00:00
|
|
|
#include "ui/wm/core/shadow_types.h"
|
2013-07-24 10:34:50 +00:00
|
|
|
|
2014-07-24 13:06:33 +00:00
|
|
|
#if defined(USE_X11)
|
2014-11-05 10:58:00 +00:00
|
|
|
#include "atom/browser/browser.h"
|
2014-07-24 13:06:33 +00:00
|
|
|
#include "ui/views/window/native_frame_view.h"
|
|
|
|
#endif
|
|
|
|
|
2014-11-05 08:05:11 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "ui/base/win/message_box_win.h"
|
|
|
|
#endif
|
|
|
|
|
2014-11-05 10:58:00 +00:00
|
|
|
#define ANSI_FOREGROUND_RED "\x1b[31m"
|
|
|
|
#define ANSI_FOREGROUND_BLACK "\x1b[30m"
|
|
|
|
#define ANSI_TEXT_BOLD "\x1b[1m"
|
|
|
|
#define ANSI_BACKGROUND_GRAY "\x1b[47m"
|
|
|
|
#define ANSI_RESET "\x1b[0m"
|
|
|
|
|
2013-07-05 01:59:53 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2013-07-24 10:34:50 +00:00
|
|
|
namespace {
|
|
|
|
|
2013-07-25 13:04:33 +00:00
|
|
|
// The group used by the buttons. This name is chosen voluntarily big not to
|
|
|
|
// conflict with other groups that could be in the dialog content.
|
|
|
|
const int kButtonGroup = 1127;
|
|
|
|
|
2014-07-13 01:50:16 +00:00
|
|
|
class MessageDialogClientView;
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
class MessageDialog : public views::WidgetDelegate,
|
2013-07-25 07:22:44 +00:00
|
|
|
public views::View,
|
2013-07-24 10:34:50 +00:00
|
|
|
public views::ButtonListener {
|
|
|
|
public:
|
|
|
|
MessageDialog(NativeWindow* parent_window,
|
|
|
|
MessageBoxType type,
|
|
|
|
const std::vector<std::string>& buttons,
|
|
|
|
const std::string& title,
|
|
|
|
const std::string& message,
|
2015-01-05 23:08:42 +00:00
|
|
|
const std::string& detail,
|
|
|
|
const gfx::ImageSkia& icon);
|
2013-07-24 10:34:50 +00:00
|
|
|
virtual ~MessageDialog();
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
void Show(base::RunLoop* run_loop = NULL);
|
2014-07-13 01:50:16 +00:00
|
|
|
void Close();
|
2013-09-24 08:11:23 +00:00
|
|
|
|
|
|
|
int GetResult() const;
|
|
|
|
|
|
|
|
void set_callback(const MessageBoxCallback& callback) {
|
|
|
|
delete_on_close_ = true;
|
|
|
|
callback_ = callback;
|
|
|
|
}
|
2013-07-25 08:56:02 +00:00
|
|
|
|
2013-07-24 10:34:50 +00:00
|
|
|
private:
|
2013-07-25 09:06:08 +00:00
|
|
|
// Overridden from views::WidgetDelegate:
|
2015-01-05 23:08:42 +00:00
|
|
|
base::string16 GetWindowTitle() const override;
|
|
|
|
gfx::ImageSkia GetWindowAppIcon() override;
|
|
|
|
gfx::ImageSkia GetWindowIcon() override;
|
2015-01-05 23:26:35 +00:00
|
|
|
bool ShouldShowWindowIcon() const override;
|
2015-01-05 23:08:42 +00:00
|
|
|
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;
|
2013-07-24 10:34:50 +00:00
|
|
|
|
2013-07-25 08:19:40 +00:00
|
|
|
// Overridden from views::View:
|
2015-01-05 23:08:42 +00:00
|
|
|
gfx::Size GetPreferredSize() const override;
|
|
|
|
void Layout() override;
|
|
|
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
2013-07-25 08:19:40 +00:00
|
|
|
|
2013-07-24 10:34:50 +00:00
|
|
|
// Overridden from views::ButtonListener:
|
2015-01-05 23:08:42 +00:00
|
|
|
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
|
|
|
|
|
|
|
|
gfx::ImageSkia icon_;
|
2013-07-24 10:34:50 +00:00
|
|
|
|
2013-09-24 08:11:23 +00:00
|
|
|
bool delete_on_close_;
|
2013-07-25 08:56:02 +00:00
|
|
|
int result_;
|
2014-06-28 14:33:00 +00:00
|
|
|
base::string16 title_;
|
2014-07-12 13:03:34 +00:00
|
|
|
|
|
|
|
NativeWindow* parent_;
|
2014-07-13 01:50:16 +00:00
|
|
|
scoped_ptr<views::Widget> widget_;
|
2013-07-24 10:34:50 +00:00
|
|
|
views::MessageBoxView* message_box_view_;
|
2014-07-12 13:03:34 +00:00
|
|
|
std::vector<views::LabelButton*> buttons_;
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
base::RunLoop* run_loop_;
|
2014-02-10 12:07:38 +00:00
|
|
|
scoped_ptr<NativeWindow::DialogScope> dialog_scope_;
|
2013-09-24 08:11:23 +00:00
|
|
|
MessageBoxCallback callback_;
|
2013-07-24 10:34:50 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MessageDialog);
|
|
|
|
};
|
|
|
|
|
2014-07-13 01:50:16 +00:00
|
|
|
class MessageDialogClientView : public views::ClientView {
|
|
|
|
public:
|
|
|
|
MessageDialogClientView(MessageDialog* dialog, views::Widget* widget)
|
|
|
|
: views::ClientView(widget, dialog),
|
|
|
|
dialog_(dialog) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// views::ClientView:
|
2015-01-05 23:08:42 +00:00
|
|
|
bool CanClose() override {
|
2014-07-13 01:50:16 +00:00
|
|
|
dialog_->Close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MessageDialog* dialog_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MessageDialogClientView);
|
|
|
|
};
|
|
|
|
|
2013-07-24 10:34:50 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MessageDialog, public:
|
|
|
|
|
|
|
|
MessageDialog::MessageDialog(NativeWindow* parent_window,
|
|
|
|
MessageBoxType type,
|
|
|
|
const std::vector<std::string>& buttons,
|
|
|
|
const std::string& title,
|
|
|
|
const std::string& message,
|
2015-01-05 23:08:42 +00:00
|
|
|
const std::string& detail,
|
|
|
|
const gfx::ImageSkia& icon)
|
|
|
|
: icon_(icon),
|
|
|
|
delete_on_close_(false),
|
2013-07-25 08:56:02 +00:00
|
|
|
result_(-1),
|
2014-07-03 17:30:36 +00:00
|
|
|
title_(base::UTF8ToUTF16(title)),
|
2014-07-12 13:03:34 +00:00
|
|
|
parent_(parent_window),
|
2014-02-10 12:07:38 +00:00
|
|
|
message_box_view_(NULL),
|
2014-07-03 17:30:36 +00:00
|
|
|
run_loop_(NULL),
|
2014-02-10 12:07:38 +00:00
|
|
|
dialog_scope_(new NativeWindow::DialogScope(parent_window)) {
|
2013-08-16 08:33:32 +00:00
|
|
|
DCHECK_GT(buttons.size(), 0u);
|
2013-07-25 07:22:44 +00:00
|
|
|
set_owned_by_client();
|
2014-07-12 13:03:34 +00:00
|
|
|
|
|
|
|
if (!parent_)
|
|
|
|
set_background(views::Background::CreateStandardPanelBackground());
|
2013-07-25 07:22:44 +00:00
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
std::string content = message + "\n" + detail;
|
2014-07-12 13:03:34 +00:00
|
|
|
views::MessageBoxView::InitParams box_params(base::UTF8ToUTF16(content));
|
|
|
|
message_box_view_ = new views::MessageBoxView(box_params);
|
2013-07-25 08:19:40 +00:00
|
|
|
AddChildView(message_box_view_);
|
2013-07-24 10:34:50 +00:00
|
|
|
|
2013-07-25 08:19:40 +00:00
|
|
|
for (size_t i = 0; i < buttons.size(); ++i) {
|
2013-07-25 07:22:44 +00:00
|
|
|
views::LabelButton* button = new views::LabelButton(
|
2014-07-03 17:30:36 +00:00
|
|
|
this, base::UTF8ToUTF16(buttons[i]));
|
2013-07-25 07:22:44 +00:00
|
|
|
button->set_tag(i);
|
2014-10-13 03:03:56 +00:00
|
|
|
button->SetMinSize(gfx::Size(60, 30));
|
2014-07-03 17:30:36 +00:00
|
|
|
button->SetStyle(views::Button::STYLE_BUTTON);
|
2013-07-25 13:04:33 +00:00
|
|
|
button->SetGroup(kButtonGroup);
|
2013-07-25 07:22:44 +00:00
|
|
|
|
2013-07-25 08:19:40 +00:00
|
|
|
buttons_.push_back(button);
|
|
|
|
AddChildView(button);
|
|
|
|
}
|
2013-07-25 13:04:33 +00:00
|
|
|
|
|
|
|
// First button is always default button.
|
2013-07-25 08:56:02 +00:00
|
|
|
buttons_[0]->SetIsDefault(true);
|
2013-07-25 13:04:33 +00:00
|
|
|
buttons_[0]->AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
|
2013-07-25 07:47:12 +00:00
|
|
|
|
2014-07-12 13:03:34 +00:00
|
|
|
views::Widget::InitParams params;
|
|
|
|
params.delegate = this;
|
2015-01-05 23:26:35 +00:00
|
|
|
params.type = views::Widget::InitParams::TYPE_WINDOW;
|
2014-07-13 01:50:16 +00:00
|
|
|
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
2014-07-12 13:03:34 +00:00
|
|
|
if (parent_) {
|
2014-07-13 01:50:16 +00:00
|
|
|
params.parent = parent_->GetNativeWindow();
|
2014-07-12 13:03:34 +00:00
|
|
|
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
|
2014-07-13 01:50:16 +00:00
|
|
|
// Use bubble style for dialog has a parent.
|
2014-07-12 13:03:34 +00:00
|
|
|
params.remove_standard_frame = true;
|
|
|
|
}
|
|
|
|
|
2014-07-13 01:50:16 +00:00
|
|
|
widget_.reset(new views::Widget);
|
2014-07-12 13:03:34 +00:00
|
|
|
widget_->Init(params);
|
2015-01-05 23:26:35 +00:00
|
|
|
widget_->UpdateWindowIcon();
|
2013-07-24 10:34:50 +00:00
|
|
|
|
2013-07-25 13:04:33 +00:00
|
|
|
// Bind to ESC.
|
|
|
|
AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
|
2013-07-24 10:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageDialog::~MessageDialog() {
|
|
|
|
}
|
|
|
|
|
2014-07-03 17:30:36 +00:00
|
|
|
void MessageDialog::Show(base::RunLoop* run_loop) {
|
|
|
|
run_loop_ = run_loop;
|
2013-09-24 08:11:23 +00:00
|
|
|
widget_->Show();
|
|
|
|
}
|
|
|
|
|
2014-07-13 01:50:16 +00:00
|
|
|
void MessageDialog::Close() {
|
|
|
|
dialog_scope_.reset();
|
|
|
|
|
|
|
|
if (delete_on_close_) {
|
|
|
|
callback_.Run(GetResult());
|
|
|
|
base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);
|
|
|
|
} else if (run_loop_) {
|
|
|
|
run_loop_->Quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 08:11:23 +00:00
|
|
|
int MessageDialog::GetResult() const {
|
|
|
|
// When the dialog is closed without choosing anything, we think the user
|
|
|
|
// chose 'Cancel', otherwise we think the default behavior is chosen.
|
|
|
|
if (result_ == -1) {
|
|
|
|
for (size_t i = 0; i < buttons_.size(); ++i)
|
|
|
|
if (LowerCaseEqualsASCII(buttons_[i]->GetText(), "cancel")) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return result_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 10:34:50 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// MessageDialog, private:
|
|
|
|
|
2015-01-05 23:26:35 +00:00
|
|
|
base::string16 MessageDialog::GetWindowTitle() const {
|
|
|
|
return title_;
|
|
|
|
}
|
|
|
|
|
2015-01-05 23:08:42 +00:00
|
|
|
gfx::ImageSkia MessageDialog::GetWindowAppIcon() {
|
|
|
|
return icon_;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::ImageSkia MessageDialog::GetWindowIcon() {
|
|
|
|
return icon_;
|
|
|
|
}
|
|
|
|
|
2015-01-05 23:26:35 +00:00
|
|
|
bool MessageDialog::ShouldShowWindowIcon() const {
|
|
|
|
return true;
|
2013-07-25 09:06:08 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 10:34:50 +00:00
|
|
|
views::Widget* MessageDialog::GetWidget() {
|
2014-07-13 01:50:16 +00:00
|
|
|
return widget_.get();
|
2013-07-24 10:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const views::Widget* MessageDialog::GetWidget() const {
|
2014-07-13 01:50:16 +00:00
|
|
|
return widget_.get();
|
2013-07-24 10:34:50 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 07:22:44 +00:00
|
|
|
views::View* MessageDialog::GetContentsView() {
|
|
|
|
return this;
|
2013-07-24 10:34:50 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 13:04:33 +00:00
|
|
|
views::View* MessageDialog::GetInitiallyFocusedView() {
|
|
|
|
if (buttons_.size() > 0)
|
|
|
|
return buttons_[0];
|
|
|
|
else
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-07-24 10:51:03 +00:00
|
|
|
ui::ModalType MessageDialog::GetModalType() const {
|
2014-07-12 13:03:34 +00:00
|
|
|
return ui::MODAL_TYPE_SYSTEM;
|
2013-07-24 10:51:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-12 13:03:34 +00:00
|
|
|
views::NonClientFrameView* MessageDialog::CreateNonClientFrameView(
|
|
|
|
views::Widget* widget) {
|
2014-07-24 13:06:33 +00:00
|
|
|
if (!parent_) {
|
|
|
|
#if defined(USE_X11)
|
|
|
|
return new views::NativeFrameView(widget);
|
|
|
|
#else
|
2014-07-12 13:03:34 +00:00
|
|
|
return NULL;
|
2014-07-24 13:06:33 +00:00
|
|
|
#endif
|
|
|
|
}
|
2014-07-12 13:03:34 +00:00
|
|
|
|
|
|
|
// Create a bubble style frame like Chrome.
|
|
|
|
views::BubbleFrameView* frame = new views::BubbleFrameView(gfx::Insets());
|
|
|
|
const SkColor color = widget->GetNativeTheme()->GetSystemColor(
|
|
|
|
ui::NativeTheme::kColorId_DialogBackground);
|
|
|
|
scoped_ptr<views::BubbleBorder> border(new views::BubbleBorder(
|
|
|
|
views::BubbleBorder::FLOAT, views::BubbleBorder::SMALL_SHADOW, color));
|
|
|
|
frame->SetBubbleBorder(border.Pass());
|
|
|
|
wm::SetShadowType(widget->GetNativeWindow(), wm::SHADOW_TYPE_NONE);
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-07-13 01:50:16 +00:00
|
|
|
views::ClientView* MessageDialog::CreateClientView(views::Widget* widget) {
|
|
|
|
return new MessageDialogClientView(this, widget);
|
|
|
|
}
|
|
|
|
|
2014-09-01 12:10:14 +00:00
|
|
|
gfx::Size MessageDialog::GetPreferredSize() const {
|
2013-07-25 08:19:40 +00:00
|
|
|
gfx::Size size(0, buttons_[0]->GetPreferredSize().height());
|
|
|
|
for (size_t i = 0; i < buttons_.size(); ++i)
|
|
|
|
size.Enlarge(buttons_[i]->GetPreferredSize().width(), 0);
|
|
|
|
|
|
|
|
// Button spaces.
|
|
|
|
size.Enlarge(views::kRelatedButtonHSpacing * (buttons_.size() - 1),
|
|
|
|
views::kRelatedControlVerticalSpacing);
|
|
|
|
|
|
|
|
// The message box view.
|
|
|
|
gfx::Size contents_size = message_box_view_->GetPreferredSize();
|
|
|
|
size.Enlarge(0, contents_size.height());
|
|
|
|
if (contents_size.width() > size.width())
|
|
|
|
size.set_width(contents_size.width());
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MessageDialog::Layout() {
|
|
|
|
gfx::Rect bounds = GetContentsBounds();
|
|
|
|
|
|
|
|
// Layout the row containing the buttons.
|
|
|
|
int x = bounds.width();
|
|
|
|
int height = buttons_[0]->GetPreferredSize().height() +
|
|
|
|
views::kRelatedControlVerticalSpacing;
|
2013-08-30 19:08:04 +00:00
|
|
|
|
|
|
|
// NB: We iterate through the buttons backwards here because
|
|
|
|
// Mac and Windows buttons are laid out in opposite order.
|
|
|
|
for (int i = buttons_.size() - 1; i >= 0; --i) {
|
2013-07-25 08:19:40 +00:00
|
|
|
gfx::Size size = buttons_[i]->GetPreferredSize();
|
|
|
|
x -= size.width() + views::kRelatedButtonHSpacing;
|
|
|
|
|
|
|
|
buttons_[i]->SetBounds(x, bounds.height() - height,
|
|
|
|
size.width(), size.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Layout the message box view.
|
|
|
|
message_box_view_->SetBounds(bounds.x(), bounds.y(), bounds.width(),
|
|
|
|
bounds.height() - height);
|
|
|
|
}
|
|
|
|
|
2013-07-25 13:04:33 +00:00
|
|
|
bool MessageDialog::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
|
|
|
DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE);
|
|
|
|
widget_->Close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-24 10:34:50 +00:00
|
|
|
void MessageDialog::ButtonPressed(views::Button* sender,
|
|
|
|
const ui::Event& event) {
|
2013-07-25 08:56:02 +00:00
|
|
|
result_ = sender->tag();
|
|
|
|
widget_->Close();
|
2013-07-24 10:34:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-07-05 01:59:53 +00:00
|
|
|
int ShowMessageBox(NativeWindow* parent_window,
|
|
|
|
MessageBoxType type,
|
|
|
|
const std::vector<std::string>& buttons,
|
|
|
|
const std::string& title,
|
|
|
|
const std::string& message,
|
2015-01-05 23:08:42 +00:00
|
|
|
const std::string& detail,
|
|
|
|
const gfx::ImageSkia& icon) {
|
2015-01-05 23:26:35 +00:00
|
|
|
MessageDialog dialog(
|
|
|
|
parent_window, type, buttons, title, message, detail, icon);
|
2013-07-24 10:34:50 +00:00
|
|
|
{
|
|
|
|
base::MessageLoop::ScopedNestableTaskAllower allow(
|
|
|
|
base::MessageLoopForUI::current());
|
2014-07-03 17:30:36 +00:00
|
|
|
base::RunLoop run_loop;
|
|
|
|
dialog.Show(&run_loop);
|
2013-07-24 10:34:50 +00:00
|
|
|
run_loop.Run();
|
|
|
|
}
|
2013-07-25 08:56:02 +00:00
|
|
|
|
2013-09-24 08:11:23 +00:00
|
|
|
return dialog.GetResult();
|
2013-07-05 01:59:53 +00:00
|
|
|
}
|
|
|
|
|
2013-09-22 09:11:09 +00:00
|
|
|
void ShowMessageBox(NativeWindow* parent_window,
|
|
|
|
MessageBoxType type,
|
|
|
|
const std::vector<std::string>& buttons,
|
|
|
|
const std::string& title,
|
|
|
|
const std::string& message,
|
|
|
|
const std::string& detail,
|
2015-01-05 23:08:42 +00:00
|
|
|
const gfx::ImageSkia& icon,
|
2013-09-22 09:11:09 +00:00
|
|
|
const MessageBoxCallback& callback) {
|
2013-09-24 08:11:23 +00:00
|
|
|
// The dialog would be deleted when the dialog is closed.
|
|
|
|
MessageDialog* dialog = new MessageDialog(
|
2015-01-05 23:26:35 +00:00
|
|
|
parent_window, type, buttons, title, message, detail, icon);
|
2013-09-24 08:11:23 +00:00
|
|
|
dialog->set_callback(callback);
|
|
|
|
dialog->Show();
|
2013-09-22 09:11:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 08:05:11 +00:00
|
|
|
void ShowErrorBox(const base::string16& title, const base::string16& content) {
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
ui::MessageBox(NULL, content, title, MB_OK | MB_ICONERROR | MB_TASKMODAL);
|
2014-11-05 10:58:00 +00:00
|
|
|
#elif defined(USE_X11)
|
|
|
|
if (Browser::Get()->is_ready()) {
|
2014-11-05 11:27:43 +00:00
|
|
|
GtkWidget* dialog = gtk_message_dialog_new(
|
|
|
|
NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
|
|
|
|
"%s", base::UTF16ToUTF8(title).c_str());
|
|
|
|
gtk_message_dialog_format_secondary_text(
|
|
|
|
GTK_MESSAGE_DIALOG(dialog),
|
|
|
|
"%s", base::UTF16ToUTF8(content).c_str());
|
|
|
|
gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
gtk_widget_destroy(dialog);
|
2014-11-05 10:58:00 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr,
|
|
|
|
ANSI_TEXT_BOLD ANSI_BACKGROUND_GRAY
|
|
|
|
ANSI_FOREGROUND_RED "%s\n"
|
|
|
|
ANSI_FOREGROUND_BLACK "%s"
|
|
|
|
ANSI_RESET "\n",
|
|
|
|
base::UTF16ToUTF8(title).c_str(),
|
|
|
|
base::UTF16ToUTF8(content).c_str());
|
|
|
|
}
|
2014-11-05 08:05:11 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-05 01:59:53 +00:00
|
|
|
} // namespace atom
|