support links to internal notes

This commit is contained in:
Le Tan 2017-08-11 21:53:37 +08:00
parent 2e7590de24
commit b5646a2b34
4 changed files with 44 additions and 8 deletions

View File

@ -1907,6 +1907,24 @@ void VMainWindow::handleVimStatusUpdated(const VVim *p_vim)
} }
} }
bool VMainWindow::tryOpenInternalFile(const QString &p_filePath)
{
if (p_filePath.isEmpty()) {
return false;
}
if (QFileInfo::exists(p_filePath)) {
VFile *file = vnote->getInternalFile(p_filePath);
if (file) {
editArea->openFile(file, OpenFileMode::Read);
return true;
}
}
return false;
}
void VMainWindow::openExternalFiles(const QStringList &p_files, bool p_forceOrphan) void VMainWindow::openExternalFiles(const QStringList &p_files, bool p_forceOrphan)
{ {
qDebug() << "open external files" << p_files; qDebug() << "open external files" << p_files;

View File

@ -57,6 +57,9 @@ public:
// it is a note inside VNote. If yes, VNote will open it as internal file. // it is a note inside VNote. If yes, VNote will open it as internal file.
void openExternalFiles(const QStringList &p_files, bool p_forceOrphan = false); void openExternalFiles(const QStringList &p_files, bool p_forceOrphan = false);
// Try to open @p_filePath as internal note.
bool tryOpenInternalFile(const QString &p_filePath);
private slots: private slots:
void importNoteFromFile(); void importNoteFromFile();
void viewSettings(); void viewSettings();

View File

@ -2,18 +2,31 @@
#include <QDesktopServices> #include <QDesktopServices>
#include "vnote.h"
#include "vmainwindow.h"
extern VNote *g_vnote;
VPreviewPage::VPreviewPage(QWidget *parent) : QWebEnginePage(parent) VPreviewPage::VPreviewPage(QWidget *parent) : QWebEnginePage(parent)
{ {
} }
bool VPreviewPage::acceptNavigationRequest(const QUrl &url, bool VPreviewPage::acceptNavigationRequest(const QUrl &p_url,
QWebEnginePage::NavigationType /*type*/, QWebEnginePage::NavigationType p_type,
bool /*isMainFrame*/) bool p_isMainFrame)
{ {
// Only allow qrc:/index.html. Q_UNUSED(p_type);
if (url.scheme() == QString("qrc")) Q_UNUSED(p_isMainFrame);
return true;
QDesktopServices::openUrl(url); if (p_url.isLocalFile()) {
QString filePath = p_url.toLocalFile();
if (g_vnote->getMainWindow()->tryOpenInternalFile(filePath)) {
qDebug() << "internal notes jump" << filePath;
return false;
}
}
QDesktopServices::openUrl(p_url);
return false; return false;
} }

View File

@ -10,7 +10,9 @@ public:
explicit VPreviewPage(QWidget *parent = 0); explicit VPreviewPage(QWidget *parent = 0);
protected: protected:
bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame); bool acceptNavigationRequest(const QUrl &p_url,
NavigationType p_type,
bool p_isMainFrame);
}; };
#endif // VPREVIEWPAGE_H #endif // VPREVIEWPAGE_H