diff --git a/src/dialog/vfileinfodialog.cpp b/src/dialog/vfileinfodialog.cpp index 59ad3ed0..40373a87 100644 --- a/src/dialog/vfileinfodialog.cpp +++ b/src/dialog/vfileinfodialog.cpp @@ -103,7 +103,8 @@ void VFileInfoDialog::handleInputChanged() "Please choose another name.") .arg(g_config->c_warningTextStyle); m_warnLabel->setText(nameConflictText); - } else if (VUtils::docTypeFromName(name) != m_file->getDocType()) { + } else if (m_file->getDocType() != DocType::Unknown + && VUtils::docTypeFromName(name) != m_file->getDocType()) { // Check if the name change the doc type. nameOk = false; showWarnLabel = true; diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 73c186c2..84105465 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -492,7 +492,7 @@ DocType VUtils::docTypeFromName(const QString &p_name) } } - return DocType::Html; + return DocType::Unknown; } QString VUtils::generateHtmlTemplate(MarkdownConverterType p_conType, bool p_exportPdf) diff --git a/src/vconfigmanager.cpp b/src/vconfigmanager.cpp index eab1199e..32c06aec 100644 --- a/src/vconfigmanager.cpp +++ b/src/vconfigmanager.cpp @@ -912,5 +912,9 @@ void VConfigManager::initDocSuffixes() container << "co" << "container" << "con"; m_docSuffixes[(int)DocType::Container] = container; + QList html; + html << "html"; + m_docSuffixes[(int)DocType::Html] = html; + qDebug() << "doc suffixes" << m_docSuffixes; } diff --git a/src/vconstants.h b/src/vconstants.h index 2b21275e..305b7c07 100644 --- a/src/vconstants.h +++ b/src/vconstants.h @@ -5,7 +5,7 @@ // Markdown: Markdown text file; // List: Infinite list file like WorkFlowy; // Container: a composite file containing multiple files; -enum class DocType { Html = 0, Markdown, List, Container, Invalid }; +enum class DocType { Html = 0, Markdown, List, Container, Unknown }; // Note: note file managed by VNote; // Orphan: external file; diff --git a/src/veditarea.cpp b/src/veditarea.cpp index 9c5933f0..9465aa34 100644 --- a/src/veditarea.cpp +++ b/src/veditarea.cpp @@ -127,6 +127,13 @@ void VEditArea::openFile(VFile *p_file, OpenFileMode p_mode) return; } + // If it is DocType::Unknown, open it using system default method. + if (p_file->getDocType() == DocType::Unknown) { + QUrl url = QUrl::fromLocalFile(p_file->fetchPath()); + QDesktopServices::openUrl(url); + return; + } + // Find if it has been opened already int winIdx, tabIdx; bool existFile = false; diff --git a/src/veditarea.h b/src/veditarea.h index acbd368e..32e6caf7 100644 --- a/src/veditarea.h +++ b/src/veditarea.h @@ -27,7 +27,10 @@ class VEditArea : public QWidget, public VNavigationMode Q_OBJECT public: explicit VEditArea(VNote *vnote, QWidget *parent = 0); + + // Whether @p_file has been opened in edit area. bool isFileOpened(const VFile *p_file); + bool closeAllFiles(bool p_forced); bool closeFile(const VFile *p_file, bool p_forced); bool closeFile(const VDirectory *p_dir, bool p_forced); diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 9fe95ded..e55d0a5b 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -117,6 +117,21 @@ void VFileList::initActions() } }); + m_openExternalAct = new QAction(tr("Open Via External Program"), this); + m_openExternalAct->setToolTip(tr("Open current note via external program")); + connect(m_openExternalAct, &QAction::triggered, + this, [this]() { + QListWidgetItem *item = fileList->currentItem(); + if (item) { + VNoteFile *file = getVFile(item); + if (file + && (!editArea->isFileOpened(file) || editArea->closeFile(file, false))) { + QUrl url = QUrl::fromLocalFile(file->fetchPath()); + QDesktopServices::openUrl(url); + } + } + }); + deleteFileAct = new QAction(QIcon(":/resources/icons/delete_note.svg"), tr("&Delete"), this); deleteFileAct->setToolTip(tr("Delete selected note")); @@ -221,8 +236,6 @@ void VFileList::fileInfo(VNoteFile *p_file) return; } - Q_ASSERT(p_file->getDocType() == VUtils::docTypeFromName(name)); - if (!p_file->rename(name)) { VUtils::showMessage(QMessageBox::Warning, tr("Warning"), tr("Fail to rename note %2.") @@ -430,9 +443,13 @@ void VFileList::contextMenuRequested(QPoint pos) if (item && fileList->selectedItems().size() == 1) { VNoteFile *file = getVFile(item); - if (file && file->getDocType() == DocType::Markdown) { - menu.addAction(m_openInReadAct); - menu.addAction(m_openInEditAct); + if (file) { + if (file->getDocType() == DocType::Markdown) { + menu.addAction(m_openInReadAct); + menu.addAction(m_openInEditAct); + } + + menu.addAction(m_openExternalAct); menu.addSeparator(); } } diff --git a/src/vfilelist.h b/src/vfilelist.h index d73202db..caeca297 100644 --- a/src/vfilelist.h +++ b/src/vfilelist.h @@ -106,6 +106,7 @@ private: // Actions QAction *m_openInReadAct; QAction *m_openInEditAct; + QAction *m_openExternalAct; QAction *newFileAct; QAction *deleteFileAct; QAction *fileInfoAct; diff --git a/src/vnotefile.cpp b/src/vnotefile.cpp index e9c6ad0b..05a05c00 100644 --- a/src/vnotefile.cpp +++ b/src/vnotefile.cpp @@ -87,7 +87,10 @@ bool VNoteFile::rename(const QString &p_name) } // Can't not change doc type. - Q_ASSERT(m_docType == VUtils::docTypeFromName(m_name)); + Q_ASSERT(m_docType == DocType::Unknown + || m_docType == VUtils::docTypeFromName(m_name)); + + m_docType = VUtils::docTypeFromName(m_name); qDebug() << "file renamed from" << oldName << "to" << m_name; return true;