summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-28 20:47:02 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-28 20:47:02 +0200
commit5daa19fdabe86ff76c1814abef3f6261a828c9d8 (patch)
tree296b6671825b0ca25dc3401fa099cee6f61816f5 /Libraries/LibGUI
parentf3e4b62be99aeb3f1df825212252f52287b78a93 (diff)
downloadserenity-5daa19fdabe86ff76c1814abef3f6261a828c9d8.zip
LibGUI: Implement a basic "any key pressed" edit trigger for TableView
This trigger allows you to initiate cell editing by simply starting to type something into the cell. :^)
Diffstat (limited to 'Libraries/LibGUI')
-rw-r--r--Libraries/LibGUI/AbstractView.h2
-rw-r--r--Libraries/LibGUI/TableView.cpp13
2 files changed, 13 insertions, 2 deletions
diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h
index 70850fdb62..b98724b3aa 100644
--- a/Libraries/LibGUI/AbstractView.h
+++ b/Libraries/LibGUI/AbstractView.h
@@ -144,6 +144,7 @@ protected:
ModelIndex m_edit_index;
RefPtr<Widget> m_edit_widget;
Gfx::IntRect m_edit_widget_content_rect;
+ OwnPtr<ModelEditingDelegate> m_editing_delegate;
Gfx::IntPoint m_left_mousedown_position;
bool m_might_drag { false };
@@ -156,7 +157,6 @@ protected:
private:
RefPtr<Model> m_model;
- OwnPtr<ModelEditingDelegate> m_editing_delegate;
ModelSelection m_selection;
ModelIndex m_cursor_index;
unsigned m_edit_triggers { EditTrigger::DoubleClicked | EditTrigger::EditKeyPressed };
diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp
index 4309d307bf..d6b12c0f3d 100644
--- a/Libraries/LibGUI/TableView.cpp
+++ b/Libraries/LibGUI/TableView.cpp
@@ -29,6 +29,7 @@
#include <LibGUI/HeaderView.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Model.h>
+#include <LibGUI/ModelEditingDelegate.h>
#include <LibGUI/Painter.h>
#include <LibGUI/ScrollBar.h>
#include <LibGUI/TableView.h>
@@ -171,7 +172,17 @@ void TableView::keydown_event(KeyEvent& event)
activate(cursor_index());
return;
}
- return AbstractTableView::keydown_event(event);
+
+ AbstractTableView::keydown_event(event);
+
+ if (event.is_accepted())
+ return;
+
+ if (is_editable() && edit_triggers() & EditTrigger::AnyKeyPressed && !event.text().is_empty()) {
+ begin_editing(cursor_index());
+ if (m_editing_delegate)
+ m_editing_delegate->set_value(event.text());
+ }
}
void TableView::move_cursor(CursorMovement movement, SelectionUpdate selection_update)