mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
check if node exists on activated
This commit is contained in:
parent
af85dc5aed
commit
36dd070d05
@ -59,6 +59,13 @@ void BufferMgr::open(Node *p_node, const QSharedPointer<FileOpenParameters> &p_p
|
|||||||
return;
|
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);
|
auto buffer = findBuffer(p_node);
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
auto nodePath = p_node->fetchAbsolutePath();
|
auto nodePath = p_node->fetchAbsolutePath();
|
||||||
@ -91,7 +98,9 @@ void BufferMgr::open(const QString &p_filePath, const QSharedPointer<FileOpenPar
|
|||||||
|
|
||||||
QFileInfo finfo(p_filePath);
|
QFileInfo finfo(p_filePath);
|
||||||
if (!finfo.exists()) {
|
if (!finfo.exists()) {
|
||||||
qWarning() << QString("failed to open file %1 that does not exist").arg(p_filePath);
|
auto msg = QString("Failed to open file that does not exist (%1)").arg(p_filePath);
|
||||||
|
qWarning() << msg;
|
||||||
|
VNoteX::getInst().showStatusMessageShort(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,3 +403,13 @@ void Node::setExists(bool p_exists)
|
|||||||
m_flags &= ~Flag::Exists;
|
m_flags &= ~Flag::Exists;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Node::checkExists()
|
||||||
|
{
|
||||||
|
bool before = exists();
|
||||||
|
bool after = getConfigMgr()->checkNodeExists(this);
|
||||||
|
if (before != after) {
|
||||||
|
emit m_notebook->nodeUpdated(this);
|
||||||
|
}
|
||||||
|
return after;
|
||||||
|
}
|
||||||
|
@ -89,9 +89,11 @@ namespace vnotex
|
|||||||
|
|
||||||
bool hasContent() const;
|
bool hasContent() const;
|
||||||
|
|
||||||
// Whether the node exists on disk.
|
// Whether the node exists on disk (without real check).
|
||||||
bool exists() const;
|
bool exists() const;
|
||||||
|
|
||||||
|
bool checkExists();
|
||||||
|
|
||||||
void setExists(bool p_exists);
|
void setExists(bool p_exists);
|
||||||
|
|
||||||
Node::Flags getFlags() const;
|
Node::Flags getFlags() const;
|
||||||
|
@ -78,6 +78,8 @@ namespace vnotex
|
|||||||
|
|
||||||
virtual QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const = 0;
|
virtual QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const = 0;
|
||||||
|
|
||||||
|
virtual bool checkNodeExists(Node *p_node) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Version of the config processing code.
|
// Version of the config processing code.
|
||||||
virtual QString getCodeVersion() const;
|
virtual QString getCodeVersion() const;
|
||||||
|
@ -989,3 +989,10 @@ bool VXNotebookConfigMgr::isExcludedFromExternalNode(const QString &p_name) cons
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VXNotebookConfigMgr::checkNodeExists(Node *p_node)
|
||||||
|
{
|
||||||
|
bool exists = getBackend()->exists(p_node->fetchPath());
|
||||||
|
p_node->setExists(exists);
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
@ -72,6 +72,8 @@ namespace vnotex
|
|||||||
|
|
||||||
QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const Q_DECL_OVERRIDE;
|
QVector<QSharedPointer<ExternalNode>> fetchExternalChildren(Node *p_node) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
bool checkNodeExists(Node *p_node) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Config of a file child.
|
// Config of a file child.
|
||||||
struct NodeFileConfig
|
struct NodeFileConfig
|
||||||
|
@ -1906,13 +1906,19 @@ void NotebookNodeExplorer::importToIndex(const QVector<ExternalNode *> &p_nodes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotebookNodeExplorer::checkInvalidNode(const Node *p_node) const
|
bool NotebookNodeExplorer::checkInvalidNode(Node *p_node) const
|
||||||
{
|
{
|
||||||
if (!p_node) {
|
if (!p_node) {
|
||||||
return true;
|
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,
|
MessageBoxHelper::notify(MessageBoxHelper::Warning,
|
||||||
tr("Invalid node (%1).").arg(p_node->getName()),
|
tr("Invalid node (%1).").arg(p_node->getName()),
|
||||||
tr("Please check if the node exists on the disk."),
|
tr("Please check if the node exists on the disk."),
|
||||||
|
@ -259,7 +259,7 @@ namespace vnotex
|
|||||||
|
|
||||||
// Check whether @p_node is a valid node. Will notify user.
|
// Check whether @p_node is a valid node. Will notify user.
|
||||||
// Return true if it is invalid.
|
// Return true if it is invalid.
|
||||||
bool checkInvalidNode(const Node *p_node) const;
|
bool checkInvalidNode(Node *p_node) const;
|
||||||
|
|
||||||
void expandCurrentNodeAll();
|
void expandCurrentNodeAll();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user