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();
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()

View File

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

View File

@ -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 &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,
bool editMode, bool modifiable);
void changePanelView(QAction *action);
void handleFileListDirectoryChanged(const QString &notebook, const QString &relativePath);
signals:
void curNotebookChanged(const QString &notebookName);