From a6774fdf4972ec6d51a177b372da8117a6fa6d41 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sun, 30 Oct 2016 18:02:41 +0800 Subject: [PATCH] handle nokebook renaming correctly We do not allow modifying the path of an existing notebook. Signed-off-by: Le Tan --- src/vdirectorytree.cpp | 12 +----------- src/vfilelist.cpp | 10 ---------- src/vmainwindow.cpp | 2 ++ src/vtabwidget.cpp | 14 ++++++++++++++ src/vtabwidget.h | 3 +++ 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp index 7b124482..9e71e369 100644 --- a/src/vdirectorytree.cpp +++ b/src/vdirectorytree.cpp @@ -580,17 +580,7 @@ void VDirectoryTree::handleNotebookRenamed(const QVector ¬ebooks, const QString &oldName, const QString &newName) { if (oldName == notebook) { - // Update treePath (though treePath actually will not be changed) notebook = newName; - treePath.clear(); - const QVector ¬ebooks = 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; } } diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 0dadb506..2aa39d1d 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -424,17 +424,7 @@ void VFileList::handleNotebookRenamed(const QVector ¬ebooks, const QString &oldName, const QString &newName) { if (oldName == notebook) { - // Update treePath (though treePath actually will not be changed) notebook = newName; - rootPath.clear(); - const QVector ¬ebooks = vnote->getNotebooks(); - for (int i = 0; i < notebooks.size(); ++i) { - if (notebooks[i].getName() == notebook) { - rootPath = notebooks[i].getPath(); - break; - } - } - Q_ASSERT(!rootPath.isEmpty()); } } diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index fb512d62..b0ed9774 100644 --- a/src/vmainwindow.cpp +++ b/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); diff --git a/src/vtabwidget.cpp b/src/vtabwidget.cpp index 81c095ac..5601439e 100644 --- a/src/vtabwidget.cpp +++ b/src/vtabwidget.cpp @@ -161,3 +161,17 @@ void VTabWidget::saveFile() Q_ASSERT(editor); editor->saveFile(); } + +void VTabWidget::handleNotebookRenamed(const QVector ¬ebooks, + 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); + } + } +} diff --git a/src/vtabwidget.h b/src/vtabwidget.h index a4268763..bc3f970a 100644 --- a/src/vtabwidget.h +++ b/src/vtabwidget.h @@ -6,6 +6,7 @@ #include #include #include +#include "vnotebook.h" class VNote; @@ -24,6 +25,8 @@ public slots: void editFile(); void saveFile(); void readFile(); + void handleNotebookRenamed(const QVector ¬ebooks, const QString &oldName, + const QString &newName); private slots: void handleTabCloseRequest(int index);