refine DocType

- Use *.html suffix for rich text file;
- For unknown DocType, open it using system's default app;
- Add "Open Via External Program" item in context menu of VFileList;
This commit is contained in:
Le Tan 2017-09-26 19:28:11 +08:00
parent fb4e818e20
commit ffd0cc8e6e
9 changed files with 45 additions and 9 deletions

View File

@ -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;

View File

@ -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)

View File

@ -912,5 +912,9 @@ void VConfigManager::initDocSuffixes()
container << "co" << "container" << "con";
m_docSuffixes[(int)DocType::Container] = container;
QList<QString> html;
html << "html";
m_docSuffixes[(int)DocType::Html] = html;
qDebug() << "doc suffixes" << m_docSuffixes;
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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 <span style=\"%1\">%2</span>.")
@ -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();
}
}

View File

@ -106,6 +106,7 @@ private:
// Actions
QAction *m_openInReadAct;
QAction *m_openInEditAct;
QAction *m_openExternalAct;
QAction *newFileAct;
QAction *deleteFileAct;
QAction *fileInfoAct;

View File

@ -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;