disable newNoteAct if FileList's directory is not set

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-11-03 21:39:46 +08:00
parent a69bd43e5a
commit 1bc95bcea0
4 changed files with 17 additions and 0 deletions

View File

@ -69,6 +69,7 @@ void VFileList::setDirectory(QJsonObject dirJson)
fileList->clear(); fileList->clear();
if (dirJson.isEmpty()) { if (dirJson.isEmpty()) {
clearDirectoryInfo(); clearDirectoryInfo();
emit directoryChanged("", "");
return; return;
} }
@ -85,6 +86,8 @@ void VFileList::setDirectory(QJsonObject dirJson)
Q_ASSERT(!rootPath.isEmpty()); Q_ASSERT(!rootPath.isEmpty());
updateFileList(); updateFileList();
emit directoryChanged(notebook, relativePath);
} }
void VFileList::clearDirectoryInfo() void VFileList::clearDirectoryInfo()

View File

@ -26,6 +26,7 @@ signals:
void fileCreated(QJsonObject fileJson); void fileCreated(QJsonObject fileJson);
void fileRenamed(const QString &notebook, const QString &oldPath, void fileRenamed(const QString &notebook, const QString &oldPath,
const QString &newPath); const QString &newPath);
void directoryChanged(const QString &notebook, const QString &relativePath);
private slots: private slots:
void contextMenuRequested(QPoint pos); void contextMenuRequested(QPoint pos);

View File

@ -102,6 +102,8 @@ void VMainWindow::setupUI()
fileList, &VFileList::setDirectory); fileList, &VFileList::setDirectory);
connect(directoryTree, &VDirectoryTree::directoryRenamed, connect(directoryTree, &VDirectoryTree::directoryRenamed,
fileList, &VFileList::handleDirectoryRenamed); fileList, &VFileList::handleDirectoryRenamed);
connect(fileList, &VFileList::directoryChanged,
this, &VMainWindow::handleFileListDirectoryChanged);
connect(fileList, &VFileList::fileClicked, connect(fileList, &VFileList::fileClicked,
tabs, &VTabWidget::openFile); tabs, &VTabWidget::openFile);
@ -266,6 +268,7 @@ void VMainWindow::initToolBar()
fileToolBar->addAction(discardExitAct); fileToolBar->addAction(discardExitAct);
fileToolBar->addAction(saveNoteAct); fileToolBar->addAction(saveNoteAct);
newNoteAct->setEnabled(false);
editNoteAct->setEnabled(false); editNoteAct->setEnabled(false);
saveExitAct->setVisible(false); saveExitAct->setVisible(false);
discardExitAct->setVisible(false); discardExitAct->setVisible(false);
@ -695,3 +698,12 @@ void VMainWindow::changeSplitterView(int nrPanel)
qWarning() << "error: invalid panel number" << nrPanel; qWarning() << "error: invalid panel number" << nrPanel;
} }
} }
void VMainWindow::handleFileListDirectoryChanged(const QString &notebook, const QString &relativePath)
{
if (relativePath.isEmpty()) {
newNoteAct->setEnabled(false);
} else {
newNoteAct->setEnabled(true);
}
}

View File

@ -47,6 +47,7 @@ private slots:
void updateToolbarFromTabChage(const QString &notebook, const QString &relativePath, void updateToolbarFromTabChage(const QString &notebook, const QString &relativePath,
bool editMode, bool modifiable); bool editMode, bool modifiable);
void changePanelView(QAction *action); void changePanelView(QAction *action);
void handleFileListDirectoryChanged(const QString &notebook, const QString &relativePath);
signals: signals:
void curNotebookChanged(const QString &notebookName); void curNotebookChanged(const QString &notebookName);