[latexila] LaTeX commands: add latex-command-char-style GAction



commit d156aef52c8410a0a3582f769c22e75b7e2b4cf8
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Oct 25 18:25:30 2017 +0200

    LaTeX commands: add latex-command-char-style GAction

 src/latex_menu.vala                       |   86 ++++++++++-------------------
 src/liblatexila/latexila-latex-commands.c |   44 +++++++++++++++
 2 files changed, 74 insertions(+), 56 deletions(-)
---
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index c64a576..752f98e 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -147,27 +147,27 @@ public class LatexMenu : Gtk.ActionGroup
 
         { "FontFamily", null, N_("_Font Family") },
         { "FontFamilyRoman", "roman", "\\_rmfamily", null,
-            N_("Roman - \\rmfamily"), on_text_font_family_roman },
+            N_("Roman - \\rmfamily") },
         { "FontFamilySansSerif", "sans_serif", "\\_sffamily", null,
-            N_("Sans Serif - \\sffamily"), on_text_font_family_sans_serif },
+            N_("Sans Serif - \\sffamily") },
         { "FontFamilyMonospace", "typewriter", "\\_ttfamily", null,
-            N_("Monospace - \\ttfamily"), on_text_font_family_monospace },
+            N_("Monospace - \\ttfamily") },
 
         { "FontSeries", null, N_("F_ont Series") },
         { "FontSeriesMedium", "roman", "\\_mdseries", null,
-            N_("Medium - \\mdseries"), on_text_font_series_medium },
+            N_("Medium - \\mdseries") },
         { "FontSeriesBold", "bold", "\\_bfseries", null,
-            N_("Bold - \\bfseries"), on_text_font_series_bold },
+            N_("Bold - \\bfseries") },
 
         { "FontShape", null, N_("Fo_nt Shape") },
         { "FontShapeUpright", "roman", "\\_upshape", null,
-            N_("Upright - \\upshape"), on_text_font_shape_upright },
+            N_("Upright - \\upshape") },
         { "FontShapeItalic", "italic", "\\_itshape", null,
-            N_("Italic - \\itshape"), on_text_font_shape_italic },
+            N_("Italic - \\itshape") },
         { "FontShapeSlanted", "slanted", "\\_slshape", null,
-            N_("Slanted - \\slshape"), on_text_font_shape_slanted },
+            N_("Slanted - \\slshape") },
         { "FontShapeSmallCaps", "small_caps", "\\s_cshape", null,
-            N_("Small Capitals - \\scshape"), on_text_font_shape_small_caps },
+            N_("Small Capitals - \\scshape") },
 
         // LaTeX: Tabular
 
@@ -499,6 +499,27 @@ public class LatexMenu : Gtk.ActionGroup
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::underline",
             this, "Underline");
 
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::rmfamily",
+            this, "FontFamilyRoman");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::sffamily",
+            this, "FontFamilySansSerif");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::ttfamily",
+            this, "FontFamilyMonospace");
+
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::mdseries",
+            this, "FontSeriesMedium");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::bfseries",
+            this, "FontSeriesBold");
+
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::upshape",
+            this, "FontShapeUpright");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::itshape",
+            this, "FontShapeItalic");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::slshape",
+            this, "FontShapeSlanted");
+        Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::scshape",
+            this, "FontShapeSmallCaps");
+
         // LaTeX: Spacing
         Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::hspace",
             this, "SpacingHSpace");
@@ -779,53 +800,6 @@ public class LatexMenu : Gtk.ActionGroup
         insert_character_style ("Huge");
     }
 
-    /* Font styles */
-
-    public void on_text_font_family_roman ()
-    {
-        insert_character_style ("rmfamily");
-    }
-
-    public void on_text_font_family_sans_serif ()
-    {
-        insert_character_style ("sffamily");
-    }
-
-    public void on_text_font_family_monospace ()
-    {
-        insert_character_style ("ttfamily");
-    }
-
-    public void on_text_font_series_medium ()
-    {
-        insert_character_style ("mdseries");
-    }
-
-    public void on_text_font_series_bold ()
-    {
-        insert_character_style ("bfseries");
-    }
-
-    public void on_text_font_shape_upright ()
-    {
-        insert_character_style ("upshape");
-    }
-
-    public void on_text_font_shape_italic ()
-    {
-        insert_character_style ("itshape");
-    }
-
-    public void on_text_font_shape_slanted ()
-    {
-        insert_character_style ("slshape");
-    }
-
-    public void on_text_font_shape_small_caps ()
-    {
-        insert_character_style ("scshape");
-    }
-
     /* Tabular */
 
     public void on_tabular_tabbing ()
diff --git a/src/liblatexila/latexila-latex-commands.c b/src/liblatexila/latexila-latex-commands.c
index 203d91b..3c44fd6 100644
--- a/src/liblatexila/latexila-latex-commands.c
+++ b/src/liblatexila/latexila-latex-commands.c
@@ -141,6 +141,49 @@ latex_command_with_braces_cb (GSimpleAction *action,
   g_free (text_before);
 }
 
+static void
+latex_command_char_style_cb (GSimpleAction *action,
+                             GVariant      *parameter,
+                             gpointer       user_data)
+{
+  TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+  const gchar *style;
+  TeplBuffer *buffer;
+  TeplSelectionType selection_type;
+  gchar *text_before;
+  gchar *text_after;
+  gchar *text_if_no_selection;
+
+  style = g_variant_get_string (parameter, NULL);
+
+  buffer = tepl_tab_group_get_active_buffer (TEPL_TAB_GROUP (tepl_window));
+  g_return_if_fail (buffer != NULL);
+
+  selection_type = tepl_buffer_get_selection_type (buffer);
+
+  if (selection_type == TEPL_SELECTION_TYPE_MULTIPLE_LINES)
+    {
+      text_before = g_strdup_printf ("\\begin{%s}\n", style);
+      text_after = g_strdup_printf ("\n\\end{%s}", style);
+      text_if_no_selection = NULL;
+    }
+  else
+    {
+      text_before = g_strdup_printf ("{\\%s ", style);
+      text_after = g_strdup_printf ("}");
+      text_if_no_selection = g_strdup_printf ("\\%s ", style);
+    }
+
+  latexila_latex_commands_insert_text (tepl_window,
+                                       text_before,
+                                       text_after,
+                                       text_if_no_selection);
+
+  g_free (text_before);
+  g_free (text_after);
+  g_free (text_if_no_selection);
+}
+
 /**
  * latexila_latex_commands_add_actions:
  * @gtk_window: a #GtkApplicationWindow.
@@ -154,6 +197,7 @@ latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
 
   const GActionEntry entries[] = {
     { "latex-command-with-braces", latex_command_with_braces_cb, "s" },
+    { "latex-command-char-style", latex_command_char_style_cb, "s" },
   };
 
   g_return_if_fail (GTK_IS_APPLICATION_WINDOW (gtk_window));


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