mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
MdTab: handle non-exist file
This commit is contained in:
parent
8d42ffea0f
commit
29c1c346a4
@ -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) {
|
||||
|
@ -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 <span style=\"%1\">%2</span>.")
|
||||
.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();
|
||||
}
|
||||
|
||||
|
@ -211,5 +211,4 @@ private slots:
|
||||
// Called when app focus changed.
|
||||
void handleFocusChanged(QWidget *p_old, QWidget *p_now);
|
||||
};
|
||||
|
||||
#endif // VEDITTAB_H
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 <span style=\"%1\">%2</span>.")
|
||||
.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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user