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); tr("&Delete"), this);
deleteFileAct->setStatusTip(tr("Delete selected note")); deleteFileAct->setStatusTip(tr("Delete selected note"));
connect(deleteFileAct, &QAction::triggered, connect(deleteFileAct, &QAction::triggered,
this, &VFileList::deleteFile); this, &VFileList::deleteCurFile);
fileInfoAct = new QAction(QIcon(":/resources/icons/note_info.svg"), fileInfoAct = new QAction(QIcon(":/resources/icons/note_info.svg"),
tr("&Info"), this); tr("&Info"), this);
@ -130,7 +130,7 @@ void VFileList::fileInfo(const QString &p_notebook, const QString &p_relativePat
{ {
qDebug() << "fileInfo" << p_notebook << p_relativePath; qDebug() << "fileInfo" << p_notebook << p_relativePath;
QString info; QString info;
QString defaultName = VUtils::directoryNameFromPath(p_relativePath); QString defaultName = VUtils::fileNameFromPath(p_relativePath);
QString curName = defaultName; QString curName = defaultName;
do { do {
VFileInfoDialog dialog(tr("Note Information"), info, defaultName, this); VFileInfoDialog dialog(tr("Note Information"), info, defaultName, this);
@ -209,27 +209,34 @@ void VFileList::newFile()
} while (true); } while (true);
} }
void VFileList::deleteFile() void VFileList::deleteCurFile()
{ {
QListWidgetItem *curItem = fileList->currentItem(); QListWidgetItem *curItem = fileList->currentItem();
Q_ASSERT(curItem); Q_ASSERT(curItem);
QJsonObject curItemJson = curItem->data(Qt::UserRole).toJsonObject(); QJsonObject curItemJson = curItem->data(Qt::UserRole).toJsonObject();
QString curItemName = curItemJson["name"].toString(); 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"), QMessageBox msgBox(QMessageBox::Warning, tr("Warning"),
QString("Are you sure you want to delete note \"%1\"?") QString("Are you sure you want to delete note \"%1\"?")
.arg(curItemName), QMessageBox::Ok | QMessageBox::Cancel, .arg(fileName), QMessageBox::Ok | QMessageBox::Cancel,
this); this);
msgBox.setInformativeText(tr("This may be not recoverable.")); msgBox.setInformativeText(tr("This may be not recoverable."));
msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setDefaultButton(QMessageBox::Ok);
if (msgBox.exec() == QMessageBox::Ok) { if (msgBox.exec() == QMessageBox::Ok) {
// First close this file forcely // First close this file forcely
curItemJson["notebook"] = notebook; QJsonObject curItemJson;
curItemJson["relative_path"] = QDir::cleanPath(QDir(relativePath).filePath(curItemName)); curItemJson["notebook"] = p_notebook;
curItemJson["relative_path"] = QDir::cleanPath(p_relativePath);
curItemJson["is_forced"] = true; curItemJson["is_forced"] = true;
emit fileDeleted(curItemJson); emit fileDeleted(curItemJson);
deleteFileAndUpdateList(curItem); deleteFileAndUpdateList(p_notebook, p_relativePath);
} }
} }
@ -317,12 +324,11 @@ QListWidgetItem* VFileList::createFileAndUpdateList(const QString &name)
return insertFileListItem(fileJson, true); return insertFileListItem(fileJson, true);
} }
void VFileList::deleteFileAndUpdateList(QListWidgetItem *item) void VFileList::deleteFileAndUpdateList(const QString &p_notebook,
const QString &p_relativePath)
{ {
Q_ASSERT(item); QString path = QDir(vnote->getNotebookPath(p_notebook)).filePath(VUtils::basePathFromPath(p_relativePath));
QJsonObject itemJson = item->data(Qt::UserRole).toJsonObject(); QString fileName = VUtils::fileNameFromPath(p_relativePath);
QString path = QDir(rootPath).filePath(relativePath);
QString fileName = itemJson["name"].toString();
QString filePath = QDir(path).filePath(fileName); QString filePath = QDir(path).filePath(fileName);
// Update current directory's config file to exclude this file // Update current directory's config file to exclude this file
@ -357,8 +363,11 @@ void VFileList::deleteFileAndUpdateList(QListWidgetItem *item)
qDebug() << "delete" << filePath; qDebug() << "delete" << filePath;
} }
QListWidgetItem *item = findItem(p_notebook, p_relativePath);
if (item) {
removeFileListItem(item); removeFileListItem(item);
} }
}
void VFileList::handleItemClicked(QListWidgetItem *currentItem) void VFileList::handleItemClicked(QListWidgetItem *currentItem)
{ {

View File

@ -23,6 +23,7 @@ public:
bool importFile(const QString &name); bool importFile(const QString &name);
inline void setEditArea(VEditArea *editArea); inline void setEditArea(VEditArea *editArea);
void fileInfo(const QString &p_notebook, const QString &p_relativePath); void fileInfo(const QString &p_notebook, const QString &p_relativePath);
void deleteFile(const QString &p_notebook, const QString &p_relativePath);
signals: signals:
void fileClicked(QJsonObject fileJson); void fileClicked(QJsonObject fileJson);
@ -36,6 +37,7 @@ private slots:
void contextMenuRequested(QPoint pos); void contextMenuRequested(QPoint pos);
void handleItemClicked(QListWidgetItem *currentItem); void handleItemClicked(QListWidgetItem *currentItem);
void curFileInfo(); void curFileInfo();
void deleteCurFile();
public slots: public slots:
void setDirectory(QJsonObject dirJson); void setDirectory(QJsonObject dirJson);
@ -44,7 +46,6 @@ public slots:
void handleDirectoryRenamed(const QString &notebook, const QString &oldRelativePath, void handleDirectoryRenamed(const QString &notebook, const QString &oldRelativePath,
const QString &newRelativePath); const QString &newRelativePath);
void newFile(); void newFile();
void deleteFile();
private: private:
void setupUI(); void setupUI();
@ -54,7 +55,8 @@ private:
void initActions(); void initActions();
bool isConflictNameWithExisting(const QString &name); bool isConflictNameWithExisting(const QString &name);
QListWidgetItem *createFileAndUpdateList(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 clearDirectoryInfo();
void renameFile(const QString &p_notebook, void renameFile(const QString &p_notebook,
const QString &p_relativePath, const QString &p_newName); const QString &p_relativePath, const QString &p_newName);

View File

@ -161,6 +161,12 @@ void VMainWindow::initActions()
connect(noteInfoAct, &QAction::triggered, connect(noteInfoAct, &QAction::triggered,
this, &VMainWindow::curEditFileInfo); 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"), editNoteAct = new QAction(QIcon(":/resources/icons/edit_note.svg"),
tr("&Edit"), this); tr("&Edit"), this);
editNoteAct->setStatusTip(tr("Edit current note")); editNoteAct->setStatusTip(tr("Edit current note"));
@ -270,6 +276,7 @@ void VMainWindow::initToolBar()
fileToolBar->addAction(newRootDirAct); fileToolBar->addAction(newRootDirAct);
fileToolBar->addAction(newNoteAct); fileToolBar->addAction(newNoteAct);
fileToolBar->addAction(noteInfoAct); fileToolBar->addAction(noteInfoAct);
fileToolBar->addAction(deleteNoteAct);
fileToolBar->addAction(editNoteAct); fileToolBar->addAction(editNoteAct);
fileToolBar->addAction(saveExitAct); fileToolBar->addAction(saveExitAct);
fileToolBar->addAction(discardExitAct); fileToolBar->addAction(discardExitAct);
@ -278,6 +285,7 @@ void VMainWindow::initToolBar()
newRootDirAct->setEnabled(false); newRootDirAct->setEnabled(false);
newNoteAct->setEnabled(false); newNoteAct->setEnabled(false);
noteInfoAct->setEnabled(false); noteInfoAct->setEnabled(false);
deleteNoteAct->setEnabled(false);
editNoteAct->setEnabled(false); editNoteAct->setEnabled(false);
saveExitAct->setVisible(false); saveExitAct->setVisible(false);
discardExitAct->setVisible(false); discardExitAct->setVisible(false);
@ -678,16 +686,19 @@ void VMainWindow::updateToolbarFromTabChage(bool empty, bool editMode, bool modi
saveExitAct->setVisible(false); saveExitAct->setVisible(false);
discardExitAct->setVisible(false); discardExitAct->setVisible(false);
saveNoteAct->setVisible(false); saveNoteAct->setVisible(false);
deleteNoteAct->setEnabled(false);
} else if (editMode) { } else if (editMode) {
editNoteAct->setEnabled(false); editNoteAct->setEnabled(false);
saveExitAct->setVisible(true); saveExitAct->setVisible(true);
discardExitAct->setVisible(true); discardExitAct->setVisible(true);
saveNoteAct->setVisible(true); saveNoteAct->setVisible(true);
deleteNoteAct->setEnabled(true);
} else { } else {
editNoteAct->setEnabled(true); editNoteAct->setEnabled(true);
saveExitAct->setVisible(false); saveExitAct->setVisible(false);
discardExitAct->setVisible(false); discardExitAct->setVisible(false);
saveNoteAct->setVisible(false); saveNoteAct->setVisible(false);
deleteNoteAct->setEnabled(true);
} }
if (empty) { if (empty) {
@ -773,3 +784,8 @@ void VMainWindow::curEditFileInfo()
{ {
fileList->fileInfo(curEditNotebook, curEditRelativePath); fileList->fileInfo(curEditNotebook, curEditRelativePath);
} }
void VMainWindow::deleteCurNote()
{
fileList->deleteFile(curEditNotebook, curEditRelativePath);
}

View File

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

View File

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