diff --git a/src/resources/icons/delete_note_tb.svg b/src/resources/icons/delete_note_tb.svg
new file mode 100644
index 00000000..ec2afc25
--- /dev/null
+++ b/src/resources/icons/delete_note_tb.svg
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp
index 093ba847..6a63d227 100644
--- a/src/vfilelist.cpp
+++ b/src/vfilelist.cpp
@@ -44,7 +44,7 @@ void VFileList::initActions()
tr("&Delete"), this);
deleteFileAct->setStatusTip(tr("Delete selected note"));
connect(deleteFileAct, &QAction::triggered,
- this, &VFileList::deleteFile);
+ this, &VFileList::deleteCurFile);
fileInfoAct = new QAction(QIcon(":/resources/icons/note_info.svg"),
tr("&Info"), this);
@@ -130,7 +130,7 @@ void VFileList::fileInfo(const QString &p_notebook, const QString &p_relativePat
{
qDebug() << "fileInfo" << p_notebook << p_relativePath;
QString info;
- QString defaultName = VUtils::directoryNameFromPath(p_relativePath);
+ QString defaultName = VUtils::fileNameFromPath(p_relativePath);
QString curName = defaultName;
do {
VFileInfoDialog dialog(tr("Note Information"), info, defaultName, this);
@@ -209,27 +209,34 @@ void VFileList::newFile()
} while (true);
}
-void VFileList::deleteFile()
+void VFileList::deleteCurFile()
{
QListWidgetItem *curItem = fileList->currentItem();
Q_ASSERT(curItem);
QJsonObject curItemJson = curItem->data(Qt::UserRole).toJsonObject();
QString curItemName = curItemJson["name"].toString();
+ deleteFile(notebook, QDir(relativePath).filePath(curItemName));
+}
+// @p_relativePath contains the file name
+void VFileList::deleteFile(const QString &p_notebook, const QString &p_relativePath)
+{
+ QString fileName = VUtils::fileNameFromPath(p_relativePath);
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"),
QString("Are you sure you want to delete note \"%1\"?")
- .arg(curItemName), QMessageBox::Ok | QMessageBox::Cancel,
+ .arg(fileName), QMessageBox::Ok | QMessageBox::Cancel,
this);
msgBox.setInformativeText(tr("This may be not recoverable."));
msgBox.setDefaultButton(QMessageBox::Ok);
if (msgBox.exec() == QMessageBox::Ok) {
// First close this file forcely
- curItemJson["notebook"] = notebook;
- curItemJson["relative_path"] = QDir::cleanPath(QDir(relativePath).filePath(curItemName));
+ QJsonObject curItemJson;
+ curItemJson["notebook"] = p_notebook;
+ curItemJson["relative_path"] = QDir::cleanPath(p_relativePath);
curItemJson["is_forced"] = true;
emit fileDeleted(curItemJson);
- deleteFileAndUpdateList(curItem);
+ deleteFileAndUpdateList(p_notebook, p_relativePath);
}
}
@@ -317,12 +324,11 @@ QListWidgetItem* VFileList::createFileAndUpdateList(const QString &name)
return insertFileListItem(fileJson, true);
}
-void VFileList::deleteFileAndUpdateList(QListWidgetItem *item)
+void VFileList::deleteFileAndUpdateList(const QString &p_notebook,
+ const QString &p_relativePath)
{
- Q_ASSERT(item);
- QJsonObject itemJson = item->data(Qt::UserRole).toJsonObject();
- QString path = QDir(rootPath).filePath(relativePath);
- QString fileName = itemJson["name"].toString();
+ QString path = QDir(vnote->getNotebookPath(p_notebook)).filePath(VUtils::basePathFromPath(p_relativePath));
+ QString fileName = VUtils::fileNameFromPath(p_relativePath);
QString filePath = QDir(path).filePath(fileName);
// Update current directory's config file to exclude this file
@@ -357,7 +363,10 @@ void VFileList::deleteFileAndUpdateList(QListWidgetItem *item)
qDebug() << "delete" << filePath;
}
- removeFileListItem(item);
+ QListWidgetItem *item = findItem(p_notebook, p_relativePath);
+ if (item) {
+ removeFileListItem(item);
+ }
}
void VFileList::handleItemClicked(QListWidgetItem *currentItem)
diff --git a/src/vfilelist.h b/src/vfilelist.h
index 0c6102f2..8038aeab 100644
--- a/src/vfilelist.h
+++ b/src/vfilelist.h
@@ -23,6 +23,7 @@ public:
bool importFile(const QString &name);
inline void setEditArea(VEditArea *editArea);
void fileInfo(const QString &p_notebook, const QString &p_relativePath);
+ void deleteFile(const QString &p_notebook, const QString &p_relativePath);
signals:
void fileClicked(QJsonObject fileJson);
@@ -36,6 +37,7 @@ private slots:
void contextMenuRequested(QPoint pos);
void handleItemClicked(QListWidgetItem *currentItem);
void curFileInfo();
+ void deleteCurFile();
public slots:
void setDirectory(QJsonObject dirJson);
@@ -44,7 +46,6 @@ public slots:
void handleDirectoryRenamed(const QString ¬ebook, const QString &oldRelativePath,
const QString &newRelativePath);
void newFile();
- void deleteFile();
private:
void setupUI();
@@ -54,7 +55,8 @@ private:
void initActions();
bool isConflictNameWithExisting(const QString &name);
QListWidgetItem *createFileAndUpdateList(const QString &name);
- void deleteFileAndUpdateList(QListWidgetItem *item);
+ void deleteFileAndUpdateList(const QString &p_notebook,
+ const QString &p_relativePath);
void clearDirectoryInfo();
void renameFile(const QString &p_notebook,
const QString &p_relativePath, const QString &p_newName);
diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp
index 3193bd4b..90bc6c58 100644
--- a/src/vmainwindow.cpp
+++ b/src/vmainwindow.cpp
@@ -161,6 +161,12 @@ void VMainWindow::initActions()
connect(noteInfoAct, &QAction::triggered,
this, &VMainWindow::curEditFileInfo);
+ deleteNoteAct = new QAction(QIcon(":/resources/icons/delete_note_tb.svg"),
+ tr("&Delete note"), this);
+ deleteNoteAct->setStatusTip(tr("Delete current note"));
+ connect(deleteNoteAct, &QAction::triggered,
+ this, &VMainWindow::deleteCurNote);
+
editNoteAct = new QAction(QIcon(":/resources/icons/edit_note.svg"),
tr("&Edit"), this);
editNoteAct->setStatusTip(tr("Edit current note"));
@@ -270,6 +276,7 @@ void VMainWindow::initToolBar()
fileToolBar->addAction(newRootDirAct);
fileToolBar->addAction(newNoteAct);
fileToolBar->addAction(noteInfoAct);
+ fileToolBar->addAction(deleteNoteAct);
fileToolBar->addAction(editNoteAct);
fileToolBar->addAction(saveExitAct);
fileToolBar->addAction(discardExitAct);
@@ -278,6 +285,7 @@ void VMainWindow::initToolBar()
newRootDirAct->setEnabled(false);
newNoteAct->setEnabled(false);
noteInfoAct->setEnabled(false);
+ deleteNoteAct->setEnabled(false);
editNoteAct->setEnabled(false);
saveExitAct->setVisible(false);
discardExitAct->setVisible(false);
@@ -678,16 +686,19 @@ void VMainWindow::updateToolbarFromTabChage(bool empty, bool editMode, bool modi
saveExitAct->setVisible(false);
discardExitAct->setVisible(false);
saveNoteAct->setVisible(false);
+ deleteNoteAct->setEnabled(false);
} else if (editMode) {
editNoteAct->setEnabled(false);
saveExitAct->setVisible(true);
discardExitAct->setVisible(true);
saveNoteAct->setVisible(true);
+ deleteNoteAct->setEnabled(true);
} else {
editNoteAct->setEnabled(true);
saveExitAct->setVisible(false);
discardExitAct->setVisible(false);
saveNoteAct->setVisible(false);
+ deleteNoteAct->setEnabled(true);
}
if (empty) {
@@ -773,3 +784,8 @@ void VMainWindow::curEditFileInfo()
{
fileList->fileInfo(curEditNotebook, curEditRelativePath);
}
+
+void VMainWindow::deleteCurNote()
+{
+ fileList->deleteFile(curEditNotebook, curEditRelativePath);
+}
diff --git a/src/vmainwindow.h b/src/vmainwindow.h
index ac49b6a0..db9eada5 100644
--- a/src/vmainwindow.h
+++ b/src/vmainwindow.h
@@ -51,6 +51,7 @@ private slots:
void changePanelView(QAction *action);
void handleFileListDirectoryChanged(const QString ¬ebook, const QString &relativePath);
void curEditFileInfo();
+ void deleteCurNote();
signals:
void curNotebookChanged(const QString ¬ebookName);
@@ -93,6 +94,7 @@ private:
QAction *newRootDirAct;
QAction *newNoteAct;
QAction *noteInfoAct;
+ QAction *deleteNoteAct;
QAction *editNoteAct;
QAction *saveNoteAct;
QAction *saveExitAct;
diff --git a/src/vnote.qrc b/src/vnote.qrc
index fbb1713b..3d8babd5 100644
--- a/src/vnote.qrc
+++ b/src/vnote.qrc
@@ -63,5 +63,6 @@
resources/icons/vnote.ico
resources/vnote.qss
resources/icons/note_info_tb.svg
+ resources/icons/delete_note_tb.svg