diff --git a/src/core/buffermgr.cpp b/src/core/buffermgr.cpp index 9de26e4b..dcd74086 100644 --- a/src/core/buffermgr.cpp +++ b/src/core/buffermgr.cpp @@ -59,6 +59,13 @@ void BufferMgr::open(Node *p_node, const QSharedPointer &p_p return; } + if (!p_node->checkExists()) { + auto msg = QString("Failed to open node that does not exist (%1)").arg(p_node->fetchAbsolutePath()); + qWarning() << msg; + VNoteX::getInst().showStatusMessageShort(msg); + return; + } + auto buffer = findBuffer(p_node); if (!buffer) { auto nodePath = p_node->fetchAbsolutePath(); @@ -91,7 +98,9 @@ void BufferMgr::open(const QString &p_filePath, const QSharedPointercheckNodeExists(this); + if (before != after) { + emit m_notebook->nodeUpdated(this); + } + return after; +} diff --git a/src/core/notebook/node.h b/src/core/notebook/node.h index 130eb57f..2d48130c 100644 --- a/src/core/notebook/node.h +++ b/src/core/notebook/node.h @@ -89,9 +89,11 @@ namespace vnotex bool hasContent() const; - // Whether the node exists on disk. + // Whether the node exists on disk (without real check). bool exists() const; + bool checkExists(); + void setExists(bool p_exists); Node::Flags getFlags() const; diff --git a/src/core/notebookconfigmgr/inotebookconfigmgr.h b/src/core/notebookconfigmgr/inotebookconfigmgr.h index 199fe4d0..c8a1f882 100644 --- a/src/core/notebookconfigmgr/inotebookconfigmgr.h +++ b/src/core/notebookconfigmgr/inotebookconfigmgr.h @@ -78,6 +78,8 @@ namespace vnotex virtual QVector> fetchExternalChildren(Node *p_node) const = 0; + virtual bool checkNodeExists(Node *p_node) = 0; + protected: // Version of the config processing code. virtual QString getCodeVersion() const; diff --git a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp index 8d506ca3..a0a269aa 100644 --- a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp +++ b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp @@ -989,3 +989,10 @@ bool VXNotebookConfigMgr::isExcludedFromExternalNode(const QString &p_name) cons } return false; } + +bool VXNotebookConfigMgr::checkNodeExists(Node *p_node) +{ + bool exists = getBackend()->exists(p_node->fetchPath()); + p_node->setExists(exists); + return exists; +} diff --git a/src/core/notebookconfigmgr/vxnotebookconfigmgr.h b/src/core/notebookconfigmgr/vxnotebookconfigmgr.h index d1958a46..64e61c5f 100644 --- a/src/core/notebookconfigmgr/vxnotebookconfigmgr.h +++ b/src/core/notebookconfigmgr/vxnotebookconfigmgr.h @@ -72,6 +72,8 @@ namespace vnotex QVector> fetchExternalChildren(Node *p_node) const Q_DECL_OVERRIDE; + bool checkNodeExists(Node *p_node) Q_DECL_OVERRIDE; + private: // Config of a file child. struct NodeFileConfig diff --git a/src/widgets/notebooknodeexplorer.cpp b/src/widgets/notebooknodeexplorer.cpp index 44bcdfc6..2aa676a0 100644 --- a/src/widgets/notebooknodeexplorer.cpp +++ b/src/widgets/notebooknodeexplorer.cpp @@ -1906,13 +1906,19 @@ void NotebookNodeExplorer::importToIndex(const QVector &p_nodes) } } -bool NotebookNodeExplorer::checkInvalidNode(const Node *p_node) const +bool NotebookNodeExplorer::checkInvalidNode(Node *p_node) const { if (!p_node) { return true; } - if (!p_node->exists()) { + bool nodeExists = p_node->exists(); + if (nodeExists) { + p_node->checkExists(); + nodeExists = p_node->exists(); + } + + if (!nodeExists) { MessageBoxHelper::notify(MessageBoxHelper::Warning, tr("Invalid node (%1).").arg(p_node->getName()), tr("Please check if the node exists on the disk."), diff --git a/src/widgets/notebooknodeexplorer.h b/src/widgets/notebooknodeexplorer.h index d610258f..8f0f2541 100644 --- a/src/widgets/notebooknodeexplorer.h +++ b/src/widgets/notebooknodeexplorer.h @@ -259,7 +259,7 @@ namespace vnotex // Check whether @p_node is a valid node. Will notify user. // Return true if it is invalid. - bool checkInvalidNode(const Node *p_node) const; + bool checkInvalidNode(Node *p_node) const; void expandCurrentNodeAll();