diff --git a/src/utils/vmetawordmanager.cpp b/src/utils/vmetawordmanager.cpp index f5401c81..4ddec9dc 100644 --- a/src/utils/vmetawordmanager.cpp +++ b/src/utils/vmetawordmanager.cpp @@ -302,7 +302,7 @@ void VMetaWordManager::init() }); // %w% - addMetaWord(MetaWordType::Dynamic, + addMetaWord(MetaWordType::FunctionBased, "w", tr("the week number (`1` to `53`)"), [](const VMetaWord *p_metaWord) { diff --git a/src/vedittab.cpp b/src/vedittab.cpp index 8acbc3c0..1e033074 100644 --- a/src/vedittab.cpp +++ b/src/vedittab.cpp @@ -187,9 +187,21 @@ void VEditTab::checkFileChangeOutside() void VEditTab::reloadFromDisk() { - m_file->reload(); - m_fileDiverged = false; - m_checkFileChange = true; + bool ret = m_file->reload(); + if (!ret) { + VUtils::showMessage(QMessageBox::Warning, + tr("Warning"), + tr("Fail to reload note %2.") + .arg(g_config->c_dataTextStyle).arg(m_file->getName()), + tr("Please check if file %1 exists.").arg(m_file->fetchPath()), + QMessageBox::Ok, + QMessageBox::Ok, + this); + } + + m_fileDiverged = !ret; + m_checkFileChange = ret; + reload(); } diff --git a/src/vedittab.h b/src/vedittab.h index 1d5d7351..d266de42 100644 --- a/src/vedittab.h +++ b/src/vedittab.h @@ -211,5 +211,4 @@ private slots: // Called when app focus changed. void handleFocusChanged(QWidget *p_old, QWidget *p_now); }; - #endif // VEDITTAB_H diff --git a/src/vfile.cpp b/src/vfile.cpp index 1e1f476b..d33d0642 100644 --- a/src/vfile.cpp +++ b/src/vfile.cpp @@ -126,14 +126,21 @@ bool VFile::isChangedOutside(bool &p_missing) const return lm.toSecsSinceEpoch() != m_lastModified.toSecsSinceEpoch(); } -void VFile::reload() +bool VFile::reload() { - Q_ASSERT(m_opened); + if (!m_opened) { + return false; + } QString filePath = fetchPath(); - Q_ASSERT(QFileInfo::exists(filePath)); + if (!QFileInfo::exists(filePath)) { + m_content.clear(); + return false; + } + m_content = VUtils::readFileFromDisk(filePath); m_lastModified = QFileInfo(filePath).lastModified(); + return true; } QString VFile::backupFileOfPreviousSession() const diff --git a/src/vfile.h b/src/vfile.h index 19a40a05..f723a445 100644 --- a/src/vfile.h +++ b/src/vfile.h @@ -33,7 +33,7 @@ public: virtual bool save(); // Reload content from disk. - virtual void reload(); + virtual bool reload(); const QString &getName() const; @@ -163,7 +163,6 @@ inline FileType VFile::getType() const inline const QString &VFile::getContent() const { - Q_ASSERT(m_opened); return m_content; } diff --git a/src/vmdtab.cpp b/src/vmdtab.cpp index b4ce9db4..fe053de3 100644 --- a/src/vmdtab.cpp +++ b/src/vmdtab.cpp @@ -45,7 +45,16 @@ VMdTab::VMdTab(VFile *p_file, VEditArea *p_editArea, { V_ASSERT(m_file->getDocType() == DocType::Markdown); - m_file->open(); + if (!m_file->open()) { + VUtils::showMessage(QMessageBox::Warning, + tr("Warning"), + tr("Fail to open note %2.") + .arg(g_config->c_dataTextStyle).arg(m_file->getName()), + tr("Please check if file %1 exists.").arg(m_file->fetchPath()), + QMessageBox::Ok, + QMessageBox::Ok, + this); + } HeadingSequenceType headingSequenceType = g_config->getHeadingSequenceType(); if (headingSequenceType == HeadingSequenceType::Enabled) {