summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-07-15 20:45:11 -0600
committerAndreas Kling <kling@serenityos.org>2020-07-16 16:10:21 +0200
commit27bd2eab2288c79206f3571bc2c46a20fc9a4254 (patch)
tree2391eb84dc9fc1a7be2bf1391daf13020b1e0076 /Libraries/LibGUI
parent6568765e8f89563fa76407ce5e369ec1eb09c125 (diff)
downloadserenity-27bd2eab2288c79206f3571bc2c46a20fc9a4254.zip
LibWeb: Require parent window argument for MessageBox
Since the vast majority of message boxes should be modal, require the parent window to be passed in, which can be nullptr for the rare case that they don't. By it being the first argument, the default arguments also don't need to be explicitly stated in most cases, and it encourages passing in a parent window handle. Fix up several message boxes that should have been modal.
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/FilePicker.cpp4
-rw-r--r--Libraries/LibGUI/MessageBox.cpp14
-rw-r--r--Libraries/LibGUI/MessageBox.h6
3 files changed, 11 insertions, 13 deletions
diff --git a/Libraries/LibGUI/FilePicker.cpp b/Libraries/LibGUI/FilePicker.cpp
index 3877df01d8..8cc3f4c0fa 100644
--- a/Libraries/LibGUI/FilePicker.cpp
+++ b/Libraries/LibGUI/FilePicker.cpp
@@ -160,7 +160,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
.string();
int rc = mkdir(new_dir_path.characters(), 0777);
if (rc < 0) {
- MessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", MessageBox::Type::Error, MessageBox::InputType::OK, this);
+ MessageBox::show(this, String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", MessageBox::Type::Error);
} else {
m_model->update();
}
@@ -322,7 +322,7 @@ void FilePicker::on_file_return()
LexicalPath path(String::format("%s/%s", m_model->root_path().characters(), m_filename_textbox->text().characters()));
if (FilePicker::file_exists(path.string()) && m_mode == Mode::Save) {
- auto result = MessageBox::show("File already exists, overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel);
+ auto result = MessageBox::show(this, "File already exists, overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel);
if (result == MessageBox::ExecCancel)
return;
}
diff --git a/Libraries/LibGUI/MessageBox.cpp b/Libraries/LibGUI/MessageBox.cpp
index df357a02fb..9af920a8c7 100644
--- a/Libraries/LibGUI/MessageBox.cpp
+++ b/Libraries/LibGUI/MessageBox.cpp
@@ -34,22 +34,20 @@
namespace GUI {
-int MessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, Window* parent_window)
+int MessageBox::show(Window* parent_window, const StringView& text, const StringView& title, Type type, InputType input_type)
{
- auto box = MessageBox::construct(text, title, type, input_type);
- if (parent_window) {
- parent_window->add_child(box);
+ auto box = MessageBox::construct(parent_window, text, title, type, input_type);
+ if (parent_window)
box->set_icon(parent_window->icon());
- }
return box->exec();
}
-int MessageBox::show_error(const StringView& text, Window* parent_window)
+int MessageBox::show_error(Window* parent_window, const StringView& text)
{
- return show(text, "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, parent_window);
+ return show(parent_window, text, "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK);
}
-MessageBox::MessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, Window* parent_window)
+MessageBox::MessageBox(Window* parent_window, const StringView& text, const StringView& title, Type type, InputType input_type)
: Dialog(parent_window)
, m_text(text)
, m_type(type)
diff --git a/Libraries/LibGUI/MessageBox.h b/Libraries/LibGUI/MessageBox.h
index 243b3469e8..dcd4c64d3c 100644
--- a/Libraries/LibGUI/MessageBox.h
+++ b/Libraries/LibGUI/MessageBox.h
@@ -50,11 +50,11 @@ public:
virtual ~MessageBox() override;
- static int show(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, Window* parent_window = nullptr);
- static int show_error(const StringView& text, Window* parent_window = nullptr);
+ static int show(Window* parent_window, const StringView& text, const StringView& title, Type type = Type::None, InputType input_type = InputType::OK);
+ static int show_error(Window* parent_window, const StringView& text);
private:
- explicit MessageBox(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, Window* parent_window = nullptr);
+ explicit MessageBox(Window* parent_window, const StringView& text, const StringView& title, Type type = Type::None, InputType input_type = InputType::OK);
bool should_include_ok_button() const;
bool should_include_cancel_button() const;