[latexila] LaTeX menu: create latex-command-with-braces GAction
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] LaTeX menu: create latex-command-with-braces GAction
- Date: Wed, 25 Oct 2017 10:38:36 +0000 (UTC)
commit 2442c0c714138ec1665871d712126f6a4dd92fa3
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Oct 25 12:26:54 2017 +0200
LaTeX menu: create latex-command-with-braces GAction
The idea is to have a limited number of GActions, to take advantage of
the GAction GVariant parameter mechanism.
docs/reference/latexila-sections.txt | 1 +
src/latex_menu.vala | 74 ++++++++++++--------------------
src/liblatexila/latexila-latex-menu.c | 42 ++++++++++++++++++
src/liblatexila/latexila-latex-menu.h | 2 +
4 files changed, 73 insertions(+), 46 deletions(-)
---
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index a47c738..61af372 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -132,6 +132,7 @@ latexila_build_view_get_type
<SECTION>
<FILE>latex-menu</FILE>
+latexila_latex_menu_add_actions
latexila_latex_menu_insert_text
</SECTION>
diff --git a/src/latex_menu.vala b/src/latex_menu.vala
index 9620d3a..609fdb6 100644
--- a/src/latex_menu.vala
+++ b/src/latex_menu.vala
@@ -1,7 +1,7 @@
/*
* This file is part of LaTeXila.
*
- * Copyright © 2010-2011 Sébastien Wilmet
+ * Copyright © 2010-2011, 2017 Sébastien Wilmet
*
* LaTeXila is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,19 +31,19 @@ public class LatexMenu : Gtk.ActionGroup
{ "Sectioning", "sectioning", N_("_Sectioning") },
{ "SectioningPart", null, "\\_part", null,
- N_("Part"), on_sectioning_part },
+ N_("Part") },
{ "SectioningChapter", null, "\\_chapter", null,
- N_("Chapter"), on_sectioning_chapter },
+ N_("Chapter") },
{ "SectioningSection", null, "\\_section", null,
- N_("Section"), on_sectioning_section },
+ N_("Section") },
{ "SectioningSubsection", null, "\\s_ubsection", null,
- N_("Sub-section"), on_sectioning_subsection },
- { "SectioningSubsubsection", null, "\\su_bsubsection",
- null, N_("Sub-sub-section"), on_sectioning_subsubsection },
+ N_("Sub-section") },
+ { "SectioningSubsubsection", null, "\\su_bsubsection", null,
+ N_("Sub-sub-section") },
{ "SectioningParagraph", null, "\\p_aragraph", null,
- N_("Paragraph"), on_sectioning_paragraph },
+ N_("Paragraph") },
{ "SectioningSubparagraph", null, "\\subpa_ragraph", null,
- N_("Sub-paragraph"), on_sectioning_subparagraph },
+ N_("Sub-paragraph") },
// LaTeX: References
@@ -460,6 +460,25 @@ public class LatexMenu : Gtk.ActionGroup
add_action (references);
add_action (presentation_env);
add_action (math_env);
+
+ /* GActions */
+
+ Latexila.latex_menu_add_actions (main_window);
+
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::part",
+ this, "SectioningPart");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::chapter",
+ this, "SectioningChapter");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::section",
+ this, "SectioningSection");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::subsection",
+ this, "SectioningSubsection");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::subsubsection",
+ this, "SectioningSubsubsection");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::paragraph",
+ this, "SectioningParagraph");
+ Amtk.utils_bind_g_action_to_gtk_action (main_window, "latex-command-with-braces::subparagraph",
+ this, "SectioningSubparagraph");
}
private Gtk.Action get_menu_tool_action (string name, string? label, string? icon_name)
@@ -496,43 +515,6 @@ public class LatexMenu : Gtk.ActionGroup
text_buffer_insert (@"{\\$style ", "}", @"\\$style ");
}
- /* Sectioning */
-
- public void on_sectioning_part ()
- {
- text_buffer_insert ("\\part{", "}");
- }
-
- public void on_sectioning_chapter ()
- {
- text_buffer_insert ("\\chapter{", "}");
- }
-
- public void on_sectioning_section ()
- {
- text_buffer_insert ("\\section{", "}");
- }
-
- public void on_sectioning_subsection ()
- {
- text_buffer_insert ("\\subsection{", "}");
- }
-
- public void on_sectioning_subsubsection ()
- {
- text_buffer_insert ("\\subsubsection{", "}");
- }
-
- public void on_sectioning_paragraph ()
- {
- text_buffer_insert ("\\paragraph{", "}");
- }
-
- public void on_sectioning_subparagraph ()
- {
- text_buffer_insert ("\\subparagraph{", "}");
- }
-
/* References */
public void on_ref_label ()
diff --git a/src/liblatexila/latexila-latex-menu.c b/src/liblatexila/latexila-latex-menu.c
index c6bd605..6c826b8 100644
--- a/src/liblatexila/latexila-latex-menu.c
+++ b/src/liblatexila/latexila-latex-menu.c
@@ -123,3 +123,45 @@ latexila_latex_menu_insert_text (TeplApplicationWindow *tepl_window,
g_free (text_before_with_indent);
g_free (text_after_with_indent);
}
+
+static void
+latex_command_with_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_menu_insert_text (tepl_window, text_before, "}", NULL);
+
+ g_free (text_before);
+}
+
+/**
+ * latexila_latex_menu_add_actions:
+ * @gtk_window: a #GtkApplicationWindow.
+ *
+ * Adds the #GAction's related to the LaTeX and Math menus.
+ */
+void
+latexila_latex_menu_add_actions (GtkApplicationWindow *gtk_window)
+{
+ TeplApplicationWindow *tepl_window;
+
+ const GActionEntry entries[] = {
+ { "latex-command-with-braces", latex_command_with_braces_cb, "s" },
+ };
+
+ 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),
+ entries,
+ G_N_ELEMENTS (entries),
+ tepl_window);
+}
diff --git a/src/liblatexila/latexila-latex-menu.h b/src/liblatexila/latexila-latex-menu.h
index e6d971d..8d1be68 100644
--- a/src/liblatexila/latexila-latex-menu.h
+++ b/src/liblatexila/latexila-latex-menu.h
@@ -24,6 +24,8 @@
G_BEGIN_DECLS
+void latexila_latex_menu_add_actions (GtkApplicationWindow *gtk_window);
+
void latexila_latex_menu_insert_text (TeplApplicationWindow *tepl_window,
const gchar *text_before,
const gchar *text_after,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]