texinfo-commits
[Top][All Lists]
Advanced

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

[no subject]


From: Gavin D. Smith
Date: Wed, 30 Nov 2022 13:36:23 -0500 (EST)

branch: old/qt-info
commit c07a5b6b6e66538f94cc4e263a2c6b91909f87fc
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Apr 7 13:26:51 2019 +0100

    Preparation for integration with a new help browser with Qt.
    
    * js/Makefile.am: Build the examples with an empty htmlxref file
    in order to produce relative links in the output.
    * js/info.js (init): New function, to connect to a QWebChannel.
    (web_channel_override): New function, to override action
    handling.
    (core): New object to represent communication channel with a
    controlling Qt/C++ process.
    
    (actions) <external_manual>: New action.
    (updater) <external-manual>: Handle.
    (on_click): Dispatch an "external-manual" action.
    (web_channel_override) <external-manual>: Send into core object.
---
 ChangeLog         |  18 +++++++++
 js/Makefile.am    |   4 +-
 js/empty_htmlxref |   0
 js/info.js        | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 131 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 825f9680b5..3bcd702f08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2019-04-07  Gavin Smith  <gavinsmith0123@gmail.com>
+
+       Preparation for integration with a new help browser with Qt.
+
+       * js/Makefile.am: Build the examples with an empty htmlxref file 
+       in order to produce relative links in the output.
+       * js/info.js (init): New function, to connect to a QWebChannel.
+       (web_channel_override): New function, to override action 
+       handling.
+       (core): New object to represent communication channel with a 
+       controlling Qt/C++ process.
+
+       (actions) <external_manual>: New action.
+       (updater) <external-manual>: Handle.
+       (on_click): Dispatch an "external-manual" action.
+       (web_channel_override) <external-manual>: Send into core object.
+
+
 2019-04-06  Gavin Smith  <gavinsmith0123@gmail.com>
 
        * doc/texinfo.tex (\printindex): Give an error message with 
diff --git a/js/Makefile.am b/js/Makefile.am
index a94cf05794..68b0d98bf2 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -96,10 +96,11 @@ EXTRA_DIST += $(examples_src)
 
 hello_extra_head = '<link rel="stylesheet" type="text/css" 
href="info.css"/><script src="modernizr.js" 
type="text/javascript"></script><script src="info.js" 
type="text/javascript"></script>'
 
-examples/hello-html: examples/hello/hello.texi examples
+examples/hello-html: examples/hello/hello.texi
        mkdir -p examples
        $(MAKEINFO) -I=$(srcdir) --html \
          -c EXTRA_HEAD=$(hello_extra_head) \
+         -c HTMLXREF=$(srcdir)/empty_htmlxref \
          $(srcdir)/examples/hello/hello.texi -o $@ && \
        for f in $(js_scripts) info.css ; do \
          cp $(srcdir)/$$f $@ ; \
@@ -111,6 +112,7 @@ examples/kawa-html: examples/kawa/kawa.texi
        mkdir -p examples
        $(MAKEINFO) -I=$(srcdir) --html \
          -c EXTRA_HEAD=$(kawa_extra_head) \
+         -c HTMLXREF=$(srcdir)/empty_htmlxref \
          $(srcdir)/examples/kawa/kawa.texi -o $@ && \
        for f in $(js_scripts) info.css kawa.css ; do \
          cp $(srcdir)/$$f $@ ; \
diff --git a/js/empty_htmlxref b/js/empty_htmlxref
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/js/info.js b/js/info.js
index 035417b6d5..1806527a84 100644
--- a/js/info.js
+++ b/js/info.js
@@ -119,6 +119,10 @@
       return { type: "current-url", pointer: pointer, history: "pushState" };
     },
 
+    external_manual: function (linkid, history) {
+      return { type: "external-manual", url: linkid };
+    },
+
     /** @arg {string} dir */
     navigate: function (dir) {
       return { type: "navigate", direction: dir, history: "pushState" };
@@ -228,6 +232,13 @@
           res.loaded_nodes[linkid] = res.loaded_nodes[linkid] || {};
           return res;
         }
+      case "external-manual":
+        {
+          // This is expected to replace the entire page, therefore the
+          // following return statement shouldn't run.
+          window.location.href = action.url;
+          return res;
+        }
       case "unfocus":
         {
           if (!res.focus)
@@ -1367,14 +1378,23 @@
         if ((target instanceof Element) && target.matches ("a"))
           {
             var href = target.getAttribute ("href");
-            if (href && !absolute_url_p (href)
-                  && !external_manual_url_p (href))
-              {
-                var linkid = href_hash (href) || config.INDEX_ID;
-                store.dispatch (actions.set_current_url (linkid));
-                event.preventDefault ();
-                event.stopPropagation ();
-                return;
+            if (href)
+             {
+                if (external_manual_url_p (href))
+                  {
+                    store.dispatch (actions.external_manual (href));
+                    event.preventDefault ();
+                    event.stopPropagation ();
+                    return;
+                  }
+                else if (!absolute_url_p (href))
+                  {
+                    var linkid = href_hash (href) || config.INDEX_ID;
+                    store.dispatch (actions.set_current_url (linkid));
+                    event.preventDefault ();
+                    event.stopPropagation ();
+                    return;
+                  }
               }
           }
       }
@@ -2007,4 +2027,86 @@
      doesn't handle the 'Escape' key properly.  See
      https://bugs.chromium.org/p/chromium/issues/detail?id=9061.  */
   window.addEventListener ("keyup", on_keyup, false);
+
+
+/*----------------------------------.
+| For communication with Qt process |
+`----------------------------------*/
+
+// object shared with controlling Qt/C++ process
+var core;
+
+// For use with QWebChannel.  init function to be called after
+// qwebchannel.js has been loaded.
+init = function ()
+{
+  if (!inside_index_page)
+    return;
+
+  if (location.search != "")
+    var baseUrl
+      = 
(/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
+  else
+    var baseUrl = "ws://localhost:12345";
+
+  var socket = new WebSocket(baseUrl);
+
+  socket.onclose = function()
+    {
+      console.error("web channel closed");
+    };
+
+  socket.onerror = function(error)
+    {
+      console.error("web channel error: " + error);
+    };
+
+  socket.onopen = function()
+    {
+      new QWebChannel(socket, function(channel)
+        {
+          window.core = channel.objects.core;
+
+          // receive signals from Qt/C++ side
+          // should we inject this code?
+
+          channel.objects.core.setUrl.connect(function(url) {
+            alert("asked to go to " + url);
+          });
+        });
+    };
+
+  var store_dispatch = Store.prototype.dispatch;
+  Store.prototype.dispatch = function (action)
+    {
+      if (!web_channel_override (this, action))
+        store_dispatch.call (this, action);
+    };
+  // Overriding just the dispatch function works better than
+  // assigining 'store' to a different object, as store.state
+  // is used as well.
+}
+
 } (window["Modernizr"], window["INFO_CONFIG"]));
+
+// Make init function visible at external scope
+var init;
+
+// Return true if the standard function doesn't need to be called.
+// This is put in the external scope because we might want to inject
+// this function in the future from Qt/C++.
+function web_channel_override (store, action)
+{
+  switch (action.type)
+    {
+    case "external-manual":
+      {
+        window.core.external_manual (action.url);
+        return 1;
+      }
+    default:
+      {
+        return 0;
+      }
+    }
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]