Browse Source

NotebookNodeExplorer: fix reload issue not loading children of node item

Le Tan 4 years ago
parent
commit
6b10a5f63d

+ 1 - 1
src/data/extra/docs/en/about_vnotex.txt

@@ -1,5 +1,5 @@
 <p>
-VNoteX is designed to be a pleasant note-taking platform, refactored from VNote, which is an open source note-taking application for Markdown since 2016. VNote shares most of the code base with VNoteX since version 3.0 and continue to be open source.
+VNoteX is designed to be a pleasant note-taking platform, refactored from VNote, which is an open source note-taking application for Markdown since 2016. VNote shares most of the code base with VNoteX since version 3 and continue to be open source.
 <br/><br/>
 Source code of VNote could be found at <a href="https://github.com/vnotex/vnote">GitHub</a>.
 <br/><br/>

+ 1 - 1
src/data/extra/docs/zh_CN/about_vnotex.txt

@@ -1,5 +1,5 @@
 <p>
-VNoteX 致力于成为一个舒适的笔记平台。VNoteX 重构自 VNote,后者是一个始于2016年的专注于 Markdown 的开源笔记软件。VNote 3.0 会和 VNoteX 共享大部分源代码,并继续开源。
+VNoteX 致力于成为一个舒适的笔记平台。VNoteX 重构自 VNote,后者是一个始于2016年的专注于 Markdown 的开源笔记软件。VNote 在版本3之后会和 VNoteX 共享大部分源代码,并继续开源。
 <br/><br/>
 VNote 源代码可以在 <a href="https://github.com/vnotex/vnote">GitHub</a> 获取。
 <br/><br/>

+ 20 - 12
src/widgets/notebooknodeexplorer.cpp

@@ -238,16 +238,7 @@ void NotebookNodeExplorer::setupMasterExplorer(QWidget *p_parent)
     NavigationModeMgr::getInst().registerNavigationTarget(m_navigationWrapper.data());
 
     connect(m_masterExplorer, &QTreeWidget::itemExpanded,
-            this, [this](QTreeWidgetItem *p_item) {
-                auto cnt = p_item->childCount();
-                for (int i = 0; i < cnt; ++i) {
-                    auto child = p_item->child(i);
-                    auto data = getItemNodeData(child);
-                    if (data.isNode() && !data.isLoaded()) {
-                        loadNode(child, data.getNode(), 1);
-                    }
-                }
-            });
+            this, &NotebookNodeExplorer::loadItemChildren);
 
     connect(m_masterExplorer, &QTreeWidget::customContextMenuRequested,
             this, [this](const QPoint &p_pos) {
@@ -421,8 +412,13 @@ void NotebookNodeExplorer::loadNode(QTreeWidgetItem *p_item, Node *p_node, int p
 
     loadChildren(p_item, p_node, p_level - 1);
 
-    if (stateCache()->contains(p_item)) {
-        p_item->setExpanded(true);
+    if (stateCache()->contains(p_item) && p_item->childCount() > 0) {
+        if (p_item->isExpanded()) {
+            loadItemChildren(p_item);
+        } else {
+            // itemExpanded() will trigger loadItemChildren().
+            p_item->setExpanded(true);
+        }
     }
 }
 
@@ -2050,3 +2046,15 @@ void NotebookNodeExplorer::openSelectedNodesWithExternalProgram(const QString &p
         ProcessUtils::startDetached(command);
     }
 }
+
+void NotebookNodeExplorer::loadItemChildren(QTreeWidgetItem *p_item) const
+{
+    auto cnt = p_item->childCount();
+    for (int i = 0; i < cnt; ++i) {
+        auto child = p_item->child(i);
+        auto data = getItemNodeData(child);
+        if (data.isNode() && !data.isLoaded()) {
+            loadNode(child, data.getNode(), 1);
+        }
+    }
+}

+ 2 - 0
src/widgets/notebooknodeexplorer.h

@@ -169,6 +169,8 @@ namespace vnotex
 
         void loadChildren(QTreeWidgetItem *p_item, Node *p_node, int p_level) const;
 
+        void loadItemChildren(QTreeWidgetItem *p_item) const;
+
         void loadNode(QTreeWidgetItem *p_item, const QSharedPointer<ExternalNode> &p_node) const;
 
         void loadRecycleBinNode(Node *p_node) const;