mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
HexEditor: Construct Find dialog from GML
This commit is contained in:
parent
7997c02b6c
commit
16094baffc
4 changed files with 65 additions and 25 deletions
|
@ -1,5 +1,6 @@
|
||||||
compile_gml(HexEditorWindow.gml HexEditorWindowGML.h hex_editor_window_gml)
|
compile_gml(HexEditorWindow.gml HexEditorWindowGML.h hex_editor_window_gml)
|
||||||
compile_gml(GoToOffsetDialog.gml GoToOffsetDialogGML.h go_to_offset_dialog_gml)
|
compile_gml(GoToOffsetDialog.gml GoToOffsetDialogGML.h go_to_offset_dialog_gml)
|
||||||
|
compile_gml(FindDialog.gml FindDialogGML.h find_dialog_gml)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
HexEditor.cpp
|
HexEditor.cpp
|
||||||
|
@ -7,6 +8,7 @@ set(SOURCES
|
||||||
FindDialog.cpp
|
FindDialog.cpp
|
||||||
GoToOffsetDialog.cpp
|
GoToOffsetDialog.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
|
FindDialogGML.h
|
||||||
GoToOffsetDialogGML.h
|
GoToOffsetDialogGML.h
|
||||||
HexEditorWindowGML.h
|
HexEditorWindowGML.h
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <AK/Hex.h>
|
#include <AK/Hex.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <Applications/HexEditor/FindDialogGML.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
#include <LibGUI/Button.h>
|
#include <LibGUI/Button.h>
|
||||||
#include <LibGUI/Label.h>
|
#include <LibGUI/Label.h>
|
||||||
|
@ -15,8 +16,6 @@
|
||||||
#include <LibGUI/RadioButton.h>
|
#include <LibGUI/RadioButton.h>
|
||||||
#include <LibGUI/TextBox.h>
|
#include <LibGUI/TextBox.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
#include <LibGfx/Font.h>
|
|
||||||
#include <LibGfx/FontDatabase.h>
|
|
||||||
|
|
||||||
struct Option {
|
struct Option {
|
||||||
String title;
|
String title;
|
||||||
|
@ -88,28 +87,23 @@ Result<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId
|
||||||
FindDialog::FindDialog()
|
FindDialog::FindDialog()
|
||||||
: Dialog(nullptr)
|
: Dialog(nullptr)
|
||||||
{
|
{
|
||||||
resize(280, 180 + ((static_cast<int>(options.size()) - 3) * 16));
|
resize(280, 146);
|
||||||
center_on_screen();
|
center_on_screen();
|
||||||
set_resizable(false);
|
set_resizable(false);
|
||||||
set_title("Find");
|
set_title("Find");
|
||||||
|
|
||||||
auto& main = set_main_widget<GUI::Widget>();
|
auto& main_widget = set_main_widget<GUI::Widget>();
|
||||||
main.set_layout<GUI::VerticalBoxLayout>();
|
if (!main_widget.load_from_gml(find_dialog_gml))
|
||||||
main.layout()->set_margins({ 8, 8, 8, 8 });
|
VERIFY_NOT_REACHED();
|
||||||
main.layout()->set_spacing(8);
|
|
||||||
main.set_fill_with_background_color(true);
|
|
||||||
|
|
||||||
auto& find_prompt_container = main.add<GUI::Widget>();
|
m_text_editor = *main_widget.find_descendant_of_type_named<GUI::TextBox>("text_editor");
|
||||||
find_prompt_container.set_layout<GUI::HorizontalBoxLayout>();
|
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");
|
||||||
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);
|
|
||||||
|
|
||||||
|
auto& radio_container = *main_widget.find_descendant_of_type_named<GUI::Widget>("radio_container");
|
||||||
for (size_t i = 0; i < options.size(); i++) {
|
for (size_t i = 0; i < options.size(); i++) {
|
||||||
auto action = options[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_enabled(action.enabled);
|
||||||
radio.set_text(action.title);
|
radio.set_text(action.title);
|
||||||
|
|
||||||
|
@ -123,22 +117,18 @@ FindDialog::FindDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& button_box = main.add<GUI::Widget>();
|
m_text_editor->on_return_pressed = [this] {
|
||||||
button_box.set_layout<GUI::HorizontalBoxLayout>();
|
m_ok_button->click();
|
||||||
button_box.layout()->set_spacing(8);
|
};
|
||||||
|
|
||||||
auto& ok_button = button_box.add<GUI::Button>();
|
m_ok_button->on_click = [this](auto) {
|
||||||
ok_button.on_click = [this](auto) {
|
|
||||||
m_text_value = m_text_editor->text();
|
m_text_value = m_text_editor->text();
|
||||||
done(ExecResult::ExecOK);
|
done(ExecResult::ExecOK);
|
||||||
};
|
};
|
||||||
ok_button.set_text("OK");
|
|
||||||
|
|
||||||
auto& cancel_button = button_box.add<GUI::Button>();
|
m_cancel_button->on_click = [this](auto) {
|
||||||
cancel_button.on_click = [this](auto) {
|
|
||||||
done(ExecResult::ExecCancel);
|
done(ExecResult::ExecCancel);
|
||||||
};
|
};
|
||||||
cancel_button.set_text("Cancel");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FindDialog::~FindDialog()
|
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;
|
virtual ~FindDialog() override;
|
||||||
|
|
||||||
RefPtr<GUI::TextEditor> m_text_editor;
|
RefPtr<GUI::TextEditor> m_text_editor;
|
||||||
|
RefPtr<GUI::Button> m_ok_button;
|
||||||
|
RefPtr<GUI::Button> m_cancel_button;
|
||||||
|
|
||||||
String m_text_value;
|
String m_text_value;
|
||||||
OptionId m_selected_option { OPTION_INVALID };
|
OptionId m_selected_option { OPTION_INVALID };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue