[latexila] LaTeX commands: port Math misc commands to GAction



commit 7d19cd9ef0d144a830c8f48ae7a42c2432bdfb9b
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Nov 24 20:28:23 2017 +0100

    LaTeX commands: port Math misc commands to GAction

 src/latex_menu.vala                       |   51 +++++++++++------------------
 src/liblatexila/latexila-latex-commands.c |   44 +++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 32 deletions(-)
---
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index 8923308..cda4cea 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -272,16 +272,18 @@ public class LatexMenu : Gtk.ActionGroup
             N_("Numbered Array of _Equations - \\begin{align}"), null,
             N_("Numbered Array of Equations - \\begin{align}") },
 
+        // Math misc
+
         { "MathSuperscript", "math-superscript", N_("_Superscript - ^{}"), null,
-            N_("Superscript - ^{}"), on_math_superscript },
+            N_("Superscript - ^{}") },
         { "MathSubscript", "math-subscript", N_("Su_bscript - __{}"), null,
-            N_("Subscript - _{}"), on_math_subscript },
+            N_("Subscript - _{}") },
         { "MathFrac", "math-frac", N_("_Fraction - \\frac{}{}"), "<Alt><Shift>F",
-            N_("Fraction - \\frac{}{}"), on_math_frac },
+            N_("Fraction - \\frac{}{}") },
         { "MathSquareRoot", "math-square-root", N_("Square _Root - \\sqrt{}"), null,
-            N_("Square Root - \\sqrt{}"), on_math_square_root },
+            N_("Square Root - \\sqrt{}") },
         { "MathNthRoot", "math-nth-root", N_("_N-th Root - \\sqrt[]{}"), null,
-            N_("N-th Root - \\sqrt[]{}"), on_math_nth_root },
+            N_("N-th Root - \\sqrt[]{}") },
 
         // Math functions
 
@@ -691,6 +693,18 @@ public class LatexMenu : Gtk.ActionGroup
             this, "MathEnvArray");
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::align",
             this, "MathEnvNumberedArray");
+
+        // Math misc
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "math-command-misc-superscript",
+            this, "MathSuperscript");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "math-command-misc-subscript",
+            this, "MathSubscript");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "math-command-misc-frac",
+            this, "MathFrac");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::sqrt",
+            this, "MathSquareRoot");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "math-command-misc-nth-root",
+            this, "MathNthRoot");
     }
 
     private Gtk.Action get_menu_tool_action (string name, string? label, string? icon_name)
@@ -711,33 +725,6 @@ public class LatexMenu : Gtk.ActionGroup
             text_if_no_selection);
     }
 
-    /* Math environments */
-
-    public void on_math_superscript ()
-    {
-        text_buffer_insert ("^{", "}");
-    }
-
-    public void on_math_subscript ()
-    {
-        text_buffer_insert ("_{", "}");
-    }
-
-    public void on_math_frac ()
-    {
-        text_buffer_insert ("\\frac{", "}{}");
-    }
-
-    public void on_math_square_root ()
-    {
-        text_buffer_insert ("\\sqrt{", "}");
-    }
-
-    public void on_math_nth_root ()
-    {
-        text_buffer_insert ("\\sqrt[]{", "}");
-    }
-
     /* Math Functions */
 
     public void on_math_func_arccos ()
diff --git a/src/liblatexila/latexila-latex-commands.c b/src/liblatexila/latexila-latex-commands.c
index 0e14f7a..47dc9dd 100644
--- a/src/liblatexila/latexila-latex-commands.c
+++ b/src/liblatexila/latexila-latex-commands.c
@@ -625,6 +625,46 @@ math_command_env_array_cb (GSimpleAction *action,
                                        NULL);
 }
 
+static void
+math_command_misc_superscript_cb (GSimpleAction *action,
+                                  GVariant      *parameter,
+                                  gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+
+  latexila_latex_commands_insert_text (tepl_window, "^{", "}", NULL);
+}
+
+static void
+math_command_misc_subscript_cb (GSimpleAction *action,
+                                GVariant      *parameter,
+                                gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+
+  latexila_latex_commands_insert_text (tepl_window, "_{", "}", NULL);
+}
+
+static void
+math_command_misc_frac_cb (GSimpleAction *action,
+                           GVariant      *parameter,
+                           gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+
+  latexila_latex_commands_insert_text (tepl_window, "\\frac{", "}{}", NULL);
+}
+
+static void
+math_command_misc_nth_root_cb (GSimpleAction *action,
+                               GVariant      *parameter,
+                               gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+
+  latexila_latex_commands_insert_text (tepl_window, "\\sqrt[]{", "}", NULL);
+}
+
 /**
  * latexila_latex_commands_add_actions:
  * @gtk_window: a #GtkApplicationWindow.
@@ -659,6 +699,10 @@ latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
     { "math-command-env-normal", math_command_env_normal_cb },
     { "math-command-env-centered", math_command_env_centered_cb },
     { "math-command-env-array", math_command_env_array_cb },
+    { "math-command-misc-superscript", math_command_misc_superscript_cb },
+    { "math-command-misc-subscript", math_command_misc_subscript_cb },
+    { "math-command-misc-frac", math_command_misc_frac_cb },
+    { "math-command-misc-nth-root", math_command_misc_nth_root_cb },
   };
 
   g_return_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window));


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