1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 16:25:08 +00:00

LibGUI: Allow basic keyboard navigation in GTableView.

Pressing Enter will now "activate" the selected index, meaning that
the model gets a call to activate(GModelIndex).
This commit is contained in:
Andreas Kling 2019-03-01 13:48:08 +01:00
parent e1d0a3f226
commit b5dcad932e
3 changed files with 32 additions and 1 deletions

View file

@ -47,13 +47,18 @@ public:
virtual ColumnMetadata column_metadata(int) const { return { }; }
virtual GVariant data(int row, int column) const = 0;
virtual void update() = 0;
virtual void activate(const GModelIndex&) { }
bool is_valid(GModelIndex index) const
{
return index.row() >= 0 && index.row() < row_count() && index.column() >= 0 && index.column() < column_count();
}
void set_selected_index(const GModelIndex& index) { m_selected_index = index; }
void set_selected_index(const GModelIndex& index)
{
if (is_valid(index))
m_selected_index = index;
}
GModelIndex selected_index() const { return m_selected_index; }
void register_view(Badge<GTableView>, GTableView&);