Browse Source

handle nokebook renaming correctly

We do not allow modifying the path of an existing notebook.

Signed-off-by: Le Tan <[email protected]>
Le Tan 9 years ago
parent
commit
a6774fdf49
5 changed files with 20 additions and 21 deletions
  1. 1 11
      src/vdirectorytree.cpp
  2. 0 10
      src/vfilelist.cpp
  3. 2 0
      src/vmainwindow.cpp
  4. 14 0
      src/vtabwidget.cpp
  5. 3 0
      src/vtabwidget.h

+ 1 - 11
src/vdirectorytree.cpp

@@ -580,17 +580,7 @@ void VDirectoryTree::handleNotebookRenamed(const QVector<VNotebook> &notebooks,
                                            const QString &oldName, const QString &newName)
 {
     if (oldName == notebook) {
-        // Update treePath (though treePath actually will not be changed)
         notebook = newName;
-        treePath.clear();
-        const QVector<VNotebook> &notebooks = vnote->getNotebooks();
-        for (int i = 0; i < notebooks.size(); ++i) {
-            if (notebooks[i].getName() == notebook) {
-                treePath = notebooks[i].getPath();
-                break;
-            }
-        }
-        Q_ASSERT(!treePath.isEmpty());
-        qDebug() << "directoryTree update notebook" << oldName << "to" << newName << "path" << treePath;
+        qDebug() << "directoryTree update notebook" << oldName << "to" << newName;
     }
 }

+ 0 - 10
src/vfilelist.cpp

@@ -424,17 +424,7 @@ void VFileList::handleNotebookRenamed(const QVector<VNotebook> &notebooks,
                                       const QString &oldName, const QString &newName)
 {
     if (oldName == notebook) {
-        // Update treePath (though treePath actually will not be changed)
         notebook = newName;
-        rootPath.clear();
-        const QVector<VNotebook> &notebooks = vnote->getNotebooks();
-        for (int i = 0; i < notebooks.size(); ++i) {
-            if (notebooks[i].getName() == notebook) {
-                rootPath = notebooks[i].getPath();
-                break;
-            }
-        }
-        Q_ASSERT(!rootPath.isEmpty());
     }
 }
 

+ 2 - 0
src/vmainwindow.cpp

@@ -109,6 +109,8 @@ void VMainWindow::setupUI()
             tabs, &VTabWidget::closeFile);
     connect(fileList, &VFileList::fileCreated,
             tabs, &VTabWidget::openFile);
+    connect(vnote, &VNote::notebooksRenamed,
+            tabs, &VTabWidget::handleNotebookRenamed);
 
     connect(newNotebookBtn, &QPushButton::clicked,
             this, &VMainWindow::onNewNotebookBtnClicked);

+ 14 - 0
src/vtabwidget.cpp

@@ -161,3 +161,17 @@ void VTabWidget::saveFile()
     Q_ASSERT(editor);
     editor->saveFile();
 }
+
+void VTabWidget::handleNotebookRenamed(const QVector<VNotebook> &notebooks,
+                                       const QString &oldName, const QString &newName)
+{
+    QTabBar *tabs = tabBar();
+    int nrTabs = tabs->count();
+    for (int i = 0; i < nrTabs; ++i) {
+        QJsonObject tabJson = tabs->tabData(i).toJsonObject();
+        if (tabJson["notebook"] == oldName) {
+            tabJson["notebook"] = newName;
+            tabs->setTabData(i, tabJson);
+        }
+    }
+}

+ 3 - 0
src/vtabwidget.h

@@ -6,6 +6,7 @@
 #include <QString>
 #include <QFileInfo>
 #include <QDir>
+#include "vnotebook.h"
 
 class VNote;
 
@@ -24,6 +25,8 @@ public slots:
     void editFile();
     void saveFile();
     void readFile();
+    void handleNotebookRenamed(const QVector<VNotebook> &notebooks, const QString &oldName,
+                               const QString &newName);
 
 private slots:
     void handleTabCloseRequest(int index);