mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
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:
parent
fb4e818e20
commit
ffd0cc8e6e
@ -103,7 +103,8 @@ void VFileInfoDialog::handleInputChanged()
|
|||||||
"Please choose another name.")
|
"Please choose another name.")
|
||||||
.arg(g_config->c_warningTextStyle);
|
.arg(g_config->c_warningTextStyle);
|
||||||
m_warnLabel->setText(nameConflictText);
|
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.
|
// Check if the name change the doc type.
|
||||||
nameOk = false;
|
nameOk = false;
|
||||||
showWarnLabel = true;
|
showWarnLabel = true;
|
||||||
|
@ -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)
|
QString VUtils::generateHtmlTemplate(MarkdownConverterType p_conType, bool p_exportPdf)
|
||||||
|
@ -912,5 +912,9 @@ void VConfigManager::initDocSuffixes()
|
|||||||
container << "co" << "container" << "con";
|
container << "co" << "container" << "con";
|
||||||
m_docSuffixes[(int)DocType::Container] = container;
|
m_docSuffixes[(int)DocType::Container] = container;
|
||||||
|
|
||||||
|
QList<QString> html;
|
||||||
|
html << "html";
|
||||||
|
m_docSuffixes[(int)DocType::Html] = html;
|
||||||
|
|
||||||
qDebug() << "doc suffixes" << m_docSuffixes;
|
qDebug() << "doc suffixes" << m_docSuffixes;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
// Markdown: Markdown text file;
|
// Markdown: Markdown text file;
|
||||||
// List: Infinite list file like WorkFlowy;
|
// List: Infinite list file like WorkFlowy;
|
||||||
// Container: a composite file containing multiple files;
|
// 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;
|
// Note: note file managed by VNote;
|
||||||
// Orphan: external file;
|
// Orphan: external file;
|
||||||
|
@ -127,6 +127,13 @@ void VEditArea::openFile(VFile *p_file, OpenFileMode p_mode)
|
|||||||
return;
|
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
|
// Find if it has been opened already
|
||||||
int winIdx, tabIdx;
|
int winIdx, tabIdx;
|
||||||
bool existFile = false;
|
bool existFile = false;
|
||||||
|
@ -27,7 +27,10 @@ class VEditArea : public QWidget, public VNavigationMode
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VEditArea(VNote *vnote, QWidget *parent = 0);
|
explicit VEditArea(VNote *vnote, QWidget *parent = 0);
|
||||||
|
|
||||||
|
// Whether @p_file has been opened in edit area.
|
||||||
bool isFileOpened(const VFile *p_file);
|
bool isFileOpened(const VFile *p_file);
|
||||||
|
|
||||||
bool closeAllFiles(bool p_forced);
|
bool closeAllFiles(bool p_forced);
|
||||||
bool closeFile(const VFile *p_file, bool p_forced);
|
bool closeFile(const VFile *p_file, bool p_forced);
|
||||||
bool closeFile(const VDirectory *p_dir, bool p_forced);
|
bool closeFile(const VDirectory *p_dir, bool p_forced);
|
||||||
|
@ -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"),
|
deleteFileAct = new QAction(QIcon(":/resources/icons/delete_note.svg"),
|
||||||
tr("&Delete"), this);
|
tr("&Delete"), this);
|
||||||
deleteFileAct->setToolTip(tr("Delete selected note"));
|
deleteFileAct->setToolTip(tr("Delete selected note"));
|
||||||
@ -221,8 +236,6 @@ void VFileList::fileInfo(VNoteFile *p_file)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_ASSERT(p_file->getDocType() == VUtils::docTypeFromName(name));
|
|
||||||
|
|
||||||
if (!p_file->rename(name)) {
|
if (!p_file->rename(name)) {
|
||||||
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
VUtils::showMessage(QMessageBox::Warning, tr("Warning"),
|
||||||
tr("Fail to rename note <span style=\"%1\">%2</span>.")
|
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) {
|
if (item && fileList->selectedItems().size() == 1) {
|
||||||
VNoteFile *file = getVFile(item);
|
VNoteFile *file = getVFile(item);
|
||||||
if (file && file->getDocType() == DocType::Markdown) {
|
if (file) {
|
||||||
|
if (file->getDocType() == DocType::Markdown) {
|
||||||
menu.addAction(m_openInReadAct);
|
menu.addAction(m_openInReadAct);
|
||||||
menu.addAction(m_openInEditAct);
|
menu.addAction(m_openInEditAct);
|
||||||
|
}
|
||||||
|
|
||||||
|
menu.addAction(m_openExternalAct);
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,7 @@ private:
|
|||||||
// Actions
|
// Actions
|
||||||
QAction *m_openInReadAct;
|
QAction *m_openInReadAct;
|
||||||
QAction *m_openInEditAct;
|
QAction *m_openInEditAct;
|
||||||
|
QAction *m_openExternalAct;
|
||||||
QAction *newFileAct;
|
QAction *newFileAct;
|
||||||
QAction *deleteFileAct;
|
QAction *deleteFileAct;
|
||||||
QAction *fileInfoAct;
|
QAction *fileInfoAct;
|
||||||
|
@ -87,7 +87,10 @@ bool VNoteFile::rename(const QString &p_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Can't not change doc type.
|
// 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;
|
qDebug() << "file renamed from" << oldName << "to" << m_name;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user