IncrementalSearchBanner: Port to GML compilation

This commit is contained in:
Aryan Baburajan 2024-04-02 13:52:43 +05:30 committed by Tim Schumacher
commit 3336d00241
Notes: sideshowbarker 2024-07-17 22:09:47 +09:00
5 changed files with 24 additions and 15 deletions

View file

@ -5,7 +5,7 @@ stringify_gml(DatePickerDialog.gml DatePickerDialogGML.h date_picker_dialog_gml)
compile_gml(EmojiInputDialog.gml EmojiInputDialogGML.cpp) compile_gml(EmojiInputDialog.gml EmojiInputDialogGML.cpp)
compile_gml(FontPickerDialog.gml FontPickerDialogGML.cpp) compile_gml(FontPickerDialog.gml FontPickerDialogGML.cpp)
compile_gml(FilePickerDialog.gml FilePickerDialogGML.cpp) compile_gml(FilePickerDialog.gml FilePickerDialogGML.cpp)
stringify_gml(IncrementalSearchBanner.gml IncrementalSearchBannerGML.h incremental_search_banner_gml) compile_gml(IncrementalSearchBanner.gml IncrementalSearchBannerGML.cpp)
compile_gml(PasswordInputDialog.gml PasswordInputDialogGML.cpp) compile_gml(PasswordInputDialog.gml PasswordInputDialogGML.cpp)
set(SOURCES set(SOURCES
@ -70,6 +70,7 @@ set(SOURCES
IconView.cpp IconView.cpp
ImageWidget.cpp ImageWidget.cpp
IncrementalSearchBanner.cpp IncrementalSearchBanner.cpp
IncrementalSearchBannerGML.cpp
INILexer.cpp INILexer.cpp
INISyntaxHighlighter.cpp INISyntaxHighlighter.cpp
InputBox.cpp InputBox.cpp
@ -152,7 +153,6 @@ set(GENERATED_SOURCES
../../Services/WindowServer/WindowManagerServerEndpoint.h ../../Services/WindowServer/WindowManagerServerEndpoint.h
../../Services/WindowServer/WindowServerEndpoint.h ../../Services/WindowServer/WindowServerEndpoint.h
DatePickerDialogGML.h DatePickerDialogGML.h
IncrementalSearchBannerGML.h
) )
serenity_lib(LibGUI gui) serenity_lib(LibGUI gui)

View file

@ -7,7 +7,6 @@
#include <LibGUI/Button.h> #include <LibGUI/Button.h>
#include <LibGUI/IncrementalSearchBanner.h> #include <LibGUI/IncrementalSearchBanner.h>
#include <LibGUI/IncrementalSearchBannerGML.h>
#include <LibGUI/Label.h> #include <LibGUI/Label.h>
#include <LibGUI/Layout.h> #include <LibGUI/Layout.h>
#include <LibGUI/Painter.h> #include <LibGUI/Painter.h>
@ -16,10 +15,15 @@
namespace GUI { namespace GUI {
IncrementalSearchBanner::IncrementalSearchBanner(TextEditor& editor) ErrorOr<NonnullRefPtr<IncrementalSearchBanner>> IncrementalSearchBanner::try_create(TextEditor& editor)
: m_editor(editor) {
auto widget = TRY(IncrementalSearchBanner::try_create());
widget->m_editor = editor;
return widget;
}
ErrorOr<void> IncrementalSearchBanner::initialize()
{ {
load_from_gml(incremental_search_banner_gml).release_value_but_fixme_should_propagate_errors();
m_index_label = find_descendant_of_type_named<Label>("incremental_search_banner_index_label"); m_index_label = find_descendant_of_type_named<Label>("incremental_search_banner_index_label");
m_wrap_search_button = find_descendant_of_type_named<Button>("incremental_search_banner_wrap_search_button"); m_wrap_search_button = find_descendant_of_type_named<Button>("incremental_search_banner_wrap_search_button");
@ -69,6 +73,7 @@ IncrementalSearchBanner::IncrementalSearchBanner(TextEditor& editor)
m_search_textbox->on_escape_pressed = [this]() { m_search_textbox->on_escape_pressed = [this]() {
hide(); hide();
}; };
return {};
} }
void IncrementalSearchBanner::show() void IncrementalSearchBanner::show()

View file

@ -1,4 +1,4 @@
@GUI::Widget { @GUI::IncrementalSearchBanner {
fill_with_background_color: true fill_with_background_color: true
visible: false visible: false
layout: @GUI::HorizontalBoxLayout { layout: @GUI::HorizontalBoxLayout {
@ -20,7 +20,7 @@
@GUI::Button { @GUI::Button {
name: "incremental_search_banner_previous_button" name: "incremental_search_banner_previous_button"
icon: "/res/icons/16x16/go-up.png" icon_from_path: "/res/icons/16x16/go-up.png"
fixed_width: 18 fixed_width: 18
button_style: "Coolbar" button_style: "Coolbar"
focus_policy: "NoFocus" focus_policy: "NoFocus"
@ -28,7 +28,7 @@
@GUI::Button { @GUI::Button {
name: "incremental_search_banner_next_button" name: "incremental_search_banner_next_button"
icon: "/res/icons/16x16/go-down.png" icon_from_path: "/res/icons/16x16/go-down.png"
fixed_width: 18 fixed_width: 18
button_style: "Coolbar" button_style: "Coolbar"
focus_policy: "NoFocus" focus_policy: "NoFocus"
@ -51,7 +51,7 @@
@GUI::Button { @GUI::Button {
name: "incremental_search_banner_wrap_search_button" name: "incremental_search_banner_wrap_search_button"
fixed_width: 24 fixed_width: 24
icon: "/res/icons/16x16/reload.png" icon_from_path: "/res/icons/16x16/reload.png"
tooltip: "Wrap Search" tooltip: "Wrap Search"
checkable: true checkable: true
checked: true checked: true
@ -62,7 +62,7 @@
@GUI::Button { @GUI::Button {
name: "incremental_search_banner_match_case_button" name: "incremental_search_banner_match_case_button"
fixed_width: 24 fixed_width: 24
icon: "/res/icons/16x16/app-font-editor.png" icon_from_path: "/res/icons/16x16/app-font-editor.png"
tooltip: "Match Case" tooltip: "Match Case"
checkable: true checkable: true
button_style: "Coolbar" button_style: "Coolbar"

View file

@ -15,21 +15,25 @@ class IncrementalSearchBanner final : public Widget {
C_OBJECT(IncrementalSearchBanner); C_OBJECT(IncrementalSearchBanner);
public: public:
static ErrorOr<NonnullRefPtr<IncrementalSearchBanner>> try_create(TextEditor& editor);
ErrorOr<void> initialize();
virtual ~IncrementalSearchBanner() override = default; virtual ~IncrementalSearchBanner() override = default;
void show(); void show();
void hide(); void hide();
protected: protected:
explicit IncrementalSearchBanner(TextEditor&);
virtual void paint_event(PaintEvent&) override; virtual void paint_event(PaintEvent&) override;
virtual Optional<UISize> calculated_min_size() const override; virtual Optional<UISize> calculated_min_size() const override;
private: private:
IncrementalSearchBanner() = default;
static ErrorOr<NonnullRefPtr<IncrementalSearchBanner>> try_create();
void search(TextEditor::SearchDirection); void search(TextEditor::SearchDirection);
NonnullRefPtr<TextEditor> m_editor; RefPtr<TextEditor> m_editor;
RefPtr<Button> m_close_button; RefPtr<Button> m_close_button;
RefPtr<Button> m_next_button; RefPtr<Button> m_next_button;
RefPtr<Button> m_previous_button; RefPtr<Button> m_previous_button;

View file

@ -67,7 +67,7 @@ TextEditor::TextEditor(Type type)
if (is_multi_line()) { if (is_multi_line()) {
set_font(Gfx::FontDatabase::default_fixed_width_font()); set_font(Gfx::FontDatabase::default_fixed_width_font());
set_wrapping_mode(WrappingMode::WrapAtWords); set_wrapping_mode(WrappingMode::WrapAtWords);
m_search_banner = GUI::IncrementalSearchBanner::construct(*this); m_search_banner = GUI::IncrementalSearchBanner::try_create(*this).release_value_but_fixme_should_propagate_errors();
set_banner_widget(m_search_banner); set_banner_widget(m_search_banner);
} }
vertical_scrollbar().set_step(line_height()); vertical_scrollbar().set_step(line_height());