handle nokebook renaming correctly

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

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-10-30 18:02:41 +08:00
parent 49020d9fb2
commit a6774fdf49
5 changed files with 20 additions and 21 deletions

View File

@ -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;
}
}

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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);