diff --git a/Userland/Applications/HexEditor/CMakeLists.txt b/Userland/Applications/HexEditor/CMakeLists.txt index ab58a31109c..cfc4cd3cfa7 100644 --- a/Userland/Applications/HexEditor/CMakeLists.txt +++ b/Userland/Applications/HexEditor/CMakeLists.txt @@ -1,5 +1,6 @@ compile_gml(HexEditorWindow.gml HexEditorWindowGML.h hex_editor_window_gml) compile_gml(GoToOffsetDialog.gml GoToOffsetDialogGML.h go_to_offset_dialog_gml) +compile_gml(FindDialog.gml FindDialogGML.h find_dialog_gml) set(SOURCES HexEditor.cpp @@ -7,6 +8,7 @@ set(SOURCES FindDialog.cpp GoToOffsetDialog.cpp main.cpp + FindDialogGML.h GoToOffsetDialogGML.h HexEditorWindowGML.h ) diff --git a/Userland/Applications/HexEditor/FindDialog.cpp b/Userland/Applications/HexEditor/FindDialog.cpp index 870ed536590..84ffbfb65ca 100644 --- a/Userland/Applications/HexEditor/FindDialog.cpp +++ b/Userland/Applications/HexEditor/FindDialog.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -15,8 +16,6 @@ #include #include #include -#include -#include struct Option { String title; @@ -88,28 +87,23 @@ Result FindDialog::process_input(String text_value, OptionId FindDialog::FindDialog() : Dialog(nullptr) { - resize(280, 180 + ((static_cast(options.size()) - 3) * 16)); + resize(280, 146); center_on_screen(); set_resizable(false); set_title("Find"); - auto& main = set_main_widget(); - main.set_layout(); - main.layout()->set_margins({ 8, 8, 8, 8 }); - main.layout()->set_spacing(8); - main.set_fill_with_background_color(true); + auto& main_widget = set_main_widget(); + if (!main_widget.load_from_gml(find_dialog_gml)) + VERIFY_NOT_REACHED(); - auto& find_prompt_container = main.add(); - find_prompt_container.set_layout(); - - find_prompt_container.add("Value to find"); - - m_text_editor = find_prompt_container.add(); - m_text_editor->set_fixed_height(19); + m_text_editor = *main_widget.find_descendant_of_type_named("text_editor"); + m_ok_button = *main_widget.find_descendant_of_type_named("ok_button"); + m_cancel_button = *main_widget.find_descendant_of_type_named("cancel_button"); + auto& radio_container = *main_widget.find_descendant_of_type_named("radio_container"); for (size_t i = 0; i < options.size(); i++) { auto action = options[i]; - auto& radio = main.add(); + auto& radio = radio_container.add(); radio.set_enabled(action.enabled); radio.set_text(action.title); @@ -123,22 +117,18 @@ FindDialog::FindDialog() } } - auto& button_box = main.add(); - button_box.set_layout(); - button_box.layout()->set_spacing(8); + m_text_editor->on_return_pressed = [this] { + m_ok_button->click(); + }; - auto& ok_button = button_box.add(); - ok_button.on_click = [this](auto) { + m_ok_button->on_click = [this](auto) { m_text_value = m_text_editor->text(); done(ExecResult::ExecOK); }; - ok_button.set_text("OK"); - auto& cancel_button = button_box.add(); - cancel_button.on_click = [this](auto) { + m_cancel_button->on_click = [this](auto) { done(ExecResult::ExecCancel); }; - cancel_button.set_text("Cancel"); } FindDialog::~FindDialog() diff --git a/Userland/Applications/HexEditor/FindDialog.gml b/Userland/Applications/HexEditor/FindDialog.gml new file mode 100644 index 00000000000..5486dc77544 --- /dev/null +++ b/Userland/Applications/HexEditor/FindDialog.gml @@ -0,0 +1,46 @@ +@GUI::Widget { + name: "main" + fixed_width: 280 + fixed_height: 146 + fill_with_background_color: true + + layout: @GUI::VerticalBoxLayout { + spacing: 2 + margins: [4, 4, 4, 4] + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout + + @GUI::Label { + text: "Value to find" + fixed_width: 80 + text_alignment: "CenterLeft" + } + + @GUI::TextBox { + name: "text_editor" + fixed_height: 20 + } + } + + @GUI::Widget { + layout: @GUI::VerticalBoxLayout + + name: "radio_container" + } + + @GUI::Widget { + layout: @GUI::HorizontalBoxLayout + + @GUI::Button { + name: "ok_button" + text: "OK" + } + + @GUI::Button { + name: "cancel_button" + text: "Cancel" + } + } +} diff --git a/Userland/Applications/HexEditor/FindDialog.h b/Userland/Applications/HexEditor/FindDialog.h index 5cc9dd2b512..5c58b49cca5 100644 --- a/Userland/Applications/HexEditor/FindDialog.h +++ b/Userland/Applications/HexEditor/FindDialog.h @@ -32,6 +32,8 @@ private: virtual ~FindDialog() override; RefPtr m_text_editor; + RefPtr m_ok_button; + RefPtr m_cancel_button; String m_text_value; OptionId m_selected_option { OPTION_INVALID };