mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support links to internal notes
This commit is contained in:
parent
2e7590de24
commit
b5646a2b34
@ -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)
|
||||
{
|
||||
qDebug() << "open external files" << p_files;
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
// 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);
|
||||
|
||||
// Try to open @p_filePath as internal note.
|
||||
bool tryOpenInternalFile(const QString &p_filePath);
|
||||
|
||||
private slots:
|
||||
void importNoteFromFile();
|
||||
void viewSettings();
|
||||
|
@ -2,18 +2,31 @@
|
||||
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "vnote.h"
|
||||
#include "vmainwindow.h"
|
||||
|
||||
extern VNote *g_vnote;
|
||||
|
||||
VPreviewPage::VPreviewPage(QWidget *parent) : QWebEnginePage(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool VPreviewPage::acceptNavigationRequest(const QUrl &url,
|
||||
QWebEnginePage::NavigationType /*type*/,
|
||||
bool /*isMainFrame*/)
|
||||
bool VPreviewPage::acceptNavigationRequest(const QUrl &p_url,
|
||||
QWebEnginePage::NavigationType p_type,
|
||||
bool p_isMainFrame)
|
||||
{
|
||||
// Only allow qrc:/index.html.
|
||||
if (url.scheme() == QString("qrc"))
|
||||
return true;
|
||||
QDesktopServices::openUrl(url);
|
||||
Q_UNUSED(p_type);
|
||||
Q_UNUSED(p_isMainFrame);
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ public:
|
||||
explicit VPreviewPage(QWidget *parent = 0);
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user