mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19: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)
|
void VMainWindow::openExternalFiles(const QStringList &p_files, bool p_forceOrphan)
|
||||||
{
|
{
|
||||||
qDebug() << "open external files" << p_files;
|
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.
|
// 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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user