[latexila] LaTeX commands: port List Environments submenu to GAction
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] LaTeX commands: port List Environments submenu to GAction
- Date: Wed, 1 Nov 2017 08:40:25 +0000 (UTC)
commit 39ab149d817005cf8c5e1cf6f32929f549013f96
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Oct 29 12:51:52 2017 +0100
LaTeX commands: port List Environments submenu to GAction
src/latex_menu.vala | 54 +++++----------
src/liblatexila/latexila-latex-commands.c | 105 +++++++++++++++++++++++++++++
2 files changed, 122 insertions(+), 37 deletions(-)
---
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index 2e69c73..53d0061 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -91,15 +91,15 @@ public class LatexMenu : Gtk.ActionGroup
{ "ListEnvironments", "list-itemize", N_("_List Environments") },
{ "ListEnvItemize", "list-itemize", "\\begin{_itemize}", null,
- N_("Bulleted List - \\begin{itemize}"), on_list_env_itemize },
+ N_("Bulleted List - \\begin{itemize}") },
{ "ListEnvEnumerate", "list-enumerate", "\\begin{_enumerate}", null,
- N_("Enumeration - \\begin{enumerate}"), on_list_env_enumerate },
+ N_("Enumeration - \\begin{enumerate}") },
{ "ListEnvDescription", "list-description", "\\begin{_description}", null,
- N_("Description - \\begin{description}"), on_list_env_description },
+ N_("Description - \\begin{description}") },
{ "ListEnvList", null, "\\begin{_list}", null,
- N_("Custom list - \\begin{list}"), on_list_env_list },
+ N_("Custom list - \\begin{list}") },
{ "ListEnvItem", "list-item", "\\i_tem", "<Alt><Shift>H",
- N_("List item - \\item"), on_list_env_item },
+ N_("List item - \\item") },
// LaTeX: character sizes
@@ -509,6 +509,18 @@ public class LatexMenu : Gtk.ActionGroup
Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-env-simple::titlepage",
this, "EnvTitlepage");
+ // LaTeX: list environments
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-list-env-simple::itemize",
+ this, "ListEnvItemize");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-list-env-simple::enumerate",
+ this, "ListEnvEnumerate");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-list-env-description",
+ this, "ListEnvDescription");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-list-env-list",
+ this, "ListEnvList");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-without-braces::item",
+ this, "ListEnvItem");
+
// LaTeX: character sizes
Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-char-style::tiny",
this, "CharacterSizeTiny");
@@ -634,38 +646,6 @@ public class LatexMenu : Gtk.ActionGroup
return Latexila.view_get_indentation_style (main_window.active_view);
}
- /* List Environments */
-
- public void on_list_env_itemize ()
- {
- string indent = get_indentation ();
- text_buffer_insert (@"\\begin{itemize}\n$indent\\item ", "\n\\end{itemize}");
- }
-
- public void on_list_env_enumerate ()
- {
- string indent = get_indentation ();
- text_buffer_insert (@"\\begin{enumerate}\n$indent\\item ", "\n\\end{enumerate}");
- }
-
- public void on_list_env_description ()
- {
- string indent = get_indentation ();
- text_buffer_insert (@"\\begin{description}\n$indent\\item[",
- "] \n\\end{description}");
- }
-
- public void on_list_env_list ()
- {
- string indent = get_indentation ();
- text_buffer_insert ("\\begin{list}{", @"}{}\n$indent\\item \n\\end{list}");
- }
-
- public void on_list_env_item ()
- {
- text_buffer_insert ("\\item ", "");
- }
-
/* Tabular */
public void on_tabular_tabbing ()
diff --git a/src/liblatexila/latexila-latex-commands.c b/src/liblatexila/latexila-latex-commands.c
index 637cdcd..f9fca24 100644
--- a/src/liblatexila/latexila-latex-commands.c
+++ b/src/liblatexila/latexila-latex-commands.c
@@ -143,6 +143,23 @@ latex_command_with_braces_cb (GSimpleAction *action,
}
static void
+latex_command_without_braces_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *command;
+ gchar *text_before;
+
+ command = g_variant_get_string (parameter, NULL);
+ text_before = g_strdup_printf ("\\%s ", command);
+
+ latexila_latex_commands_insert_text (tepl_window, text_before, "", NULL);
+
+ g_free (text_before);
+}
+
+static void
latex_command_env_simple_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
@@ -246,6 +263,90 @@ latex_command_env_table_cb (GSimpleAction *action,
}
static void
+latex_command_list_env_simple_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ const gchar *list_env;
+ TeplView *view;
+ gchar *indent;
+ gchar *text_before;
+ gchar *text_after;
+
+ list_env = g_variant_get_string (parameter, NULL);
+
+ 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{%s}\n"
+ "%s\\item ",
+ list_env,
+ indent);
+
+ text_after = g_strdup_printf ("\n\\end{%s}", list_env);
+
+ 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_list_env_description_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{description}\n"
+ "%s\\item[",
+ indent);
+
+ text_after = g_strdup_printf ("] \n\\end{description}");
+
+ 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_list_env_list_cb (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ TeplApplicationWindow *tepl_window = TEPL_APPLICATION_WINDOW (user_data);
+ TeplView *view;
+ gchar *indent;
+ 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_after = g_strdup_printf ("}{}\n%s\\item \n\\end{list}", indent);
+
+ latexila_latex_commands_insert_text (tepl_window, "\\begin{list}{", text_after, NULL);
+
+ g_free (indent);
+ g_free (text_after);
+}
+
+static void
latex_command_char_style_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
@@ -301,9 +402,13 @@ latexila_latex_commands_add_actions (GtkApplicationWindow *gtk_window)
const GActionEntry entries[] = {
{ "latex-command-with-braces", latex_command_with_braces_cb, "s" },
+ { "latex-command-without-braces", latex_command_without_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-list-env-simple", latex_command_list_env_simple_cb, "s" },
+ { "latex-command-list-env-description", latex_command_list_env_description_cb },
+ { "latex-command-list-env-list", latex_command_list_env_list_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]