diff options
author | Brendan Coles <bcoles@gmail.com> | 2021-05-25 11:22:05 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-25 13:17:28 +0100 |
commit | 16094baffcc8c0c3cdaa2cd7a5f4562918d4c492 (patch) | |
tree | 081930f8514cc94fac1ce108466a2942567c4ac5 /Userland/Applications | |
parent | 7997c02b6c1a56404d5a854a6b85f41a673b944a (diff) | |
download | serenity-16094baffcc8c0c3cdaa2cd7a5f4562918d4c492.zip |
HexEditor: Construct Find dialog from GML
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/HexEditor/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Userland/Applications/HexEditor/FindDialog.cpp | 40 | ||||
-rw-r--r-- | Userland/Applications/HexEditor/FindDialog.gml | 46 | ||||
-rw-r--r-- | Userland/Applications/HexEditor/FindDialog.h | 2 |
4 files changed, 65 insertions, 25 deletions
diff --git a/Userland/Applications/HexEditor/CMakeLists.txt b/Userland/Applications/HexEditor/CMakeLists.txt index ab58a31109..cfc4cd3cfa 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 870ed53659..84ffbfb65c 100644 --- a/Userland/Applications/HexEditor/FindDialog.cpp +++ b/Userland/Applications/HexEditor/FindDialog.cpp @@ -8,6 +8,7 @@ #include <AK/Hex.h> #include <AK/String.h> #include <AK/Vector.h> +#include <Applications/HexEditor/FindDialogGML.h> #include <LibGUI/BoxLayout.h> #include <LibGUI/Button.h> #include <LibGUI/Label.h> @@ -15,8 +16,6 @@ #include <LibGUI/RadioButton.h> #include <LibGUI/TextBox.h> #include <LibGUI/Widget.h> -#include <LibGfx/Font.h> -#include <LibGfx/FontDatabase.h> struct Option { String title; @@ -88,28 +87,23 @@ Result<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId FindDialog::FindDialog() : Dialog(nullptr) { - resize(280, 180 + ((static_cast<int>(options.size()) - 3) * 16)); + resize(280, 146); center_on_screen(); set_resizable(false); set_title("Find"); - auto& main = set_main_widget<GUI::Widget>(); - main.set_layout<GUI::VerticalBoxLayout>(); - main.layout()->set_margins({ 8, 8, 8, 8 }); - main.layout()->set_spacing(8); - main.set_fill_with_background_color(true); - - auto& find_prompt_container = main.add<GUI::Widget>(); - find_prompt_container.set_layout<GUI::HorizontalBoxLayout>(); - - find_prompt_container.add<GUI::Label>("Value to find"); + auto& main_widget = set_main_widget<GUI::Widget>(); + if (!main_widget.load_from_gml(find_dialog_gml)) + VERIFY_NOT_REACHED(); - m_text_editor = find_prompt_container.add<GUI::TextBox>(); - m_text_editor->set_fixed_height(19); + m_text_editor = *main_widget.find_descendant_of_type_named<GUI::TextBox>("text_editor"); + m_ok_button = *main_widget.find_descendant_of_type_named<GUI::Button>("ok_button"); + m_cancel_button = *main_widget.find_descendant_of_type_named<GUI::Button>("cancel_button"); + auto& radio_container = *main_widget.find_descendant_of_type_named<GUI::Widget>("radio_container"); for (size_t i = 0; i < options.size(); i++) { auto action = options[i]; - auto& radio = main.add<GUI::RadioButton>(); + auto& radio = radio_container.add<GUI::RadioButton>(); radio.set_enabled(action.enabled); radio.set_text(action.title); @@ -123,22 +117,18 @@ FindDialog::FindDialog() } } - auto& button_box = main.add<GUI::Widget>(); - button_box.set_layout<GUI::HorizontalBoxLayout>(); - button_box.layout()->set_spacing(8); + m_text_editor->on_return_pressed = [this] { + m_ok_button->click(); + }; - auto& ok_button = button_box.add<GUI::Button>(); - 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<GUI::Button>(); - 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 0000000000..5486dc7754 --- /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 5cc9dd2b51..5c58b49cca 100644 --- a/Userland/Applications/HexEditor/FindDialog.h +++ b/Userland/Applications/HexEditor/FindDialog.h @@ -32,6 +32,8 @@ private: virtual ~FindDialog() override; RefPtr<GUI::TextEditor> m_text_editor; + RefPtr<GUI::Button> m_ok_button; + RefPtr<GUI::Button> m_cancel_button; String m_text_value; OptionId m_selected_option { OPTION_INVALID }; |