summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-12-01 03:46:55 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-12-01 03:46:55 +0100
commitb774a671da62d86444812d2b3769ec2f04d767dc (patch)
treeaa3a9ff7d52ca2839babd528f84fb666f90520f2 /src/timeline
parentDon't waste space for non existing subspaces (diff)
downloadnheko-b774a671da62d86444812d2b3769ec2f04d767dc.tar.xz
Remember all the collapsed trees
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/CommunitiesModel.cpp51
-rw-r--r--src/timeline/CommunitiesModel.h3
2 files changed, 54 insertions, 0 deletions
diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp
index fb8aac24..3c28463e 100644
--- a/src/timeline/CommunitiesModel.cpp
+++ b/src/timeline/CommunitiesModel.cpp
@@ -40,6 +40,7 @@ CommunitiesModel::setData(const QModelIndex &index, const QVariant &value, int r
 
         const auto cindex = spaceOrder_.lastChild(index.row() - 2);
         emit dataChanged(index, this->index(cindex + 2), {Collapsed, Qt::DisplayRole});
+        spaceOrder_.storeCollapsed();
         return true;
     } else
         return false;
@@ -276,6 +277,7 @@ CommunitiesModel::initializeSidebar()
         tags_.push_back(QString::fromStdString(t));
 
     hiddentTagIds_ = UserSettings::instance()->hiddenTags();
+    spaceOrder_.restoreCollapsed();
     endResetModel();
 
     emit tagsChanged();
@@ -284,6 +286,55 @@ CommunitiesModel::initializeSidebar()
 }
 
 void
+CommunitiesModel::FlatTree::storeCollapsed()
+{
+    QList<QStringList> elements;
+
+    int depth = -1;
+
+    QStringList current;
+
+    for (const auto &e : tree) {
+        if (e.depth > depth) {
+            current.push_back(e.name);
+        } else if (e.depth == depth) {
+            current.back() = e.name;
+        } else {
+            current.pop_back();
+            current.back() = e.name;
+        }
+
+        if (e.collapsed)
+            elements.push_back(current);
+    }
+
+    UserSettings::instance()->setCollapsedSpaces(elements);
+}
+void
+CommunitiesModel::FlatTree::restoreCollapsed()
+{
+    QList<QStringList> elements = UserSettings::instance()->collapsedSpaces();
+
+    int depth = -1;
+
+    QStringList current;
+
+    for (auto &e : tree) {
+        if (e.depth > depth) {
+            current.push_back(e.name);
+        } else if (e.depth == depth) {
+            current.back() = e.name;
+        } else {
+            current.pop_back();
+            current.back() = e.name;
+        }
+
+        if (elements.contains(current))
+            e.collapsed = true;
+    }
+}
+
+void
 CommunitiesModel::clear()
 {
     beginResetModel();
diff --git a/src/timeline/CommunitiesModel.h b/src/timeline/CommunitiesModel.h
index 5191b239..0cba7104 100644
--- a/src/timeline/CommunitiesModel.h
+++ b/src/timeline/CommunitiesModel.h
@@ -92,6 +92,9 @@ public:
                     break;
             return i;
         }
+
+        void storeCollapsed();
+        void restoreCollapsed();
     };
 
     CommunitiesModel(QObject *parent = nullptr);