[gnome-builder] html-preview: disable navigating away from preview



commit 6bb2491bd511acb4dc2c91e0dddff9d4bde07c84
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 17 14:14:19 2019 -0800

    html-preview: disable navigating away from preview
    
    This is a rudimentary hack to avoid navigating away from the current page
    while also allowing loading the external resources we need.
    
    Related to #760

 src/plugins/html-preview/html_preview.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/src/plugins/html-preview/html_preview.py b/src/plugins/html-preview/html_preview.py
index af0a5a4ac..b4da8d056 100644
--- a/src/plugins/html-preview/html_preview.py
+++ b/src/plugins/html-preview/html_preview.py
@@ -374,6 +374,7 @@ class HtmlPreviewPage(Ide.Page):
 
         self.webview = WebKit2.WebView()
         self.webview.props.expand = True
+        self.webview.connect('decide-policy', self.on_decide_policy_cb)
         self.add(self.webview)
         self.webview.show()
 
@@ -395,6 +396,25 @@ class HtmlPreviewPage(Ide.Page):
         self.on_changed(document)
         self.on_title_changed(document)
 
+    def on_decide_policy_cb(self, webview, decision, decision_type):
+        """Handle policy decisions from webview"""
+
+        if decision_type == WebKit2.PolicyDecisionType.NAVIGATION_ACTION:
+            # Don't allow navigating away from the current page
+
+            action = decision.get_navigation_action()
+            request = action.get_request()
+            uri = request.get_uri()
+
+            # print(">>> URI = ", uri)
+
+            if uri != self.document.get_file().get_uri() \
+            and 'gnome-builder-sphinx' not in uri:
+                decision.ignore()
+                return True
+
+        return False
+
     def on_title_changed(self, buffer):
         self.set_title("%s %s" % (buffer.dup_title(), _("(Preview)")))
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]