diff --git a/Applications/IRCClient/IRCClientWindowListModel.cpp b/Applications/IRCClient/IRCClientWindowListModel.cpp index 3f2dcd45e5..f4d58e263c 100644 --- a/Applications/IRCClient/IRCClientWindowListModel.cpp +++ b/Applications/IRCClient/IRCClientWindowListModel.cpp @@ -7,6 +7,7 @@ IRCClientWindowListModel::IRCClientWindowListModel(IRCClient& client) : m_client(client) { + set_activates_on_selection(true); } IRCClientWindowListModel::~IRCClientWindowListModel() diff --git a/LibGUI/GModelIndex.h b/LibGUI/GModelIndex.h index 9cd19ba3ac..a60b3c5efc 100644 --- a/LibGUI/GModelIndex.h +++ b/LibGUI/GModelIndex.h @@ -13,6 +13,8 @@ public: int row() const { return m_row; } int column() const { return m_column; } + bool operator==(const GModelIndex& other) const { return m_row == other.m_row && m_column == other.m_column; } + private: int m_row { -1 }; int m_column { -1 }; diff --git a/LibGUI/GTableModel.cpp b/LibGUI/GTableModel.cpp index e9185199b8..4cd6bdc468 100644 --- a/LibGUI/GTableModel.cpp +++ b/LibGUI/GTableModel.cpp @@ -33,3 +33,14 @@ void GTableModel::did_update() view.did_update_model(); }); } + +void GTableModel::set_selected_index(const GModelIndex& index) +{ + if (m_selected_index == index) + return; + m_selected_index = index; + if (on_selection_changed) + on_selection_changed(index); + if (m_activates_on_selection && is_valid(index)) + activate(index); +} diff --git a/LibGUI/GTableModel.h b/LibGUI/GTableModel.h index baae6c4eff..200796f8a0 100644 --- a/LibGUI/GTableModel.h +++ b/LibGUI/GTableModel.h @@ -58,9 +58,12 @@ public: 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&); GModelIndex selected_index() const { return m_selected_index; } + bool activates_on_selection() const { return m_activates_on_selection; } + void set_activates_on_selection(bool b) { m_activates_on_selection = b; } + virtual int key_column() const { return -1; } virtual GSortOrder sort_order() const { return GSortOrder::None; } virtual void set_key_column_and_sort_order(int, GSortOrder) { } @@ -69,6 +72,7 @@ public: void unregister_view(Badge, GTableView&); Function on_model_update; + Function on_selection_changed; protected: GTableModel(); @@ -79,4 +83,5 @@ protected: private: HashTable m_views; GModelIndex m_selected_index; + bool m_activates_on_selection { false }; };