diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp
index fb59feb8..085eac30 100644
--- a/src/vdirectorytree.cpp
+++ b/src/vdirectorytree.cpp
@@ -115,6 +115,11 @@ void VDirectoryTree::initActions()
m_openLocationAct->setToolTip(tr("Open the folder containing this folder in operating system"));
connect(m_openLocationAct, &QAction::triggered,
this, &VDirectoryTree::openDirectoryLocation);
+
+ m_reloadAct = new QAction(tr("&Reload From Disk"), this);
+ m_reloadAct->setToolTip(tr("Reload the content of this folder (or notebook) from disk"));
+ connect(m_reloadAct, &QAction::triggered,
+ this, &VDirectoryTree::reloadFromDisk);
}
void VDirectoryTree::setNotebook(VNotebook *p_notebook)
@@ -140,7 +145,9 @@ void VDirectoryTree::setNotebook(VNotebook *p_notebook)
if (!m_notebook->open()) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to open notebook %2.")
- .arg(g_config->c_dataTextStyle).arg(m_notebook->getName()), "",
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getName()),
+ tr("Please check if path %2 exists.")
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getPath()),
QMessageBox::Ok, QMessageBox::Ok, this);
clear();
return;
@@ -202,7 +209,9 @@ void VDirectoryTree::buildSubTree(QTreeWidgetItem *p_parent, int p_depth)
if (!dir->open()) {
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
tr("Fail to open folder %2.")
- .arg(g_config->c_dataTextStyle).arg(dir->getName()), "",
+ .arg(g_config->c_dataTextStyle).arg(dir->getName()),
+ tr("Please check if path %2 exists.")
+ .arg(g_config->c_dataTextStyle).arg(dir->retrivePath()),
QMessageBox::Ok, QMessageBox::Ok, this);
return;
}
@@ -355,8 +364,10 @@ void VDirectoryTree::contextMenuRequested(QPoint pos)
menu.addAction(pasteAct);
}
+ menu.addSeparator();
+ menu.addAction(m_reloadAct);
+
if (item) {
- menu.addSeparator();
menu.addAction(m_openLocationAct);
menu.addAction(dirInfoAct);
}
@@ -532,6 +543,81 @@ void VDirectoryTree::openDirectoryLocation() const
QDesktopServices::openUrl(url);
}
+void VDirectoryTree::reloadFromDisk()
+{
+ if (!m_notebook) {
+ return;
+ }
+
+ QString info;
+ VDirectory *curDir = NULL;
+ QTreeWidgetItem *curItem = currentItem();
+ if (curItem) {
+ // Reload current directory.
+ curDir = getVDirectory(curItem);
+ info = tr("Are you sure to reload folder %2?")
+ .arg(g_config->c_dataTextStyle).arg(curDir->getName());
+ } else {
+ // Reload notebook.
+ info = tr("Are you sure to reload notebook %2?")
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getName());
+ }
+
+ int ret = VUtils::showMessage(QMessageBox::Information, tr("Information"),
+ info,
+ tr("VNote will close all the related notes before reload."),
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Ok, this);
+
+ if (ret != QMessageBox::Ok) {
+ return;
+ }
+
+ m_notebookCurrentDirMap.remove(m_notebook);
+
+ if (curItem) {
+ if (!m_editArea->closeFile(curDir, false)) {
+ return;
+ }
+
+ setCurrentItem(NULL);
+
+ curItem->setExpanded(false);
+ curDir->setExpanded(false);
+
+ curDir->close();
+
+ // Remove all its children.
+ QList children = curItem->takeChildren();
+ for (int i = 0; i < children.size(); ++i) {
+ delete children[i];
+ }
+
+ buildSubTree(curItem, 1);
+
+ setCurrentItem(curItem);
+ } else {
+ if (!m_editArea->closeFile(m_notebook, false)) {
+ return;
+ }
+
+ m_notebook->close();
+
+ if (!m_notebook->open()) {
+ VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
+ tr("Fail to open notebook %2.")
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getName()),
+ tr("Please check if path %2 exists.")
+ .arg(g_config->c_dataTextStyle).arg(m_notebook->getPath()),
+ QMessageBox::Ok, QMessageBox::Ok, this);
+ clear();
+ return;
+ }
+
+ updateDirectoryTree();
+ }
+}
+
void VDirectoryTree::copySelectedDirectories(bool p_cut)
{
QList items = selectedItems();
diff --git a/src/vdirectorytree.h b/src/vdirectorytree.h
index 7db9a572..6d390c52 100644
--- a/src/vdirectorytree.h
+++ b/src/vdirectorytree.h
@@ -56,6 +56,9 @@ private slots:
void pasteDirectoriesInCurDir();
void openDirectoryLocation() const;
+ // Reload the content of current directory.
+ void reloadFromDisk();
+
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
@@ -123,6 +126,9 @@ private:
QAction *pasteAct;
QAction *m_openLocationAct;
+ // Reload content from disk.
+ QAction *m_reloadAct;
+
// Navigation Mode.
// Map second key to QTreeWidgetItem.
QMap m_keyMap;
diff --git a/src/vnotebook.cpp b/src/vnotebook.cpp
index c42fdbe5..a472d849 100644
--- a/src/vnotebook.cpp
+++ b/src/vnotebook.cpp
@@ -82,12 +82,12 @@ bool VNotebook::writeConfig() const
return VConfigManager::writeDirectoryConfig(m_path, json);
}
-QString VNotebook::getName() const
+const QString &VNotebook::getName() const
{
return m_name;
}
-QString VNotebook::getPath() const
+const QString &VNotebook::getPath() const
{
return m_path;
}
diff --git a/src/vnotebook.h b/src/vnotebook.h
index 3c2f82eb..c01153a0 100644
--- a/src/vnotebook.h
+++ b/src/vnotebook.h
@@ -33,8 +33,8 @@ public:
// if @p_path is not inside this notebook.
VFile *tryLoadFile(const QString &p_path);
- QString getName() const;
- QString getPath() const;
+ const QString &getName() const;
+ const QString &getPath() const;
VDirectory *getRootDir() const;