mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +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);
|
tabs, &VTabWidget::openFile);
|
||||||
connect(newNotebookBtn, &QPushButton::clicked,
|
connect(newNotebookBtn, &QPushButton::clicked,
|
||||||
this, &VMainWindow::onNewNotebookBtnClicked);
|
this, &VMainWindow::onNewNotebookBtnClicked);
|
||||||
|
connect(deleteNotebookBtn, &QPushButton::clicked,
|
||||||
|
this, &VMainWindow::onDeleteNotebookBtnClicked);
|
||||||
connect(vnote, &VNote::notebooksChanged,
|
connect(vnote, &VNote::notebooksChanged,
|
||||||
this, &VMainWindow::updateNotebookComboBox);
|
this, &VMainWindow::updateNotebookComboBox);
|
||||||
|
|
||||||
@ -194,3 +196,19 @@ bool VMainWindow::isConflictWithExistingNotebooks(const QString &name, const QSt
|
|||||||
}
|
}
|
||||||
return false;
|
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);
|
void setCurNotebookIndex(int index);
|
||||||
// Create a notebook
|
// Create a notebook
|
||||||
void onNewNotebookBtnClicked();
|
void onNewNotebookBtnClicked();
|
||||||
|
void onDeleteNotebookBtnClicked();
|
||||||
void updateNotebookComboBox(const QVector<VNotebook> ¬ebooks);
|
void updateNotebookComboBox(const QVector<VNotebook> ¬ebooks);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
29
vnote.cpp
29
vnote.cpp
@ -2,6 +2,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QDir>
|
||||||
#include "vnote.h"
|
#include "vnote.h"
|
||||||
#include "utils/vutils.h"
|
#include "utils/vutils.h"
|
||||||
#include "vconfigmanager.h"
|
#include "vconfigmanager.h"
|
||||||
@ -50,3 +51,31 @@ void VNote::createNotebook(const QString &name, const QString &path)
|
|||||||
|
|
||||||
emit notebooksChanged(notebooks);
|
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);
|
||||||
|
}
|
||||||
|
1
vnote.h
1
vnote.h
@ -21,6 +21,7 @@ public:
|
|||||||
static QString templateHtml;
|
static QString templateHtml;
|
||||||
|
|
||||||
void createNotebook(const QString &name, const QString &path);
|
void createNotebook(const QString &name, const QString &path);
|
||||||
|
void removeNotebook(const QString &name);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void notebooksChanged(const QVector<VNotebook> ¬ebooks);
|
void notebooksChanged(const QVector<VNotebook> ¬ebooks);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user