add delete note button in tool bar

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-11-15 22:17:15 +08:00
parent a6c2416cc8
commit c7259c307e
6 changed files with 55 additions and 15 deletions

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<path d="M341,128V99c0-19.1-14.5-35-34.5-35H205.4C185.5,64,171,79.9,171,99v29H80v32h9.2c0,0,5.4,0.6,8.2,3.4c2.8,2.8,3.9,9,3.9,9
l19,241.7c1.5,29.4,1.5,33.9,36,33.9h199.4c34.5,0,34.5-4.4,36-33.8l19-241.6c0,0,1.1-6.3,3.9-9.1c2.8-2.8,8.2-3.4,8.2-3.4h9.2v-32
h-91V128z M192,99c0-9.6,7.8-15,17.7-15h91.7c9.9,0,18.6,5.5,18.6,15v29H192V99z M183.5,384l-10.3-192h20.3L204,384H183.5z
M267.1,384h-22V192h22V384z M328.7,384h-20.4l10.5-192h20.3L328.7,384z"/>
</svg>

After

Width:  |  Height:  |  Size: 944 B

View File

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

View File

@ -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 &notebook, 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);

View File

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

View File

@ -51,6 +51,7 @@ private slots:
void changePanelView(QAction *action);
void handleFileListDirectoryChanged(const QString &notebook, const QString &relativePath);
void curEditFileInfo();
void deleteCurNote();
signals:
void curNotebookChanged(const QString &notebookName);
@ -93,6 +94,7 @@ private:
QAction *newRootDirAct;
QAction *newNoteAct;
QAction *noteInfoAct;
QAction *deleteNoteAct;
QAction *editNoteAct;
QAction *saveNoteAct;
QAction *saveExitAct;

View File

@ -63,5 +63,6 @@
<file>resources/icons/vnote.ico</file>
<file>resources/vnote.qss</file>
<file>resources/icons/note_info_tb.svg</file>
<file>resources/icons/delete_note_tb.svg</file>
</qresource>
</RCC>