mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-07 11:39:44 +03:00
HexEditor: Construct Find dialog from GML
This commit is contained in:
parent
7997c02b6c
commit
16094baffc
Notes:
sideshowbarker
2024-07-18 17:25:24 +09:00
Author: https://github.com/bcoles Commit: https://github.com/SerenityOS/serenity/commit/16094baffcc Pull-request: https://github.com/SerenityOS/serenity/pull/7461
@ -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
|
||||
)
|
||||
|
@ -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& main_widget = set_main_widget<GUI::Widget>();
|
||||
if (!main_widget.load_from_gml(find_dialog_gml))
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
auto& find_prompt_container = main.add<GUI::Widget>();
|
||||
find_prompt_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
find_prompt_container.add<GUI::Label>("Value to find");
|
||||
|
||||
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()
|
||||
|
46
Userland/Applications/HexEditor/FindDialog.gml
Normal file
46
Userland/Applications/HexEditor/FindDialog.gml
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user