[latexila] LaTeX commands: add first AmtkActionInfo and create GtkAction from it



commit ad199c72316acdd9bef5c5562bcd9f9c6421a18c
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Nov 29 15:40:12 2017 +0100

    LaTeX commands: add first AmtkActionInfo and create GtkAction from it
    
    This is a proof of concept, all the other GtkActionEntry's will need to
    be ported to AmtkActionInfoEntry's. This will permit to create the Edit
    toolbar with Amtk, without duplicating the action infos, while still
    using GtkUIManager to create the menu.

 docs/reference/latexila-sections.txt      |    2 +-
 src/latex_menu.vala                       |    6 +--
 src/liblatexila/latexila-latex-commands.c |   53 +++++++++++++++++++++++-----
 src/liblatexila/latexila-latex-commands.h |    2 +-
 4 files changed, 47 insertions(+), 16 deletions(-)
---
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index ccf6767..90e135a 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -132,7 +132,7 @@ latexila_build_view_get_type
 
 <SECTION>
 <FILE>latex-commands</FILE>
-latexila_latex_commands_add_actions
+latexila_latex_commands_init
 latexila_latex_commands_insert_text
 </SECTION>
 
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index 8ac7af8..e78f07c 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -70,8 +70,6 @@ public class LatexMenu : Gtk.ActionGroup
             N_("Align Left - \\begin{flushleft}") },
         { "EnvRight", "format-justify-right", "\\begin{flush_right}", null,
             N_("Align Right - \\begin{flushright}") },
-        { "EnvFigure", "image-x-generic", "\\begin{_figure}", null,
-            N_("Figure - \\begin{figure}") },
         { "EnvTable", "table", "\\begin{_table}", null,
             N_("Table - \\begin{table}") },
         { "EnvQuote", null, "\\begin{_quote}", null,
@@ -453,7 +451,7 @@ public class LatexMenu : Gtk.ActionGroup
 
         /* GActions */
 
-        Latexila.latex_commands_add_actions (main_window);
+        Latexila.latex_commands_init (main_window);
 
         // LaTeX: Sectioning
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::part",
@@ -492,7 +490,7 @@ public class LatexMenu : Gtk.ActionGroup
             this, "EnvLeft");
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::flushright",
             this, "EnvRight");
-        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-figure",
+        Amtk.utils_create_gtk_action (main_window, "win.latex-command-env-figure",
             this, "EnvFigure");
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-table",
             this, "EnvTable");
diff --git a/src/liblatexila/latexila-latex-commands.c b/src/liblatexila/latexila-latex-commands.c
index 47dc9dd..7b0138d 100644
--- a/src/liblatexila/latexila-latex-commands.c
+++ b/src/liblatexila/latexila-latex-commands.c
@@ -23,7 +23,9 @@
  * @short_description: LaTeX menu, Math menu and Edit toolbar
  */
 
+#include "config.h"
 #include "latexila-latex-commands.h"
+#include <glib/gi18n.h>
 #include "latexila-utils.h"
 #include "latexila-view.h"
 
@@ -665,14 +667,8 @@ math_command_misc_nth_root_cb (GSimpleAction *action,
   latexila_latex_commands_insert_text (tepl_window, "\\sqrt[]{", "}", NULL);
 }
 
-/**
- * latexila_latex_commands_add_actions:
- * @gtk_window: a #GtkApplicationWindow.
- *
- * Adds the #GAction's related to the LaTeX and Math menus.
- */
-void
-latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
+static void
+add_actions (GtkApplicationWindow *gtk_window)
 {
   TeplApplicationWindow *tepl_window;
 
@@ -705,8 +701,6 @@ latexila_latex_commands_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),
@@ -714,3 +708,42 @@ latexila_latex_commands_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 d44ca04..8f0c206 100644
--- a/src/liblatexila/latexila-latex-commands.h
+++ b/src/liblatexila/latexila-latex-commands.h
@@ -24,7 +24,7 @@
 
 G_BEGIN_DECLS
 
-void      latexila_latex_commands_add_actions       (GtkApplicationWindow *gtk_window);
+void      latexila_latex_commands_init              (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]