mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 09:05:09 +00:00
LibGUI: Add a mode where GTableModel automatically activates on selection.
This commit is contained in:
parent
84f5312dc2
commit
c1f2f5a153
4 changed files with 20 additions and 1 deletions
|
@ -7,6 +7,7 @@
|
||||||
IRCClientWindowListModel::IRCClientWindowListModel(IRCClient& client)
|
IRCClientWindowListModel::IRCClientWindowListModel(IRCClient& client)
|
||||||
: m_client(client)
|
: m_client(client)
|
||||||
{
|
{
|
||||||
|
set_activates_on_selection(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
IRCClientWindowListModel::~IRCClientWindowListModel()
|
IRCClientWindowListModel::~IRCClientWindowListModel()
|
||||||
|
|
|
@ -13,6 +13,8 @@ public:
|
||||||
int row() const { return m_row; }
|
int row() const { return m_row; }
|
||||||
int column() const { return m_column; }
|
int column() const { return m_column; }
|
||||||
|
|
||||||
|
bool operator==(const GModelIndex& other) const { return m_row == other.m_row && m_column == other.m_column; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_row { -1 };
|
int m_row { -1 };
|
||||||
int m_column { -1 };
|
int m_column { -1 };
|
||||||
|
|
|
@ -33,3 +33,14 @@ void GTableModel::did_update()
|
||||||
view.did_update_model();
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -58,9 +58,12 @@ public:
|
||||||
return index.row() >= 0 && index.row() < row_count() && index.column() >= 0 && index.column() < column_count();
|
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; }
|
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 int key_column() const { return -1; }
|
||||||
virtual GSortOrder sort_order() const { return GSortOrder::None; }
|
virtual GSortOrder sort_order() const { return GSortOrder::None; }
|
||||||
virtual void set_key_column_and_sort_order(int, GSortOrder) { }
|
virtual void set_key_column_and_sort_order(int, GSortOrder) { }
|
||||||
|
@ -69,6 +72,7 @@ public:
|
||||||
void unregister_view(Badge<GTableView>, GTableView&);
|
void unregister_view(Badge<GTableView>, GTableView&);
|
||||||
|
|
||||||
Function<void(GTableModel&)> on_model_update;
|
Function<void(GTableModel&)> on_model_update;
|
||||||
|
Function<void(const GModelIndex&)> on_selection_changed;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GTableModel();
|
GTableModel();
|
||||||
|
@ -79,4 +83,5 @@ protected:
|
||||||
private:
|
private:
|
||||||
HashTable<GTableView*> m_views;
|
HashTable<GTableView*> m_views;
|
||||||
GModelIndex m_selected_index;
|
GModelIndex m_selected_index;
|
||||||
|
bool m_activates_on_selection { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue