TextEditor: Hide the search bar until the user asks for it

You can get to it via Edit/Find, or by pressing Ctrl+F.
This commit is contained in:
Andreas Kling 2019-08-22 11:02:03 +02:00
parent 933a98f8fa
commit 96c5c9ce12
Notes: sideshowbarker 2024-07-19 12:34:06 +09:00
2 changed files with 9 additions and 0 deletions

View File

@ -30,6 +30,7 @@ TextEditorWidget::TextEditorWidget()
find_widget->set_preferred_size(0, 22);
find_widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
find_widget->layout()->set_margins({ 2, 2, 2, 2 });
find_widget->set_visible(false);
m_find_textbox = new GTextBox(find_widget);
@ -52,6 +53,11 @@ TextEditorWidget::TextEditorWidget()
}
};
m_find_action = GAction::create("Find...", { Mod_Ctrl, Key_F }, [this, find_widget](auto&) {
find_widget->set_visible(true);
m_find_textbox->set_focus(true);
});
auto* statusbar = new GStatusBar(this);
m_editor->on_cursor_change = [statusbar, this] {
@ -120,6 +126,8 @@ TextEditorWidget::TextEditorWidget()
edit_menu->add_action(m_editor->copy_action());
edit_menu->add_action(m_editor->paste_action());
edit_menu->add_action(m_editor->delete_action());
edit_menu->add_separator();
edit_menu->add_action(*m_find_action);
menubar->add_menu(move(edit_menu));
auto font_menu = make<GMenu>("Font");

View File

@ -28,6 +28,7 @@ private:
RefPtr<GAction> m_open_action;
RefPtr<GAction> m_save_action;
RefPtr<GAction> m_save_as_action;
RefPtr<GAction> m_find_action;
GTextBox* m_find_textbox { nullptr };
GButton* m_find_button { nullptr };