1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibGUI+Userland: Make Dialog::ExecResult an enum class

This commit is contained in:
Sam Atkins 2022-05-13 13:10:27 +01:00 committed by Linus Groh
parent 1f82beded3
commit cdffe556c8
90 changed files with 232 additions and 232 deletions

View file

@ -82,7 +82,7 @@ AboutDialog::AboutDialog(StringView name, Gfx::Bitmap const* icon, Window* paren
auto& ok_button = button_container.add<Button>("OK");
ok_button.set_fixed_width(80);
ok_button.on_click = [this](auto) {
done(Dialog::ExecOK);
done(ExecResult::OK);
};
}

View file

@ -72,7 +72,7 @@ void ColorInput::mouseup_event(MouseEvent& event)
if (is_color_rect_click) {
auto dialog = GUI::ColorPicker::construct(m_color, window(), m_color_picker_title);
dialog->set_color_has_alpha_channel(m_color_has_alpha_channel);
if (dialog->exec() == GUI::Dialog::ExecOK)
if (dialog->exec() == GUI::Dialog::ExecResult::OK)
set_color(dialog->color());
event.accept();
return;

View file

@ -236,14 +236,14 @@ void ColorPicker::build_ui()
ok_button.set_fixed_width(80);
ok_button.set_text("OK");
ok_button.on_click = [this](auto) {
done(ExecOK);
done(ExecResult::OK);
};
auto& cancel_button = button_container.add<Button>();
cancel_button.set_fixed_width(80);
cancel_button.set_text("Cancel");
cancel_button.on_click = [this](auto) {
done(ExecCancel);
done(ExecResult::Cancel);
};
}
@ -464,7 +464,7 @@ void ColorButton::doubleclick_event(GUI::MouseEvent&)
{
click();
m_selected = true;
m_picker.done(Dialog::ExecOK);
m_picker.done(Dialog::ExecResult::OK);
}
void ColorButton::paint_event(PaintEvent& event)

View file

@ -288,7 +288,7 @@ void CommandPalette::finish_with_index(GUI::ModelIndex const& filter_index)
auto* action = static_cast<GUI::Action*>(action_index.internal_data());
VERIFY(action);
m_selected_action = action;
done(ExecOK);
done(ExecResult::OK);
}
}

View file

@ -184,7 +184,7 @@ void ConnectionToWindowServer::key_down(i32 window_id, u32 code_point, u32 key,
bool focused_widget_accepts_emoji_input = window->focused_widget() && window->focused_widget()->accepts_emoji_input();
if (focused_widget_accepts_emoji_input && (modifiers == (Mod_Ctrl | Mod_Alt)) && key == Key_Space) {
auto emoji_input_dialog = EmojiInputDialog::construct(window);
if (emoji_input_dialog->exec() != EmojiInputDialog::ExecOK)
if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK)
return;
key_event->m_key = Key_Invalid;
key_event->m_modifiers = 0;
@ -203,7 +203,7 @@ void ConnectionToWindowServer::key_down(i32 window_id, u32 code_point, u32 key,
if (accepts_command_palette && !m_in_command_palette && modifiers == (Mod_Ctrl | Mod_Shift) && key == Key_A) {
auto command_palette = CommandPalette::construct(*window);
TemporaryChange change { m_in_command_palette, true };
if (command_palette->exec() != GUI::Dialog::ExecOK)
if (command_palette->exec() != GUI::Dialog::ExecResult::OK)
return;
auto* action = command_palette->selected_action();
VERIFY(action);

View file

@ -20,7 +20,7 @@ Dialog::Dialog(Window* parent_window, ScreenPosition screen_position)
set_minimizable(false);
}
int Dialog::exec()
Dialog::ExecResult Dialog::exec()
{
VERIFY(!m_event_loop);
m_event_loop = make<Core::EventLoop>();
@ -87,16 +87,16 @@ int Dialog::exec()
m_event_loop = nullptr;
dbgln("{}: Event loop returned with result {}", *this, result);
remove_from_parent();
return result;
return static_cast<ExecResult>(result);
}
void Dialog::done(int result)
void Dialog::done(ExecResult result)
{
if (!m_event_loop)
return;
m_result = result;
dbgln("{}: Quit event loop with result {}", *this, result);
m_event_loop->quit(result);
dbgln("{}: Quit event loop with result {}", *this, to_underlying(result));
m_event_loop->quit(to_underlying(result));
}
void Dialog::event(Core::Event& event)
@ -104,7 +104,7 @@ void Dialog::event(Core::Event& event)
if (event.type() == Event::KeyUp || event.type() == Event::KeyDown) {
auto& key_event = static_cast<KeyEvent&>(event);
if (key_event.key() == KeyCode::Key_Escape) {
done(ExecCancel);
done(ExecResult::Cancel);
event.accept();
return;
}
@ -116,7 +116,7 @@ void Dialog::event(Core::Event& event)
void Dialog::close()
{
Window::close();
done(ExecCancel);
done(ExecResult::Cancel);
}
}

View file

@ -15,12 +15,12 @@ namespace GUI {
class Dialog : public Window {
C_OBJECT(Dialog)
public:
enum ExecResult {
ExecOK = 0,
ExecCancel = 1,
ExecAborted = 2,
ExecYes = 3,
ExecNo = 4,
enum class ExecResult {
OK = 0,
Cancel = 1,
Aborted = 2,
Yes = 3,
No = 4,
};
enum ScreenPosition {
CenterWithinParent = 0,
@ -40,10 +40,10 @@ public:
virtual ~Dialog() override = default;
int exec();
ExecResult exec();
int result() const { return m_result; }
void done(int result);
ExecResult result() const { return m_result; }
void done(ExecResult);
virtual void event(Core::Event&) override;
@ -54,7 +54,7 @@ protected:
private:
OwnPtr<Core::EventLoop> m_event_loop;
int m_result { ExecAborted };
ExecResult m_result { ExecResult::Aborted };
int m_screen_position { CenterWithinParent };
};

View file

@ -85,7 +85,7 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
button.set_button_style(Gfx::ButtonStyle::Coolbar);
button.on_click = [this, button = &button](auto) {
m_selected_emoji_text = button->text();
done(ExecOK);
done(ExecResult::OK);
};
} else {
horizontal_container.add<Widget>();
@ -99,7 +99,7 @@ void EmojiInputDialog::event(Core::Event& event)
if (event.type() == Event::KeyDown) {
auto& key_event = static_cast<KeyEvent&>(event);
if (key_event.key() == Key_Escape) {
done(ExecCancel);
done(ExecResult::Cancel);
return;
}
}

View file

@ -39,7 +39,7 @@ Optional<String> FilePicker::get_open_filepath(Window* parent_window, String con
if (!window_title.is_null())
picker->set_title(window_title);
if (picker->exec() == Dialog::ExecOK) {
if (picker->exec() == ExecResult::OK) {
String file_path = picker->selected_file();
if (file_path.is_null())
@ -54,7 +54,7 @@ Optional<String> FilePicker::get_save_filepath(Window* parent_window, String con
{
auto picker = FilePicker::construct(parent_window, Mode::Save, String::formatted("{}.{}", title, extension), path, screen_position);
if (picker->exec() == Dialog::ExecOK) {
if (picker->exec() == ExecResult::OK) {
String file_path = picker->selected_file();
if (file_path.is_null())
@ -131,7 +131,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
auto mkdir_action = 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(), [this](Action const&) {
String value;
if (InputBox::show(this, value, "Enter name:", "New directory") == InputBox::ExecOK && !value.is_empty()) {
if (InputBox::show(this, value, "Enter name:", "New directory") == InputBox::ExecResult::OK && !value.is_empty()) {
auto new_dir_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", m_model->root_path(), value));
int rc = mkdir(new_dir_path.characters(), 0777);
if (rc < 0) {
@ -185,7 +185,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.set_text("Cancel");
cancel_button.on_click = [this](auto) {
done(ExecCancel);
done(ExecResult::Cancel);
};
m_filename_textbox->on_change = [&] {
@ -278,12 +278,12 @@ void FilePicker::on_file_return()
if (file_exists && m_mode == Mode::Save) {
auto result = MessageBox::show(this, "File already exists. Overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel);
if (result == MessageBox::ExecCancel)
if (result == MessageBox::ExecResult::Cancel)
return;
}
m_selected_file = path;
done(ExecOK);
done(ExecResult::OK);
}
void FilePicker::set_path(String const& path)

View file

@ -159,12 +159,12 @@ FontPicker::FontPicker(Window* parent_window, Gfx::Font const* current_font, boo
auto& ok_button = *widget.find_descendant_of_type_named<GUI::Button>("ok_button");
ok_button.on_click = [this](auto) {
done(ExecOK);
done(ExecResult::OK);
};
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.on_click = [this](auto) {
done(ExecCancel);
done(ExecResult::Cancel);
};
set_font(current_font);

View file

@ -25,7 +25,7 @@ InputBox::InputBox(Window* parent_window, String& text_value, StringView prompt,
build(input_type);
}
int InputBox::show(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
Dialog::ExecResult InputBox::show(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
{
auto box = InputBox::construct(parent_window, text_value, prompt, title, placeholder, input_type);
box->set_resizable(false);
@ -87,7 +87,7 @@ void InputBox::build(InputType input_type)
m_ok_button->on_click = [this](auto) {
dbgln("GUI::InputBox: OK button clicked");
m_text_value = m_text_editor->text();
done(ExecOK);
done(ExecResult::OK);
};
m_ok_button->set_default(true);
@ -95,7 +95,7 @@ void InputBox::build(InputType input_type)
m_cancel_button->set_text("Cancel");
m_cancel_button->on_click = [this](auto) {
dbgln("GUI::InputBox: Cancel button clicked");
done(ExecCancel);
done(ExecResult::Cancel);
};
m_text_editor->on_escape_pressed = [this] {

View file

@ -22,7 +22,7 @@ class InputBox : public Dialog {
public:
virtual ~InputBox() override = default;
static int show(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder = {}, InputType input_type = InputType::Text);
static ExecResult show(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder = {}, InputType input_type = InputType::Text);
private:
explicit InputBox(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type);

View file

@ -16,7 +16,7 @@
namespace GUI {
int MessageBox::show(Window* parent_window, StringView text, StringView title, Type type, InputType input_type)
Dialog::ExecResult MessageBox::show(Window* parent_window, StringView text, StringView title, Type type, InputType input_type)
{
auto box = MessageBox::construct(parent_window, text, title, type, input_type);
if (parent_window)
@ -24,12 +24,12 @@ int MessageBox::show(Window* parent_window, StringView text, StringView title, T
return box->exec();
}
int MessageBox::show_error(Window* parent_window, StringView text)
Dialog::ExecResult MessageBox::show_error(Window* parent_window, StringView text)
{
return show(parent_window, text, "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK);
}
int MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp)
Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp)
{
StringBuilder builder;
builder.append("Save changes to ");
@ -151,7 +151,7 @@ void MessageBox::build()
constexpr int button_width = 80;
int button_count = 0;
auto add_button = [&](String label, Dialog::ExecResult result) -> GUI::Button& {
auto add_button = [&](String label, ExecResult result) -> GUI::Button& {
auto& button = button_container.add<Button>();
button.set_fixed_width(button_width);
button.set_text(label);
@ -164,13 +164,13 @@ void MessageBox::build()
button_container.layout()->add_spacer();
if (should_include_ok_button())
m_ok_button = add_button("OK", Dialog::ExecOK);
m_ok_button = add_button("OK", ExecResult::OK);
if (should_include_yes_button())
m_yes_button = add_button("Yes", Dialog::ExecYes);
m_yes_button = add_button("Yes", ExecResult::Yes);
if (should_include_no_button())
m_no_button = add_button("No", Dialog::ExecNo);
m_no_button = add_button("No", ExecResult::No);
if (should_include_cancel_button())
m_cancel_button = add_button("Cancel", Dialog::ExecCancel);
m_cancel_button = add_button("Cancel", ExecResult::Cancel);
button_container.layout()->add_spacer();
int width = (button_count * button_width) + ((button_count - 1) * button_container.layout()->spacing()) + 32;

View file

@ -32,9 +32,9 @@ public:
virtual ~MessageBox() override = default;
static int show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
static int show_error(Window* parent_window, StringView text);
static int ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
static ExecResult show(Window* parent_window, StringView text, StringView title, Type type = Type::None, InputType input_type = InputType::OK);
static ExecResult show_error(Window* parent_window, StringView text);
static ExecResult ask_about_unsaved_changes(Window* parent_window, StringView path, Optional<Time> last_unmodified_timestamp = {});
void set_text(String text);

View file

@ -42,13 +42,13 @@ PasswordInputDialog::PasswordInputDialog(Window* parent_window, String title, St
ok_button.on_click = [&](auto) {
dbgln("GUI::PasswordInputDialog: OK button clicked");
m_password = password_box.text();
done(ExecOK);
done(ExecResult::OK);
};
auto& cancel_button = *widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
cancel_button.on_click = [this](auto) {
dbgln("GUI::PasswordInputDialog: Cancel button clicked");
done(ExecCancel);
done(ExecResult::Cancel);
};
password_box.on_return_pressed = [&] {
@ -60,7 +60,7 @@ PasswordInputDialog::PasswordInputDialog(Window* parent_window, String title, St
password_box.set_focus(true);
}
int PasswordInputDialog::show(Window* parent_window, String& text_value, String title, String server, String username)
Dialog::ExecResult PasswordInputDialog::show(Window* parent_window, String& text_value, String title, String server, String username)
{
auto box = PasswordInputDialog::construct(parent_window, move(title), move(server), move(username));
auto result = box->exec();

View file

@ -17,7 +17,7 @@ class PasswordInputDialog : public Dialog {
public:
virtual ~PasswordInputDialog() override = default;
static int show(Window* parent_window, String& text_value, String title, String server, String username);
static ExecResult show(Window* parent_window, String& text_value, String title, String server, String username);
private:
explicit PasswordInputDialog(Window* parent_window, String title, String server, String username);

View file

@ -65,7 +65,7 @@ ProcessChooser::ProcessChooser(StringView window_title, StringView button_label,
auto& cancel_button = button_container.add<GUI::Button>("Cancel");
cancel_button.set_fixed_width(80);
cancel_button.on_click = [this](auto) {
done(ExecCancel);
done(ExecResult::Cancel);
};
m_process_model->update();
@ -102,7 +102,7 @@ ProcessChooser::ProcessChooser(StringView window_title, StringView button_label,
void ProcessChooser::set_pid_from_index_and_close(ModelIndex const& index)
{
m_pid = index.data(GUI::ModelRole::Custom).as_i32();
done(ExecOK);
done(ExecResult::OK);
}
}

View file

@ -81,10 +81,10 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(String title, Show
auto result = MessageBox::show(window, "Apply these settings before closing?", "Unsaved changes", MessageBox::Type::Warning, MessageBox::InputType::YesNoCancel);
switch (result) {
case MessageBox::ExecYes:
case MessageBox::ExecResult::Yes:
window->apply_settings();
return Window::CloseRequestDecision::Close;
case MessageBox::ExecNo:
case MessageBox::ExecResult::No:
window->cancel_settings();
return Window::CloseRequestDecision::Close;
default:

View file

@ -94,7 +94,7 @@ void TextEditor::create_actions()
m_go_to_line_action = Action::create(
"Go to line...", { Mod_Ctrl, Key_L }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-to.png").release_value_but_fixme_should_propagate_errors(), [this](auto&) {
String value;
if (InputBox::show(window(), value, "Line:", "Go to line") == InputBox::ExecOK) {
if (InputBox::show(window(), value, "Line:", "Go to line") == InputBox::ExecResult::OK) {
auto line_target = value.to_uint();
if (line_target.has_value()) {
set_cursor_and_focus_line(line_target.value() - 1, 0);

View file

@ -58,11 +58,11 @@ WizardDialog::WizardDialog(Window* parent_window)
VERIFY(has_pages());
if (!current_page().can_go_next())
return done(ExecOK);
return done(ExecResult::OK);
auto next_page = current_page().next_page();
if (!next_page)
return done(ExecOK);
return done(ExecResult::OK);
push_page(*next_page);
};
@ -143,7 +143,7 @@ void WizardDialog::handle_cancel()
if (on_cancel)
return on_cancel();
done(ExecCancel);
done(ExecResult::Cancel);
}
}

View file

@ -329,13 +329,13 @@ void OutOfProcessWebView::notify_server_did_request_alert(Badge<WebContentClient
bool OutOfProcessWebView::notify_server_did_request_confirm(Badge<WebContentClient>, String const& message)
{
auto confirm_result = GUI::MessageBox::show(window(), message, "Confirm", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel);
return confirm_result == GUI::Dialog::ExecResult::ExecOK;
return confirm_result == GUI::Dialog::ExecResult::OK;
}
String OutOfProcessWebView::notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_)
{
String response { default_ };
if (GUI::InputBox::show(window(), response, message, "Prompt") == GUI::InputBox::ExecOK)
if (GUI::InputBox::show(window(), response, message, "Prompt") == GUI::InputBox::ExecResult::OK)
return response;
return {};
}