From 1bc95bcea03dccdc4be15c74f823eede2c7fe9ca Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 3 Nov 2016 21:39:46 +0800 Subject: [PATCH] disable newNoteAct if FileList's directory is not set Signed-off-by: Le Tan --- src/vfilelist.cpp | 3 +++ src/vfilelist.h | 1 + src/vmainwindow.cpp | 12 ++++++++++++ src/vmainwindow.h | 1 + 4 files changed, 17 insertions(+) diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 733acb51..8e41bb56 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -69,6 +69,7 @@ void VFileList::setDirectory(QJsonObject dirJson) fileList->clear(); if (dirJson.isEmpty()) { clearDirectoryInfo(); + emit directoryChanged("", ""); return; } @@ -85,6 +86,8 @@ void VFileList::setDirectory(QJsonObject dirJson) Q_ASSERT(!rootPath.isEmpty()); updateFileList(); + + emit directoryChanged(notebook, relativePath); } void VFileList::clearDirectoryInfo() diff --git a/src/vfilelist.h b/src/vfilelist.h index 4b4a169b..2bd85b17 100644 --- a/src/vfilelist.h +++ b/src/vfilelist.h @@ -26,6 +26,7 @@ signals: void fileCreated(QJsonObject fileJson); void fileRenamed(const QString ¬ebook, const QString &oldPath, const QString &newPath); + void directoryChanged(const QString ¬ebook, const QString &relativePath); private slots: void contextMenuRequested(QPoint pos); diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 71398a61..ec71eb81 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -102,6 +102,8 @@ void VMainWindow::setupUI() fileList, &VFileList::setDirectory); connect(directoryTree, &VDirectoryTree::directoryRenamed, fileList, &VFileList::handleDirectoryRenamed); + connect(fileList, &VFileList::directoryChanged, + this, &VMainWindow::handleFileListDirectoryChanged); connect(fileList, &VFileList::fileClicked, tabs, &VTabWidget::openFile); @@ -266,6 +268,7 @@ void VMainWindow::initToolBar() fileToolBar->addAction(discardExitAct); fileToolBar->addAction(saveNoteAct); + newNoteAct->setEnabled(false); editNoteAct->setEnabled(false); saveExitAct->setVisible(false); discardExitAct->setVisible(false); @@ -695,3 +698,12 @@ void VMainWindow::changeSplitterView(int nrPanel) qWarning() << "error: invalid panel number" << nrPanel; } } + +void VMainWindow::handleFileListDirectoryChanged(const QString ¬ebook, const QString &relativePath) +{ + if (relativePath.isEmpty()) { + newNoteAct->setEnabled(false); + } else { + newNoteAct->setEnabled(true); + } +} diff --git a/src/vmainwindow.h b/src/vmainwindow.h index 9135fa14..e1a8b1a0 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -47,6 +47,7 @@ private slots: void updateToolbarFromTabChage(const QString ¬ebook, const QString &relativePath, bool editMode, bool modifiable); void changePanelView(QAction *action); + void handleFileListDirectoryChanged(const QString ¬ebook, const QString &relativePath); signals: void curNotebookChanged(const QString ¬ebookName);