Przeglądaj źródła

support links to internal notes

Le Tan 8 lat temu
rodzic
commit
b5646a2b34
4 zmienionych plików z 44 dodań i 8 usunięć
  1. 18 0
      src/vmainwindow.cpp
  2. 3 0
      src/vmainwindow.h
  3. 20 7
      src/vpreviewpage.cpp
  4. 3 1
      src/vpreviewpage.h

+ 18 - 0
src/vmainwindow.cpp

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

+ 3 - 0
src/vmainwindow.h

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

+ 20 - 7
src/vpreviewpage.cpp

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

+ 3 - 1
src/vpreviewpage.h

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