Browse Source

bugfix: update outline info after renaming

Update the filePath property in VToc after renaming the note.

Signed-off-by: Le Tan <[email protected]>
Le Tan 9 years ago
parent
commit
62f2d39fbc
2 changed files with 21 additions and 0 deletions
  1. 18 0
      src/vedittab.cpp
  2. 3 0
      src/vedittab.h

+ 18 - 0
src/vedittab.cpp

@@ -400,6 +400,7 @@ void VEditTab::requestUpdateCurHeader()
 
 void VEditTab::requestUpdateOutline()
 {
+    checkToc();
     emit outlineChanged(tableOfContent);
 }
 
@@ -427,6 +428,9 @@ void VEditTab::updateCurHeader(const QString &anchor)
     }
     curHeader = VAnchor(m_file->retrivePath(), "#" + anchor, -1);
     if (!anchor.isEmpty()) {
+        if (checkToc()) {
+            emit outlineChanged(tableOfContent);
+        }
         const QVector<VHeader> &headers = tableOfContent.headers;
         for (int i = 0; i < headers.size(); ++i) {
             if (headers[i].anchor == curHeader.anchor) {
@@ -443,6 +447,9 @@ void VEditTab::updateCurHeader(int p_lineNumber, int p_outlineIndex)
     if (!isEditMode || curHeader.lineNumber == p_lineNumber) {
         return;
     }
+    if (checkToc()) {
+        emit outlineChanged(tableOfContent);
+    }
     curHeader = VAnchor(m_file->retrivePath(), "", p_lineNumber);
     curHeader.m_outlineIndex = p_outlineIndex;
     if (p_lineNumber > -1) {
@@ -519,3 +526,14 @@ void VEditTab::clearFindSelectionInWebView()
         webPreviewer->findText("");
     }
 }
+
+bool VEditTab::checkToc()
+{
+    bool ret = false;
+    if (tableOfContent.filePath != m_file->retrivePath()) {
+        tableOfContent.filePath = m_file->retrivePath();
+        ret = true;
+    }
+    return ret;
+}
+

+ 3 - 0
src/vedittab.h

@@ -77,6 +77,9 @@ private:
     void scrollPreviewToHeader(int p_outlineIndex);
     void findTextInWebView(const QString &p_text, uint p_options, bool p_peek,
                            bool p_forward);
+    // Check if @tableOfContent is outdated (such as renaming the file).
+    // Return true if we need to update toc.
+    bool checkToc();
 
     QPointer<VFile> m_file;
     bool isEditMode;