diff options
-rw-r--r-- | components/channels.cpp | 16 | ||||
-rw-r--r-- | components/channels.hpp | 3 | ||||
-rw-r--r-- | css/application-low-priority.css | 3 |
3 files changed, 22 insertions, 0 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 520c8fd..a085d62 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -29,6 +29,8 @@ ChannelList::ChannelList() m_view.signal_row_collapsed().connect(sigc::mem_fun(*this, &ChannelList::OnRowCollapsed), false); m_view.signal_row_expanded().connect(sigc::mem_fun(*this, &ChannelList::OnRowExpanded), false); m_view.set_activate_on_single_click(true); + m_view.get_selection()->set_mode(Gtk::SELECTION_SINGLE); + m_view.get_selection()->set_select_function(sigc::mem_fun(*this, &ChannelList::SelectionFunc)); m_view.set_hexpand(true); m_view.set_vexpand(true); @@ -309,6 +311,20 @@ void ChannelList::OnRowExpanded(const Gtk::TreeModel::iterator &iter, const Gtk: if ((*it)[m_columns.m_expanded]) m_view.expand_row(m_model->get_path(it), false); } + + // try and restore selection if previous collapsed + if (auto selection = m_view.get_selection(); selection && !selection->get_selected()) { + selection->select(m_last_selected); + } +} + +bool ChannelList::SelectionFunc(const Glib::RefPtr<Gtk::TreeModel> &model, const Gtk::TreeModel::Path &path, bool is_currently_selected) { + if (auto selection = m_view.get_selection()) + if (auto row = selection->get_selected()) + m_last_selected = m_model->get_path(row); + + auto iter = m_model->get_iter(path); + return (*iter)[m_columns.m_type] == RenderType::TextChannel; } ChannelList::type_signal_action_channel_item_select ChannelList::signal_action_channel_item_select() { diff --git a/components/channels.hpp b/components/channels.hpp index 0bc0b04..c0f0d33 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -131,6 +131,9 @@ protected: void OnRowCollapsed(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path); void OnRowExpanded(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path); + bool SelectionFunc(const Glib::RefPtr<Gtk::TreeModel> &model, const Gtk::TreeModel::Path &path, bool is_currently_selected); + + Gtk::TreeModel::Path m_last_selected; public: typedef sigc::signal<void, Snowflake> type_signal_action_channel_item_select; diff --git a/css/application-low-priority.css b/css/application-low-priority.css index 449127b..cf108f4 100644 --- a/css/application-low-priority.css +++ b/css/application-low-priority.css @@ -38,6 +38,9 @@ has to be separate to allow main.css to override certain things .app-window treeview { color: @text_color; +} + +.app-window treeview:not(:selected) { background: @secondary_color; } |