mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
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:
parent
49020d9fb2
commit
a6774fdf49
@ -580,17 +580,7 @@ void VDirectoryTree::handleNotebookRenamed(const QVector<VNotebook> ¬ebooks,
|
|||||||
const QString &oldName, const QString &newName)
|
const QString &oldName, const QString &newName)
|
||||||
{
|
{
|
||||||
if (oldName == notebook) {
|
if (oldName == notebook) {
|
||||||
// Update treePath (though treePath actually will not be changed)
|
|
||||||
notebook = newName;
|
notebook = newName;
|
||||||
treePath.clear();
|
qDebug() << "directoryTree update notebook" << oldName << "to" << newName;
|
||||||
const QVector<VNotebook> ¬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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -424,17 +424,7 @@ void VFileList::handleNotebookRenamed(const QVector<VNotebook> ¬ebooks,
|
|||||||
const QString &oldName, const QString &newName)
|
const QString &oldName, const QString &newName)
|
||||||
{
|
{
|
||||||
if (oldName == notebook) {
|
if (oldName == notebook) {
|
||||||
// Update treePath (though treePath actually will not be changed)
|
|
||||||
notebook = newName;
|
notebook = newName;
|
||||||
rootPath.clear();
|
|
||||||
const QVector<VNotebook> ¬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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +109,8 @@ void VMainWindow::setupUI()
|
|||||||
tabs, &VTabWidget::closeFile);
|
tabs, &VTabWidget::closeFile);
|
||||||
connect(fileList, &VFileList::fileCreated,
|
connect(fileList, &VFileList::fileCreated,
|
||||||
tabs, &VTabWidget::openFile);
|
tabs, &VTabWidget::openFile);
|
||||||
|
connect(vnote, &VNote::notebooksRenamed,
|
||||||
|
tabs, &VTabWidget::handleNotebookRenamed);
|
||||||
|
|
||||||
connect(newNotebookBtn, &QPushButton::clicked,
|
connect(newNotebookBtn, &QPushButton::clicked,
|
||||||
this, &VMainWindow::onNewNotebookBtnClicked);
|
this, &VMainWindow::onNewNotebookBtnClicked);
|
||||||
|
@ -161,3 +161,17 @@ void VTabWidget::saveFile()
|
|||||||
Q_ASSERT(editor);
|
Q_ASSERT(editor);
|
||||||
editor->saveFile();
|
editor->saveFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VTabWidget::handleNotebookRenamed(const QVector<VNotebook> ¬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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include "vnotebook.h"
|
||||||
|
|
||||||
class VNote;
|
class VNote;
|
||||||
|
|
||||||
@ -24,6 +25,8 @@ public slots:
|
|||||||
void editFile();
|
void editFile();
|
||||||
void saveFile();
|
void saveFile();
|
||||||
void readFile();
|
void readFile();
|
||||||
|
void handleNotebookRenamed(const QVector<VNotebook> ¬ebooks, const QString &oldName,
|
||||||
|
const QString &newName);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void handleTabCloseRequest(int index);
|
void handleTabCloseRequest(int index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user