summaryrefslogtreecommitdiff
path: root/Applications/TextEditor
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 /Applications/TextEditor
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 'Applications/TextEditor')
-rw-r--r--Applications/TextEditor/TextEditorWidget.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp
index c368b73017..6407117344 100644
--- a/Applications/TextEditor/TextEditorWidget.cpp
+++ b/Applications/TextEditor/TextEditorWidget.cpp
@@ -124,11 +124,10 @@ TextEditorWidget::TextEditorWidget()
if (found_range.is_valid()) {
m_editor->set_selection(found_range);
} else {
- GUI::MessageBox::show(
+ GUI::MessageBox::show(window(),
String::format("Not found: \"%s\"", needle.characters()),
"Not found",
- GUI::MessageBox::Type::Information,
- GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::Type::Information);
}
});
@@ -149,11 +148,10 @@ TextEditorWidget::TextEditorWidget()
if (found_range.is_valid()) {
m_editor->set_selection(found_range);
} else {
- GUI::MessageBox::show(
+ GUI::MessageBox::show(window(),
String::format("Not found: \"%s\"", needle.characters()),
"Not found",
- GUI::MessageBox::Type::Information,
- GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::Type::Information);
}
});
@@ -174,11 +172,10 @@ TextEditorWidget::TextEditorWidget()
m_editor->set_selection(found_range);
m_editor->insert_at_cursor_or_replace_selection(substitute);
} else {
- GUI::MessageBox::show(
+ GUI::MessageBox::show(window(),
String::format("Not found: \"%s\"", needle.characters()),
"Not found",
- GUI::MessageBox::Type::Information,
- GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::Type::Information);
}
});
@@ -198,11 +195,10 @@ TextEditorWidget::TextEditorWidget()
m_editor->set_selection(found_range);
m_editor->insert_at_cursor_or_replace_selection(substitute);
} else {
- GUI::MessageBox::show(
+ GUI::MessageBox::show(window(),
String::format("Not found: \"%s\"", needle.characters()),
"Not found",
- GUI::MessageBox::Type::Information,
- GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::Type::Information);
}
});
@@ -290,7 +286,7 @@ TextEditorWidget::TextEditorWidget()
m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
if (m_document_dirty) {
- auto save_document_first_result = GUI::MessageBox::show("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
+ auto save_document_first_result = GUI::MessageBox::show(window(), "Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
m_save_action->activate();
if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel)
@@ -310,7 +306,7 @@ TextEditorWidget::TextEditorWidget()
return;
if (m_document_dirty) {
- auto save_document_first_result = GUI::MessageBox::show("Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel, window());
+ auto save_document_first_result = GUI::MessageBox::show(window(), "Save Document First?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
m_save_action->activate();
if (save_document_first_result == GUI::Dialog::ExecResult::ExecCancel)
@@ -326,7 +322,7 @@ TextEditorWidget::TextEditorWidget()
return;
if (!m_editor->write_to_file(save_path.value())) {
- GUI::MessageBox::show("Unable to save file.\n", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::show(window(), "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
return;
}
@@ -338,7 +334,7 @@ TextEditorWidget::TextEditorWidget()
m_save_action = GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](const GUI::Action&) {
if (!m_path.is_empty()) {
if (!m_editor->write_to_file(m_path)) {
- GUI::MessageBox::show("Unable to save file.\n", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::show(window(), "Unable to save file.\n", "Error", GUI::MessageBox::Type::Error);
} else {
m_document_dirty = false;
update_title();
@@ -523,7 +519,7 @@ void TextEditorWidget::open_sesame(const String& path)
{
auto file = Core::File::construct(path);
if (!file->open(Core::IODevice::ReadOnly) && file->error() != ENOENT) {
- GUI::MessageBox::show(String::format("Opening \"%s\" failed: %s", path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::show(window(), String::format("Opening \"%s\" failed: %s", path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error);
return;
}
@@ -540,7 +536,7 @@ bool TextEditorWidget::request_close()
{
if (!m_document_dirty)
return true;
- auto result = GUI::MessageBox::show("The document has been modified. Would you like to save?", "Unsaved changes", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel, window());
+ auto result = GUI::MessageBox::show(window(), "The document has been modified. Would you like to save?", "Unsaved changes", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
if (result == GUI::MessageBox::ExecYes) {
m_save_action->activate();
@@ -563,7 +559,7 @@ void TextEditorWidget::drop_event(GUI::DropEvent& event)
if (urls.is_empty())
return;
if (urls.size() > 1) {
- GUI::MessageBox::show("TextEditor can only open one file at a time!", "One at a time please!", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
+ GUI::MessageBox::show(window(), "TextEditor can only open one file at a time!", "One at a time please!", GUI::MessageBox::Type::Error);
return;
}
open_sesame(urls.first().path());