mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
support deleting notebook
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
5506cec07b
commit
f31272966e
@ -86,6 +86,8 @@ void VMainWindow::setupUI()
|
||||
tabs, &VTabWidget::openFile);
|
||||
connect(newNotebookBtn, &QPushButton::clicked,
|
||||
this, &VMainWindow::onNewNotebookBtnClicked);
|
||||
connect(deleteNotebookBtn, &QPushButton::clicked,
|
||||
this, &VMainWindow::onDeleteNotebookBtnClicked);
|
||||
connect(vnote, &VNote::notebooksChanged,
|
||||
this, &VMainWindow::updateNotebookComboBox);
|
||||
|
||||
@ -194,3 +196,19 @@ bool VMainWindow::isConflictWithExistingNotebooks(const QString &name, const QSt
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VMainWindow::onDeleteNotebookBtnClicked()
|
||||
{
|
||||
int curIndex = notebookComboBox->currentIndex();
|
||||
QString curName = vnote->getNotebooks()[curIndex].getName();
|
||||
QString curPath = vnote->getNotebooks()[curIndex].getPath();
|
||||
|
||||
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Are you sure you want to delete notebook \"%1\"?")
|
||||
.arg(curName));
|
||||
msgBox.setInformativeText(QString("This will delete any files in this notebook (\"%1\").").arg(curPath));
|
||||
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
||||
msgBox.setDefaultButton(QMessageBox::Ok);
|
||||
if (msgBox.exec() == QMessageBox::Ok) {
|
||||
vnote->removeNotebook(curName);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ private slots:
|
||||
void setCurNotebookIndex(int index);
|
||||
// Create a notebook
|
||||
void onNewNotebookBtnClicked();
|
||||
void onDeleteNotebookBtnClicked();
|
||||
void updateNotebookComboBox(const QVector<VNotebook> ¬ebooks);
|
||||
|
||||
signals:
|
||||
|
29
vnote.cpp
29
vnote.cpp
@ -2,6 +2,7 @@
|
||||
#include <QDebug>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDir>
|
||||
#include "vnote.h"
|
||||
#include "utils/vutils.h"
|
||||
#include "vconfigmanager.h"
|
||||
@ -50,3 +51,31 @@ void VNote::createNotebook(const QString &name, const QString &path)
|
||||
|
||||
emit notebooksChanged(notebooks);
|
||||
}
|
||||
|
||||
void VNote::removeNotebook(const QString &name)
|
||||
{
|
||||
// Update notebooks settings
|
||||
QString path;
|
||||
int index;
|
||||
for (index = 0; index < notebooks.size(); ++index) {
|
||||
if (notebooks[index].getName() == name) {
|
||||
path = notebooks[index].getPath();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index == notebooks.size()) {
|
||||
return;
|
||||
}
|
||||
notebooks.remove(index);
|
||||
vconfig.setNotebooks(notebooks);
|
||||
vconfig.setCurNotebookIndex(notebooks.isEmpty() ? -1 : 0);
|
||||
|
||||
// Delete the directory
|
||||
QDir dir(path);
|
||||
if (!dir.removeRecursively()) {
|
||||
qWarning() << "error: fail to delete" << path << "recursively";
|
||||
} else {
|
||||
qDebug() << "delete" << path << "recursively";
|
||||
}
|
||||
emit notebooksChanged(notebooks);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user