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: Sun, 20 Mar 2022 04:55:27 -0400 (EDT)

branch: master
commit 431e679bdf41100e98ef6cb7c3cd2ae424021c63
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Oct 27 18:16:32 2019 +0000

    update TOC selection upon node change
---
 js/infog/extension.c |  5 +++++
 js/infog/main.c      | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/js/infog/extension.c b/js/infog/extension.c
index 50f6b64bbc..1ec84f610c 100644
--- a/js/infog/extension.c
+++ b/js/infog/extension.c
@@ -146,6 +146,11 @@ request_callback (WebKitWebPage     *web_page,
           if (!load_manual (manual))
             ;// return TRUE; /* Cancel load request */
         }
+      GString *s = g_string_new (NULL);
+      g_string_append (s, "new-node\n");
+      g_string_append (s, node);
+      send_datagram (s);
+      g_string_free (s, TRUE);
     }
 
   return FALSE;
diff --git a/js/infog/main.c b/js/infog/main.c
index 77540ed543..085879f286 100644
--- a/js/infog/main.c
+++ b/js/infog/main.c
@@ -75,8 +75,14 @@ enum { COLUMN_TEXT, COLUMN_URL, COLUMN_CHILD_FULL };
 GtkTreeView *toc_pane;
 GtkTreeSelection *toc_selection = 0;
 GtkWidget *toc_scroll = 0;
-GtkWidget *toc_revealer = 0;
 GtkPaned *paned;
+GTree *toc_paths = 0;
+
+gint
+toc_cmp (const void *a, const void *b, void *ignored)
+{
+  return strcmp ((char *)a, (char *)b);
+}
 
 gboolean indices_loaded = FALSE;
 WebKitWebView *hiddenWebView = NULL;
@@ -260,6 +266,9 @@ load_toc (char *p)
 {
   int last;
 
+  if (!toc_paths)
+    toc_paths = g_tree_new_full (toc_cmp, NULL, free, free);
+
   if (!toc_store)
     {
       toc_store = gtk_tree_store_new (3, G_TYPE_STRING, G_TYPE_STRING,
@@ -322,6 +331,18 @@ load_toc (char *p)
                           COLUMN_TEXT, p,
                           COLUMN_URL, q,
                           COLUMN_CHILD_FULL, FALSE, -1);
+
+      GtkTreeIter *saved_iter = malloc (sizeof (last_iter));
+      *saved_iter = last_iter;
+
+      /* Strip off file extension. */
+      char *node = strdup (q);
+      char *dot = strchr (node, '.');
+      if (dot)
+        *dot = '\0';
+
+      g_tree_insert (toc_paths, node, saved_iter);
+
       toc_empty = 0;
 
       if (last)
@@ -418,6 +439,11 @@ new_manual (char *manual)
          so toc_selected_cb runs and loads all the nodes in the old 
          manual.  */
     }
+  if (toc_paths)
+    {
+      g_tree_destroy (toc_paths);
+      toc_paths = 0;
+    }
   return 1;
 }
 
@@ -500,6 +526,31 @@ socket_cb (GSocket *socket,
           webkit_web_view_load_uri (hiddenWebView, s->str);
           g_string_free (s, TRUE);
         }
+      else if (!strcmp (buffer, "new-node"))
+        {
+          p++;
+          GtkTreeIter *iter = g_tree_lookup (toc_paths, p);
+          if (iter)
+            {
+              char *path = gtk_tree_model_get_string_from_iter
+                             (GTK_TREE_MODEL(toc_store), iter);
+              if (path)
+                {
+                  GtkTreePath *path2 = gtk_tree_path_new_from_string (path);
+                  GtkTreePath *parent = gtk_tree_path_copy (path2);
+
+                  if (gtk_tree_path_up (parent))
+                    gtk_tree_view_expand_to_path (toc_pane, parent);
+
+                  gtk_tree_selection_select_path (toc_selection, path2);
+                  gtk_tree_view_scroll_to_cell (toc_pane, path2,
+                                                NULL, TRUE, 0.5, 0);
+                  gtk_tree_path_free (path2);
+                  gtk_tree_path_free (parent);
+                  free (path);
+                }
+            }
+        }
       else if (!strcmp (buffer, "toc"))
         {
           p++;



reply via email to

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