Skip to content

Commit

Permalink
LibGUI+Userland: Make Dialog::ExecResult an enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
AtkinsSJ authored and linusg committed May 13, 2022
1 parent 1f82bed commit cdffe55
Show file tree
Hide file tree
Showing 90 changed files with 232 additions and 232 deletions.
10 changes: 5 additions & 5 deletions Userland/Applications/Browser/BookmarksBarWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BookmarkEditor final : public GUI::Dialog {
editor->set_title("Edit Bookmark");
editor->set_icon(g_icon_bag.bookmark_filled);

if (editor->exec() == Dialog::ExecOK) {
if (editor->exec() == ExecResult::OK) {
return Vector<JsonValue> { editor->title(), editor->url() };
}

Expand All @@ -58,23 +58,23 @@ class BookmarkEditor final : public GUI::Dialog {
m_title_textbox->set_focus(true);
m_title_textbox->select_all();
m_title_textbox->on_return_pressed = [this] {
done(Dialog::ExecOK);
done(ExecResult::OK);
};

m_url_textbox = *widget.find_descendant_of_type_named<GUI::TextBox>("url_textbox");
m_url_textbox->set_text(url);
m_url_textbox->on_return_pressed = [this] {
done(Dialog::ExecOK);
done(ExecResult::OK);
};

auto& ok_button = *widget.find_descendant_of_type_named<GUI::Button>("ok_button");
ok_button.on_click = [this](auto) {
done(Dialog::ExecOK);
done(ExecResult::OK);
};

auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.on_click = [this](auto) {
done(Dialog::ExecCancel);
done(ExecResult::Cancel);
};
}

Expand Down
6 changes: 3 additions & 3 deletions Userland/Applications/Browser/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ void BrowserWindow::build_menus()
m_change_homepage_action = GUI::Action::create(
"Set Homepage URL...", g_icon_bag.go_home, [this](auto&) {
auto homepage_url = Config::read_string("Browser", "Preferences", "Home", "about:blank");
if (GUI::InputBox::show(this, homepage_url, "Enter URL", "Change homepage URL") == GUI::InputBox::ExecOK) {
if (GUI::InputBox::show(this, homepage_url, "Enter URL", "Change homepage URL") == GUI::InputBox::ExecResult::OK) {
if (URL(homepage_url).is_valid()) {
Config::write_string("Browser", "Preferences", "Home", homepage_url);
Browser::g_home_url = homepage_url;
Expand Down Expand Up @@ -373,7 +373,7 @@ void BrowserWindow::build_menus()

auto custom_user_agent = GUI::Action::create_checkable("Custom...", [this](auto& action) {
String user_agent;
if (GUI::InputBox::show(this, user_agent, "Enter User Agent:", "Custom User Agent") != GUI::InputBox::ExecOK || user_agent.is_empty() || user_agent.is_null()) {
if (GUI::InputBox::show(this, user_agent, "Enter User Agent:", "Custom User Agent") != GUI::InputBox::ExecResult::OK || user_agent.is_empty() || user_agent.is_null()) {
m_disable_user_agent_spoofing->activate();
return;
}
Expand Down Expand Up @@ -455,7 +455,7 @@ ErrorOr<void> BrowserWindow::load_search_engines(GUI::Menu& settings_menu)

auto custom_search_engine_action = GUI::Action::create_checkable("Custom...", [&](auto& action) {
String search_engine;
if (GUI::InputBox::show(this, search_engine, "Enter URL template:", "Custom Search Engine", "https://host/search?q={}") != GUI::InputBox::ExecOK || search_engine.is_empty()) {
if (GUI::InputBox::show(this, search_engine, "Enter URL template:", "Custom Search Engine", "https://host/search?q={}") != GUI::InputBox::ExecResult::OK || search_engine.is_empty()) {
m_disable_search_engine_action->activate();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ContentFilterSettingsWidget::ContentFilterSettingsWidget()

m_add_new_domain_button->on_click = [&](unsigned) {
String text;
if (GUI::InputBox::show(window(), text, "Enter domain name", "Add domain to Content Filter") == GUI::Dialog::ExecOK) {
if (GUI::InputBox::show(window(), text, "Enter domain name", "Add domain to Content Filter") == GUI::Dialog::ExecResult::OK) {
m_domain_list_model->add_domain(std::move(text));
set_modified(true);
}
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/Calendar/AddEventDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ AddEventDialog::AddEventDialog(Core::DateTime date_time, Window* parent_window)
ok_button.set_fixed_size(80, 20);
ok_button.on_click = [this](auto) {
dbgln("TODO: Add event icon on specific tile");
done(Dialog::ExecOK);
done(ExecResult::OK);
};

event_title_textbox.set_focus(true);
Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/CharacterMap/CharacterMapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CharacterMapWidget::CharacterMapWidget()

m_choose_font_action = GUI::Action::create("Choose Font...", Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-font-editor.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
auto font_picker = GUI::FontPicker::construct(window(), &font(), false);
if (font_picker->exec() == GUI::Dialog::ExecOK) {
if (font_picker->exec() == GUI::Dialog::ExecResult::OK) {
auto& font = *font_picker->font();
Config::write_string("CharacterMap", "History", "Font", font.qualified_name());
set_font(font);
Expand Down Expand Up @@ -70,7 +70,7 @@ CharacterMapWidget::CharacterMapWidget()

m_go_to_glyph_action = GUI::Action::create("Go to glyph...", { Mod_Ctrl, Key_G }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-to.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
String input;
if (GUI::InputBox::show(window(), input, "Hexadecimal:", "Go to glyph") == GUI::InputBox::ExecOK && !input.is_empty()) {
if (GUI::InputBox::show(window(), input, "Hexadecimal:", "Go to glyph") == GUI::InputBox::ExecResult::OK && !input.is_empty()) {
auto maybe_code_point = AK::StringUtils::convert_to_uint_from_hex(input);
if (!maybe_code_point.has_value())
return;
Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/DisplaySettings/FontSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FontSettingsWidget::FontSettingsWidget()
auto& default_font_button = *find_descendant_of_type_named<GUI::Button>("default_font_button");
default_font_button.on_click = [this](auto) {
auto font_picker = GUI::FontPicker::construct(window(), &m_default_font_label->font(), false);
if (font_picker->exec() == GUI::Dialog::ExecOK) {
if (font_picker->exec() == GUI::Dialog::ExecResult::OK) {
update_label_with_font(*m_default_font_label, *font_picker->font());
set_modified(true);
}
Expand All @@ -41,7 +41,7 @@ FontSettingsWidget::FontSettingsWidget()
auto& fixed_width_font_button = *find_descendant_of_type_named<GUI::Button>("fixed_width_font_button");
fixed_width_font_button.on_click = [this](auto) {
auto font_picker = GUI::FontPicker::construct(window(), &m_fixed_width_font_label->font(), true);
if (font_picker->exec() == GUI::Dialog::ExecOK) {
if (font_picker->exec() == GUI::Dialog::ExecResult::OK) {
update_label_with_font(*m_fixed_width_font_label, *font_picker->font());
set_modified(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void MonitorSettingsWidget::apply_settings()
revert_timer->start();

// If the user selects "No", closes the window or the window gets closed by the 10 seconds timer, revert the changes.
if (box->exec() == GUI::MessageBox::ExecYes) {
if (box->exec() == GUI::MessageBox::ExecResult::Yes) {
auto save_result = GUI::ConnectionToWindowServer::the().save_screen_layout();
if (!save_result.success()) {
GUI::MessageBox::show(window(), String::formatted("Error saving settings: {}", save_result.error_msg()),
Expand Down
4 changes: 2 additions & 2 deletions Userland/Applications/FileManager/DirectoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ void DirectoryView::setup_actions()
{
m_mkdir_action = GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png").release_value_but_fixme_should_propagate_errors(), [&](GUI::Action const&) {
String value;
if (GUI::InputBox::show(window(), value, "Enter name:", "New directory") == GUI::InputBox::ExecOK && !value.is_empty()) {
if (GUI::InputBox::show(window(), value, "Enter name:", "New directory") == GUI::InputBox::ExecResult::OK && !value.is_empty()) {
auto new_dir_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value));
int rc = mkdir(new_dir_path.characters(), 0777);
if (rc < 0) {
Expand All @@ -554,7 +554,7 @@ void DirectoryView::setup_actions()

m_touch_action = GUI::Action::create("New &File...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png").release_value_but_fixme_should_propagate_errors(), [&](GUI::Action const&) {
String value;
if (GUI::InputBox::show(window(), value, "Enter name:", "New file") == GUI::InputBox::ExecOK && !value.is_empty()) {
if (GUI::InputBox::show(window(), value, "Enter name:", "New file") == GUI::InputBox::ExecResult::OK && !value.is_empty()) {
auto new_file_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value));
struct stat st;
int rc = stat(new_file_path.characters(), &st);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/FileManager/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void delete_paths(Vector<String> const& paths, bool should_confirm, GUI::Window*
"Confirm deletion",
GUI::MessageBox::Type::Warning,
GUI::MessageBox::InputType::OKCancel);
if (result == GUI::MessageBox::ExecCancel)
if (result == GUI::MessageBox::ExecResult::Cancel)
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/FileManager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void do_create_link(Vector<String> const& selected_file_paths, GUI::Window* wind
void do_create_archive(Vector<String> const& selected_file_paths, GUI::Window* window)
{
String archive_name;
if (GUI::InputBox::show(window, archive_name, "Enter name:", "Create Archive") != GUI::InputBox::ExecOK)
if (GUI::InputBox::show(window, archive_name, "Enter name:", "Create Archive") != GUI::InputBox::ExecResult::OK)
return;

auto output_directory_path = LexicalPath(selected_file_paths.first());
Expand Down
8 changes: 4 additions & 4 deletions Userland/Applications/FontEditor/FontEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ FontEditorWidget::FontEditorWidget()
if (!request_close())
return;
auto new_font_wizard = NewFontDialog::construct(window());
if (new_font_wizard->exec() == GUI::Dialog::ExecOK) {
if (new_font_wizard->exec() == GUI::Dialog::ExecResult::OK) {
auto metadata = new_font_wizard->new_font_metadata();
auto new_font = Gfx::BitmapFont::create(metadata.glyph_height, metadata.glyph_width, metadata.is_fixed_width, 0x110000);
new_font->set_name(metadata.name);
Expand Down Expand Up @@ -241,7 +241,7 @@ FontEditorWidget::FontEditorWidget()

m_go_to_glyph_action = GUI::Action::create("&Go to Glyph...", { Mod_Ctrl, Key_G }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-to.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
String input;
if (GUI::InputBox::show(window(), input, "Hexadecimal:", "Go to glyph") == GUI::InputBox::ExecOK && !input.is_empty()) {
if (GUI::InputBox::show(window(), input, "Hexadecimal:", "Go to glyph") == GUI::InputBox::ExecResult::OK && !input.is_empty()) {
auto maybe_code_point = AK::StringUtils::convert_to_uint_from_hex(input);
if (!maybe_code_point.has_value())
return;
Expand Down Expand Up @@ -782,12 +782,12 @@ bool FontEditorWidget::request_close()
if (!window()->is_modified())
return true;
auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), m_path, m_undo_stack->last_unmodified_timestamp());
if (result == GUI::MessageBox::ExecYes) {
if (result == GUI::MessageBox::ExecResult::Yes) {
m_save_action->activate();
if (!window()->is_modified())
return true;
}
if (result == GUI::MessageBox::ExecNo)
if (result == GUI::MessageBox::ExecResult::No)
return true;
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions Userland/Applications/HexEditor/FindDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static constexpr Array<Option, 2> options = {
}
};

int FindDialog::show(GUI::Window* parent_window, String& out_text, ByteBuffer& out_buffer, bool& find_all)
GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out_text, ByteBuffer& out_buffer, bool& find_all)
{
auto dialog = FindDialog::construct();

Expand All @@ -46,7 +46,7 @@ int FindDialog::show(GUI::Window* parent_window, String& out_text, ByteBuffer& o

auto result = dialog->exec();

if (result != GUI::Dialog::ExecOK)
if (result != ExecResult::OK)
return result;

auto selected_option = dialog->selected_option();
Expand All @@ -56,7 +56,7 @@ int FindDialog::show(GUI::Window* parent_window, String& out_text, ByteBuffer& o

if (processed.is_error()) {
GUI::MessageBox::show_error(parent_window, processed.error());
result = GUI::Dialog::ExecAborted;
result = ExecResult::Aborted;
} else {
out_buffer = move(processed.value());
}
Expand Down Expand Up @@ -138,7 +138,7 @@ FindDialog::FindDialog()
auto text = m_text_editor->text();
if (!text.is_empty()) {
m_text_value = text;
done(ExecResult::ExecOK);
done(ExecResult::OK);
}
};

Expand All @@ -148,6 +148,6 @@ FindDialog::FindDialog()
};

m_cancel_button->on_click = [this](auto) {
done(ExecResult::ExecCancel);
done(ExecResult::Cancel);
};
}
2 changes: 1 addition & 1 deletion Userland/Applications/HexEditor/FindDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FindDialog : public GUI::Dialog {
C_OBJECT(FindDialog);

public:
static int show(GUI::Window* parent_window, String& out_tex, ByteBuffer& out_buffer, bool& find_all);
static ExecResult show(GUI::Window* parent_window, String& out_tex, ByteBuffer& out_buffer, bool& find_all);

private:
Result<ByteBuffer, String> process_input(String text_value, OptionId opt);
Expand Down
8 changes: 4 additions & 4 deletions Userland/Applications/HexEditor/GoToOffsetDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <LibGUI/TextBox.h>
#include <LibGUI/Widget.h>

int GoToOffsetDialog::show(GUI::Window* parent_window, int& history_offset, int& out_offset, int selection_offset, int buffer_size)
GUI::Dialog::ExecResult GoToOffsetDialog::show(GUI::Window* parent_window, int& history_offset, int& out_offset, int selection_offset, int buffer_size)
{
auto dialog = GoToOffsetDialog::construct();
dialog->m_selection_offset = selection_offset;
Expand All @@ -31,7 +31,7 @@ int GoToOffsetDialog::show(GUI::Window* parent_window, int& history_offset, int&

auto result = dialog->exec();

if (result != GUI::Dialog::ExecOK)
if (result != ExecResult::OK)
return result;

auto input_offset = dialog->process_input();
Expand All @@ -41,7 +41,7 @@ int GoToOffsetDialog::show(GUI::Window* parent_window, int& history_offset, int&
dbgln("Go to offset: value={}", new_offset);
out_offset = move(new_offset);

return GUI::Dialog::ExecOK;
return ExecResult::OK;
}

int GoToOffsetDialog::process_input()
Expand Down Expand Up @@ -124,7 +124,7 @@ GoToOffsetDialog::GoToOffsetDialog()
};

m_go_button->on_click = [this](auto) {
done(ExecResult::ExecOK);
done(ExecResult::OK);
};

m_text_editor->on_change = [this]() {
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/HexEditor/GoToOffsetDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GoToOffsetDialog : public GUI::Dialog {
C_OBJECT(GoToOffsetDialog);

public:
static int show(GUI::Window* parent_window, int& history_offset, int& out_offset, int selection_offset, int end);
static ExecResult show(GUI::Window* parent_window, int& history_offset, int& out_offset, int selection_offset, int end);

private:
GoToOffsetDialog();
Expand Down
12 changes: 6 additions & 6 deletions Userland/Applications/HexEditor/HexEditorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ HexEditorWidget::HexEditorWidget()

m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png").release_value_but_fixme_should_propagate_errors(), [this](const GUI::Action&) {
String value;
if (request_close() && GUI::InputBox::show(window(), value, "Enter new file size:", "New file size") == GUI::InputBox::ExecOK && !value.is_empty()) {
if (request_close() && GUI::InputBox::show(window(), value, "Enter new file size:", "New file size") == GUI::InputBox::ExecResult::OK && !value.is_empty()) {
auto file_size = value.to_int();
if (file_size.has_value() && file_size.value() > 0) {
window()->set_modified(false);
Expand Down Expand Up @@ -151,7 +151,7 @@ HexEditorWidget::HexEditorWidget()
m_find_action = GUI::Action::create("&Find", { Mod_Ctrl, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png").release_value_but_fixme_should_propagate_errors(), [&](const GUI::Action&) {
auto old_buffer = m_search_buffer;
bool find_all = false;
if (FindDialog::show(window(), m_search_text, m_search_buffer, find_all) == GUI::InputBox::ExecOK) {
if (FindDialog::show(window(), m_search_text, m_search_buffer, find_all) == GUI::InputBox::ExecResult::OK) {
if (find_all) {
auto matches = m_editor->find_all(m_search_buffer, 0);
m_search_results->set_model(*new SearchResultsModel(move(matches)));
Expand Down Expand Up @@ -193,7 +193,7 @@ HexEditorWidget::HexEditorWidget()
new_offset,
m_editor->selection_start_offset(),
m_editor->buffer_size());
if (result == GUI::InputBox::ExecOK) {
if (result == GUI::InputBox::ExecResult::OK) {
m_editor->highlight(new_offset, new_offset);
m_editor->update();
}
Expand Down Expand Up @@ -225,7 +225,7 @@ HexEditorWidget::HexEditorWidget()

m_fill_selection_action = GUI::Action::create("Fill &Selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) {
String value;
if (GUI::InputBox::show(window(), value, "Fill byte (hex):", "Fill Selection") == GUI::InputBox::ExecOK && !value.is_empty()) {
if (GUI::InputBox::show(window(), value, "Fill byte (hex):", "Fill Selection") == GUI::InputBox::ExecResult::OK && !value.is_empty()) {
auto fill_byte = strtol(value.characters(), nullptr, 16);
m_editor->fill_selection(fill_byte);
}
Expand Down Expand Up @@ -508,11 +508,11 @@ bool HexEditorWidget::request_close()
return true;

auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), m_path);
if (result == GUI::MessageBox::ExecYes) {
if (result == GUI::MessageBox::ExecResult::Yes) {
m_save_action->activate();
return !window()->is_modified();
}
return result == GUI::MessageBox::ExecNo;
return result == GUI::MessageBox::ExecResult::No;
}

void HexEditorWidget::set_search_results_visible(bool visible)
Expand Down
2 changes: 1 addition & 1 deletion Userland/Applications/ImageViewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
GUI::MessageBox::Type::Warning,
GUI::MessageBox::InputType::OKCancel);

if (msgbox_result == GUI::MessageBox::ExecCancel)
if (msgbox_result == GUI::MessageBox::ExecResult::Cancel)
return;

auto unlinked_or_error = Core::System::unlink(widget->path());
Expand Down
6 changes: 3 additions & 3 deletions Userland/Applications/KeyboardMapper/KeyboardMapperWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ bool KeyboardMapperWidget::request_close()
if (!window()->is_modified())
return true;
auto result = GUI::MessageBox::ask_about_unsaved_changes(window(), m_filename);
if (result == GUI::MessageBox::ExecYes) {
if (result == GUI::MessageBox::ExecResult::Yes) {
ErrorOr<void> error_or = save();
if (error_or.is_error())
show_error_to_user(error_or.error());

if (!window()->is_modified())
return true;
}
return result == GUI::MessageBox::ExecNo;
return result == GUI::MessageBox::ExecResult::No;
}

void KeyboardMapperWidget::create_frame()
Expand All @@ -58,7 +58,7 @@ void KeyboardMapperWidget::create_frame()

tmp_button.on_click = [this, &tmp_button]() {
String value;
if (GUI::InputBox::show(window(), value, "New Character:", "Select Character") == GUI::InputBox::ExecOK) {
if (GUI::InputBox::show(window(), value, "New Character:", "Select Character") == GUI::InputBox::ExecResult::OK) {
int i = m_keys.find_first_index(&tmp_button).value_or(0);
VERIFY(i > 0);

Expand Down
Loading

0 comments on commit cdffe55

Please sign in to comment.