summaryrefslogtreecommitdiff
path: root/components/channels.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-11-04 01:39:56 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2021-11-04 01:39:56 -0400
commit1f445742b4fbc185fe0e24d9ed2478e4f7495f53 (patch)
tree115717c39b7769a7ad97776fbc299362fd8b10c9 /components/channels.cpp
parentd629846220d069a86b000db213d47c8681e8f57a (diff)
downloadabaddon-portaudio-1f445742b4fbc185fe0e24d9ed2478e4f7495f53.tar.gz
abaddon-portaudio-1f445742b4fbc185fe0e24d9ed2478e4f7495f53.zip
preserve channel list expansion and active channel (#36)
also check getenv in platform
Diffstat (limited to 'components/channels.cpp')
-rw-r--r--components/channels.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/components/channels.cpp b/components/channels.cpp
index ac11a0c..621d7dc 100644
--- a/components/channels.cpp
+++ b/components/channels.cpp
@@ -380,6 +380,56 @@ void ChannelList::SetActiveChannel(Snowflake id) {
}
}
+void ChannelList::UseExpansionState(const ExpansionStateRoot &root) {
+ auto recurse = [this](auto &self, const ExpansionStateRoot &root) -> void {
+ // and these are only channels
+ for (const auto &[id, state] : root.Children) {
+ if (const auto iter = GetIteratorForChannelFromID(id)) {
+ if (state.IsExpanded)
+ m_view.expand_row(m_model->get_path(iter), false);
+ else
+ m_view.collapse_row(m_model->get_path(iter));
+ }
+
+ self(self, state.Children);
+ }
+ };
+
+ // top level is guild
+ for (const auto &[id, state] : root.Children) {
+ if (const auto iter = GetIteratorForGuildFromID(id)) {
+ if (state.IsExpanded)
+ m_view.expand_row(m_model->get_path(iter), false);
+ else
+ m_view.collapse_row(m_model->get_path(iter));
+ }
+
+ recurse(recurse, state.Children);
+ }
+}
+
+ExpansionStateRoot ChannelList::GetExpansionState() const {
+ ExpansionStateRoot r;
+
+ auto recurse = [this](auto &self, const Gtk::TreeRow &row) -> ExpansionState {
+ ExpansionState r;
+
+ r.IsExpanded = row[m_columns.m_expanded];
+ for (const auto &child : row.children())
+ r.Children.Children[static_cast<Snowflake>(child[m_columns.m_id])] = self(self, child);
+
+ return r;
+ };
+
+ for (const auto &child : m_model->children()) {
+ const auto id = static_cast<Snowflake>(child[m_columns.m_id]);
+ if (static_cast<uint64_t>(id) == 0ULL) continue; // dont save DM header
+ r.Children[id] = recurse(recurse, child);
+ }
+
+ return r;
+}
+
Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) {
auto &discord = Abaddon::Get().GetDiscordClient();
auto &img = Abaddon::Get().GetImageManager();