OSDN Git Service

Retain expanded state of notebooks & tags across sync.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / NotebookTreeWidget.java
index 807802c..e46baaa 100644 (file)
@@ -184,6 +184,15 @@ public class NotebookTreeWidget extends QTreeWidget {
        public void load(List<Notebook> books, List<String> localBooks) {\r
        Notebook book;\r
        QTreeWidgetItem child;\r
+       \r
+       /* First, let's find out which stacks are expanded */\r
+       QTreeWidgetItem root =  invisibleRootItem();\r
+       List<String> expandedStacks = new ArrayList<String>();\r
+       for (int i=0; i<root.childCount(); i++) {\r
+               if (root.child(i).isExpanded())\r
+                       expandedStacks.add(root.child(i).text(0));\r
+       }\r
+       \r
        clear();\r
        stacks.clear();\r
        \r
@@ -236,8 +245,20 @@ public class NotebookTreeWidget extends QTreeWidget {
        }\r
        resizeColumnToContents(0);\r
        resizeColumnToContents(1);\r
+       \r
+       // Finally, expand the stacks back out\r
+       root = invisibleRootItem();\r
+       for (int i=0; i<root.childCount(); i++) {\r
+               for (int j=0; j<expandedStacks.size(); j++) {\r
+                       if (root.child(i).text(0).equalsIgnoreCase(expandedStacks.get(j))) {\r
+                               expandItem(root.child(i));\r
+                               j=expandedStacks.size();\r
+                       }\r
+               }\r
+       }\r
        }\r
 \r
+\r
        // update the display with the current number of notes\r
        public void updateCounts(List<Notebook> books, List<NotebookCounter> counts) {\r
                QTreeWidgetItem root = invisibleRootItem();\r