[latexila] LaTeX commands: port Environments submenu to GAction



commit dc9a2dde880b8efbea9d362af0136427bfc94223
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Oct 29 12:31:45 2017 +0100

    LaTeX commands: port Environments submenu to GAction

 src/latex_menu.vala                       |  135 ++++++++---------------------
 src/liblatexila/latexila-latex-commands.c |  107 +++++++++++++++++++++++
 2 files changed, 142 insertions(+), 100 deletions(-)
---
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index 43da952..2e69c73 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -65,27 +65,27 @@ public class LatexMenu : Gtk.ActionGroup
 
         { "Environments", "format-justify-center", "_Environments" },
         { "EnvCenter", "format-justify-center", "\\begin{_center}", null,
-            N_("Center - \\begin{center}"), on_env_center },
+            N_("Center - \\begin{center}") },
         { "EnvLeft", "format-justify-left", "\\begin{flush_left}", null,
-            N_("Align Left - \\begin{flushleft}"), on_env_left },
+            N_("Align Left - \\begin{flushleft}") },
         { "EnvRight", "format-justify-right", "\\begin{flush_right}", null,
-            N_("Align Right - \\begin{flushright}"), on_env_right },
+            N_("Align Right - \\begin{flushright}") },
         { "EnvFigure", "image-x-generic", "\\begin{_figure}", null,
-            N_("Figure - \\begin{figure}"), on_env_figure },
+            N_("Figure - \\begin{figure}") },
         { "EnvTable", "table", "\\begin{_table}", null,
-            N_("Table - \\begin{table}"), on_env_table },
+            N_("Table - \\begin{table}") },
         { "EnvQuote", null, "\\begin{_quote}", null,
-            N_("Quote - \\begin{quote}"), on_env_quote },
+            N_("Quote - \\begin{quote}") },
         { "EnvQuotation", null, "\\begin{qu_otation}", null,
-            N_("Quotation - \\begin{quotation}"), on_env_quotation },
+            N_("Quotation - \\begin{quotation}") },
         { "EnvVerse", null, "\\begin{_verse}", null,
-            N_("Verse - \\begin{verse}"), on_env_verse },
+            N_("Verse - \\begin{verse}") },
         { "EnvVerbatim", null, "\\begin{ver_batim}", null,
-            N_("Verbatim - \\begin{verbatim}"), on_env_verbatim },
+            N_("Verbatim - \\begin{verbatim}") },
         { "EnvMinipage", null, "\\begin{_minipage}", null,
-            N_("Minipage - \\begin{minipage}"), on_env_minipage },
+            N_("Minipage - \\begin{minipage}") },
         { "EnvTitlepage", null, "\\begin{titlepage}", null,
-            N_("Title page - \\begin{titlepage}"), on_env_titlepage },
+            N_("Title page - \\begin{titlepage}") },
 
         // LaTeX: list environments
 
@@ -485,6 +485,30 @@ public class LatexMenu : Gtk.ActionGroup
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::cite",
             this, "ReferencesCite");
 
+        // LaTeX: Environments
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::center",
+            this, "EnvCenter");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::flushleft",
+            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",
+            this, "EnvFigure");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-table",
+            this, "EnvTable");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::quote",
+            this, "EnvQuote");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::quotation",
+            this, "EnvQuotation");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::verse",
+            this, "EnvVerse");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::verbatim",
+            this, "EnvVerbatim");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::minipage",
+            this, "EnvMinipage");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::titlepage",
+            this, "EnvTitlepage");
+
         // LaTeX: character sizes
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::tiny",
             this, "CharacterSizeTiny");
@@ -610,95 +634,6 @@ public class LatexMenu : Gtk.ActionGroup
         return Latexila.view_get_indentation_style (main_window.active_view);
     }
 
-    /* Environments */
-
-    public void on_env_center ()
-    {
-        text_buffer_insert ("\\begin{center}\n", "\n\\end{center}");
-    }
-
-    public void on_env_left ()
-    {
-        text_buffer_insert ("\\begin{flushleft}\n", "\n\\end{flushleft}");
-    }
-
-    public void on_env_right ()
-    {
-        text_buffer_insert ("\\begin{flushright}\n", "\n\\end{flushright}");
-    }
-
-    public void on_env_figure ()
-    {
-        string indent = get_indentation ();
-
-        string before_cursor =
-            "\\begin{figure}\n" +
-            @"$indent\\begin{center}\n" +
-            @"$indent$indent\\includegraphics{";
-
-        string after_cursor =
-            "}\n" +
-            @"$indent$indent\\caption{}\n" +
-            @"$indent$indent\\label{fig:}\n" +
-            @"$indent\\end{center}\n" +
-            "\\end{figure}";
-
-        text_buffer_insert (before_cursor, after_cursor);
-    }
-
-    public void on_env_table ()
-    {
-        string indent = get_indentation ();
-
-        string before_cursor =
-            "\\begin{table}\n" +
-            @"$indent\\caption{";
-
-        string after_cursor =
-            "}\n" +
-            @"$indent\\label{tab:}\n" +
-            "\n" +
-            @"$indent\\begin{center}\n" +
-            @"$indent$indent\\begin{tabular}{cc}\n" +
-            @"$indent$indent$indent & \\\\\n" +
-            @"$indent$indent$indent & \\\\\n" +
-            @"$indent$indent\\end{tabular}\n" +
-            @"$indent\\end{center}\n" +
-            "\\end{table}";
-
-        text_buffer_insert (before_cursor, after_cursor);
-    }
-
-    public void on_env_quote ()
-    {
-        text_buffer_insert ("\\begin{quote}\n", "\n\\end{quote}");
-    }
-
-    public void on_env_quotation ()
-    {
-        text_buffer_insert ("\\begin{quotation}\n", "\n\\end{quotation}");
-    }
-
-    public void on_env_verse ()
-    {
-        text_buffer_insert ("\\begin{verse}\n", "\n\\end{verse}");
-    }
-
-    public void on_env_verbatim ()
-    {
-        text_buffer_insert ("\\begin{verbatim}\n", "\n\\end{verbatim}");
-    }
-
-    public void on_env_minipage ()
-    {
-        text_buffer_insert ("\\begin{minipage}\n", "\n\\end{minipage}");
-    }
-
-    public void on_env_titlepage ()
-    {
-        text_buffer_insert ("\\begin{titlepage}\n", "\n\\end{titlepage}");
-    }
-
     /* List Environments */
 
     public void on_list_env_itemize ()
diff --git a/src/liblatexila/latexila-latex-commands.c b/src/liblatexila/latexila-latex-commands.c
index 3c44fd6..637cdcd 100644
--- a/src/liblatexila/latexila-latex-commands.c
+++ b/src/liblatexila/latexila-latex-commands.c
@@ -25,6 +25,7 @@
 
 #include "latexila-latex-commands.h"
 #include "latexila-utils.h"
+#include "latexila-view.h"
 
 /* Temporarily public, will be made private when all GActions for the LaTeX and
  * Math menus are implemented.
@@ -142,6 +143,109 @@ latex_command_with_braces_cb (GSimpleAction *action,
 }
 
 static void
+latex_command_env_simple_cb (GSimpleAction *action,
+                             GVariant      *parameter,
+                             gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+  const gchar *environment;
+  gchar *text_before;
+  gchar *text_after;
+
+  environment = g_variant_get_string (parameter, NULL);
+  text_before = g_strdup_printf ("\\begin{%s}\n", environment);
+  text_after = g_strdup_printf ("\n\\end{%s}", environment);
+
+  latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+
+  g_free (text_before);
+  g_free (text_after);
+}
+
+static void
+latex_command_env_figure_cb (GSimpleAction *action,
+                             GVariant      *parameter,
+                             gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+  TeplView *view;
+  gchar *indent;
+  gchar *text_before;
+  gchar *text_after;
+
+  view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+  g_return_if_fail (view != NULL);
+
+  indent = latexila_view_get_indentation_style (GTK_SOURCE_VIEW (view));
+
+  text_before = g_strdup_printf ("\\begin{figure}\n"
+                                 "%s\\begin{center}\n"
+                                 "%s%s\\includegraphics{",
+                                 indent,
+                                 indent, indent);
+
+  text_after = g_strdup_printf ("}\n"
+                                "%s%s\\caption{}\n"
+                                "%s%s\\label{fig:}\n"
+                                "%s\\end{center}\n"
+                                "\\end{figure}",
+                                indent, indent,
+                                indent, indent,
+                                indent);
+
+  latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+
+  g_free (indent);
+  g_free (text_before);
+  g_free (text_after);
+}
+
+static void
+latex_command_env_table_cb (GSimpleAction *action,
+                            GVariant      *parameter,
+                            gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+  TeplView *view;
+  gchar *indent;
+  gchar *text_before;
+  gchar *text_after;
+
+  view = tepl_tab_group_get_active_view (TEPL_TAB_GROUP (tepl_window));
+  g_return_if_fail (view != NULL);
+
+  indent = latexila_view_get_indentation_style (GTK_SOURCE_VIEW (view));
+
+  text_before = g_strdup_printf ("\\begin{table}\n"
+                                 "%s\\caption{",
+                                 indent);
+
+  text_after = g_strdup_printf ("}\n"
+                                "%s\\label{tab:}\n"
+                                "\n"
+                                "%s\\begin{center}\n"
+                                "%s%s\\begin{tabular}{cc}\n"
+                                "%s%s%s & \\\\\n"
+                                "%s%s%s & \\\\\n"
+                                "%s%s\\end{tabular}\n"
+                                "%s\\end{center}\n"
+                                "\\end{table}",
+                                indent,
+                                indent,
+                                indent, indent,
+                                indent, indent, indent,
+                                indent, indent, indent,
+                                indent, indent,
+                                indent);
+
+  latexila_latex_commands_insert_text (tepl_window, text_before, text_after, NULL);
+
+  g_free (indent);
+  g_free (text_before);
+  g_free (text_after);
+}
+
+static void
 latex_command_char_style_cb (GSimpleAction *action,
                              GVariant      *parameter,
                              gpointer       user_data)
@@ -197,6 +301,9 @@ latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
 
   const GActionEntry entries[] = {
     { "latex-command-with-braces", latex_command_with_braces_cb, "s" },
+    { "latex-command-env-simple", latex_command_env_simple_cb, "s" },
+    { "latex-command-env-figure", latex_command_env_figure_cb },
+    { "latex-command-env-table", latex_command_env_table_cb },
     { "latex-command-char-style", latex_command_char_style_cb, "s" },
   };
 


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