[latexila] LaTeX commands: don't add AmtkActionInfo's for each window



commit cafd0894a616e60ee012d7b600df7eba16146441
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Dec 14 17:18:20 2017 +0100

    LaTeX commands: don't add AmtkActionInfo's for each window
    
    The GAction's are created for each main window, but the AmtkActionInfo's
    are for the whole application.

 docs/reference/latexila-sections.txt      |    3 +-
 src/latex_menu.vala                       |    2 +-
 src/latexila_app.vala                     |    1 +
 src/liblatexila/latexila-latex-commands.c |   85 +++++++++++++++--------------
 src/liblatexila/latexila-latex-commands.h |    4 +-
 5 files changed, 51 insertions(+), 44 deletions(-)
---
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index 9cbfe67..b9500e6 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -132,7 +132,8 @@ latexila_build_view_get_type
 
 <SECTION>
 <FILE>latex-commands</FILE>
-latexila_latex_commands_init
+latexila_latex_commands_add_action_infos
+latexila_latex_commands_add_actions
 latexila_latex_commands_insert_text
 </SECTION>
 
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index 563092e..cb2c59a 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -443,7 +443,7 @@ public class LatexMenu : Gtk.ActionGroup
 
         /* GActions */
 
-        Latexila.latex_commands_init (main_window);
+        Latexila.latex_commands_add_actions (main_window);
 
         // LaTeX: Sectioning
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::part",
diff --git a/src/latexila_app.vala b/src/latexila_app.vala
index 92801ef..822f73a 100644
--- a/src/latexila_app.vala
+++ b/src/latexila_app.vala
@@ -119,6 +119,7 @@ public class LatexilaApp : Gtk.Application
         hold ();
 
         add_action_entries (_app_actions, this);
+        Latexila.latex_commands_add_action_infos (this);
 
         GLib.MenuModel manual_app_menu = get_menu_by_id ("manual-app-menu");
         if (manual_app_menu == null)
diff --git a/src/liblatexila/latexila-latex-commands.c b/src/liblatexila/latexila-latex-commands.c
index 7b0138d..287d292 100644
--- a/src/liblatexila/latexila-latex-commands.c
+++ b/src/liblatexila/latexila-latex-commands.c
@@ -29,6 +29,39 @@
 #include "latexila-utils.h"
 #include "latexila-view.h"
 
+/**
+ * latexila_latex_commands_add_action_infos:
+ * @gtk_app: the #GtkApplication instance.
+ *
+ * Creates the #AmtkActionInfo's related to the LaTeX and Math menus, and add
+ * them to the #AmtkActionInfoStore as returned by
+ * tepl_application_get_app_action_info_store().
+ */
+void
+latexila_latex_commands_add_action_infos (GtkApplication *gtk_app)
+{
+  TeplApplication *tepl_app;
+  AmtkActionInfoStore *store;
+
+  const AmtkActionInfoEntry entries[] =
+  {
+    /* action, icon, label, accel, tooltip */
+
+    { "win.latex-command-env-figure", "image-x-generic", "\\begin{_figure}", NULL,
+      N_("Figure - \\begin{figure}") },
+  };
+
+  g_return_if_fail (GTK_IS_APPLICATION (gtk_app));
+
+  tepl_app = tepl_application_get_from_gtk_application (gtk_app);
+  store = tepl_application_get_app_action_info_store (tepl_app);
+
+  amtk_action_info_store_add_entries (store,
+                                      entries,
+                                      G_N_ELEMENTS (entries),
+                                      GETTEXT_PACKAGE);
+}
+
 /* Util functions */
 
 /* Temporarily public, will be made private when all GActions for the LaTeX and
@@ -667,8 +700,15 @@ math_command_misc_nth_root_cb (GSimpleAction *action,
   latexila_latex_commands_insert_text (tepl_window, "\\sqrt[]{", "}", NULL);
 }
 
-static void
-add_actions (GtkApplicationWindow *gtk_window)
+/**
+ * latexila_latex_commands_add_actions:
+ * @gtk_window: a #GtkApplicationWindow.
+ *
+ * Creates the #GAction's related to the LaTeX and Math menus, and add them to
+ * @gtk_window.
+ */
+void
+latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
 {
   TeplApplicationWindow *tepl_window;
 
@@ -701,6 +741,8 @@ add_actions (GtkApplicationWindow *gtk_window)
     { "math-command-misc-nth-root", math_command_misc_nth_root_cb },
   };
 
+  g_return_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window));
+
   tepl_window = tepl_application_window_get_from_gtk_application_window (gtk_window);
 
   amtk_action_map_add_action_entries_check_dups (G_ACTION_MAP (gtk_window),
@@ -708,42 +750,3 @@ add_actions (GtkApplicationWindow *gtk_window)
                                                  G_N_ELEMENTS (entries),
                                                  tepl_window);
 }
-
-static void
-add_action_info_entries (void)
-{
-  TeplApplication *tepl_app;
-  AmtkActionInfoStore *store;
-
-  const AmtkActionInfoEntry entries[] =
-  {
-    /* action, icon, label, accel, tooltip */
-
-    { "win.latex-command-env-figure", "image-x-generic", "\\begin{_figure}", NULL,
-      N_("Figure - \\begin{figure}") },
-  };
-
-  tepl_app = tepl_application_get_default ();
-  store = tepl_application_get_app_action_info_store (tepl_app);
-
-  amtk_action_info_store_add_entries (store,
-                                      entries,
-                                      G_N_ELEMENTS (entries),
-                                      GETTEXT_PACKAGE);
-}
-
-/**
- * latexila_latex_commands_init:
- * @gtk_window: a #GtkApplicationWindow.
- *
- * Creates the #GAction's and #AmtkActionInfo's related to the LaTeX and Math
- * menus.
- */
-void
-latexila_latex_commands_init (GtkApplicationWindow *gtk_window)
-{
-  g_return_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window));
-
-  add_actions (gtk_window);
-  add_action_info_entries ();
-}
diff --git a/src/liblatexila/latexila-latex-commands.h b/src/liblatexila/latexila-latex-commands.h
index 8f0c206..bc1d44e 100644
--- a/src/liblatexila/latexila-latex-commands.h
+++ b/src/liblatexila/latexila-latex-commands.h
@@ -24,7 +24,9 @@
 
 G_BEGIN_DECLS
 
-void      latexila_latex_commands_init              (GtkApplicationWindow *gtk_window);
+void      latexila_latex_commands_add_action_infos  (GtkApplication *gtk_app);
+
+void      latexila_latex_commands_add_actions       (GtkApplicationWindow *gtk_window);
 
 void      latexila_latex_commands_insert_text       (TeplApplicationWindow *tepl_window,
                                                      const gchar           *text_before,


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