summaryrefslogtreecommitdiff
path: root/DevTools/HackStudio
diff options
context:
space:
mode:
authorFalseHonesty <thefalsehonesty@gmail.com>2020-05-26 22:17:06 -0400
committerAndreas Kling <kling@serenityos.org>2020-05-27 20:04:52 +0200
commit139dbfd5b508bacf7494ba2318eae80f96dc5e76 (patch)
tree82e8aa66d5f4a8d51e918814830833ecc62acd97 /DevTools/HackStudio
parent893a9ff5b05557547c173d67b66eff0642806698 (diff)
downloadserenity-139dbfd5b508bacf7494ba2318eae80f96dc5e76.zip
LibGUI: Add up & down arrow hooks and input history to TextBox
This patch adds the ability to enable "input history" on a textbox, allowing to navigate between the history with the arrow keys. Also removes a custom TextBox subclass from HackStudio that added the exact same hooks, and moves it to use the now standard ones.
Diffstat (limited to 'DevTools/HackStudio')
-rw-r--r--DevTools/HackStudio/Locator.cpp28
-rw-r--r--DevTools/HackStudio/Locator.h4
2 files changed, 4 insertions, 28 deletions
diff --git a/DevTools/HackStudio/Locator.cpp b/DevTools/HackStudio/Locator.cpp
index 5f31c0af37..2a9cc5205a 100644
--- a/DevTools/HackStudio/Locator.cpp
+++ b/DevTools/HackStudio/Locator.cpp
@@ -73,28 +73,6 @@ private:
Vector<String> m_suggestions;
};
-class LocatorTextBox final : public GUI::TextBox {
- C_OBJECT(LocatorTextBox)
-public:
- virtual ~LocatorTextBox() override {}
-
- Function<void()> on_up;
- Function<void()> on_down;
-
- virtual void keydown_event(GUI::KeyEvent& event) override
- {
- if (event.key() == Key_Up)
- on_up();
- else if (event.key() == Key_Down)
- on_down();
-
- GUI::TextBox::keydown_event(event);
- }
-
-private:
- LocatorTextBox() {}
-};
-
Locator::Locator()
{
if (!s_cplusplus_icon) {
@@ -106,14 +84,14 @@ Locator::Locator()
set_layout<GUI::VerticalBoxLayout>();
set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
set_preferred_size(0, 20);
- m_textbox = add<LocatorTextBox>();
+ m_textbox = add<GUI::TextBox>();
m_textbox->on_change = [this] {
update_suggestions();
};
m_textbox->on_escape_pressed = [this] {
m_popup_window->hide();
};
- m_textbox->on_up = [this] {
+ m_textbox->on_up_pressed = [this] {
GUI::ModelIndex new_index = m_suggestion_view->selection().first();
if (new_index.is_valid())
new_index = m_suggestion_view->model()->index(new_index.row() - 1);
@@ -125,7 +103,7 @@ Locator::Locator()
m_suggestion_view->scroll_into_view(new_index, Orientation::Vertical);
}
};
- m_textbox->on_down = [this] {
+ m_textbox->on_down_pressed = [this] {
GUI::ModelIndex new_index = m_suggestion_view->selection().first();
if (new_index.is_valid())
new_index = m_suggestion_view->model()->index(new_index.row() + 1);
diff --git a/DevTools/HackStudio/Locator.h b/DevTools/HackStudio/Locator.h
index 28033b0fce..ccd615e444 100644
--- a/DevTools/HackStudio/Locator.h
+++ b/DevTools/HackStudio/Locator.h
@@ -28,8 +28,6 @@
#include <LibGUI/Widget.h>
-class LocatorTextBox;
-
class Locator final : public GUI::Widget {
C_OBJECT(Locator)
public:
@@ -44,7 +42,7 @@ private:
Locator();
- RefPtr<LocatorTextBox> m_textbox;
+ RefPtr<GUI::TextBox> m_textbox;
RefPtr<GUI::Window> m_popup_window;
RefPtr<GUI::TableView> m_suggestion_view;
};