[gnome-latex: 65/205] Menu: LaTeX: environments



commit 8b709267f05d0c639b1eb8f067e04e3ad41ab338
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Tue Sep 15 18:26:50 2009 +0200

    Menu: LaTeX: environments
    
    All the callbacks of the actions located in the LaTeX menu are in
    cb_latex.c.

 TODO                            |  13 ++-
 images/icons/justify-center.png | Bin 0 -> 569 bytes
 images/icons/justify-left.png   | Bin 0 -> 510 bytes
 images/icons/justify-right.png  | Bin 0 -> 497 bytes
 src/CMakeLists.txt              |   1 +
 src/callbacks.c                 | 162 ----------------------------
 src/callbacks.h                 |  18 ----
 src/cb_latex.c                  | 233 ++++++++++++++++++++++++++++++++++++++++
 src/cb_latex.h                  |  30 ++++++
 src/ui.c                        |  29 ++++-
 src/ui.xml                      |  14 +++
 11 files changed, 308 insertions(+), 192 deletions(-)
---
diff --git a/TODO b/TODO
index 810f263..d1c04c2 100644
--- a/TODO
+++ b/TODO
@@ -13,18 +13,17 @@ Wed Sep 9, 2009 to Wed Sep 16, 2009
 
 [x] check memory leaks
 
+[x] open recent
+       x when "save as", add the file to the recent manager
+
 [-] new toolbar
-       x bold, italic, typewriter, underline
-       x font styles
-       - structure: part, chapter, section, subsection, subsubsection, paragraph, subparagraph
+       x font styles: bold, italic, ...
+       x environments: center, flushleft, ...
+       - structures: part, chapter, section, ...
        - size of characters
-       - center
        - lists: itemize, enumerate, description
        - various: label, ref, pageref, cite, footnote, index
 
-[x] open recent
-       x when "save as", add the file to the recent manager
-
 [-] symbol tables
        - the categories must take the minimum place but the presentation must be nice
                * homogeneous icons
diff --git a/images/icons/justify-center.png b/images/icons/justify-center.png
new file mode 100644
index 0000000..d5e754a
Binary files /dev/null and b/images/icons/justify-center.png differ
diff --git a/images/icons/justify-left.png b/images/icons/justify-left.png
new file mode 100644
index 0000000..0ba4d6f
Binary files /dev/null and b/images/icons/justify-left.png differ
diff --git a/images/icons/justify-right.png b/images/icons/justify-right.png
new file mode 100644
index 0000000..5f8fa59
Binary files /dev/null and b/images/icons/justify-right.png differ
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3f43944..b46845f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,6 @@
 SET(latexila_src main.c        main.h
                 callbacks.c    callbacks.h
+                cb_latex.c     cb_latex.h
                 print.c        print.h
                 symbols.c      symbols.h
                 actions.c      actions.h
diff --git a/src/callbacks.c b/src/callbacks.c
index 7a9f9b5..d4d9209 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -52,8 +52,6 @@ static gboolean find_next_match (const gchar *what, GtkSourceSearchFlags flags,
 static void change_font_source_view (void);
 static void create_preferences (void);
 static void free_latexila (void);
-static void text_buffer_insert (gchar *text_before, gchar *text_after,
-               gchar *text_if_no_selection);
 
 static GtkWidget *pref_dialog = NULL;
 
@@ -861,166 +859,6 @@ cb_show_symbol_tables (GtkToggleAction *toggle_action, gpointer user_data)
                gtk_widget_hide (latexila.symbols->vbox);
 }
 
-static void
-text_buffer_insert (gchar *text_before, gchar *text_after,
-               gchar *text_if_no_selection)
-{
-       if (latexila.active_doc == NULL)
-               return;
-
-       // we do not use the insert and selection_bound marks because the we don't
-       // know the order. With gtk_text_buffer_get_selection_bounds, we are certain
-       // that "start" points to the start of the selection, where we must insert
-       // "text_before".
-
-       GtkTextBuffer *buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
-       GtkTextIter start, end;
-       gboolean text_selected = gtk_text_buffer_get_selection_bounds (buffer,
-                       &start, &end);
-
-       gtk_text_buffer_begin_user_action (buffer);
-
-       // insert around the selected text
-       // move the cursor to the end
-       if (text_selected)
-       {
-               GtkTextMark *mark_end = gtk_text_buffer_create_mark (buffer, NULL,
-                               &end, FALSE);
-               gtk_text_buffer_insert (buffer, &start, text_before, -1);
-               gtk_text_buffer_get_iter_at_mark (buffer, &end, mark_end);
-               gtk_text_buffer_insert (buffer, &end, text_after, -1);
-
-               gtk_text_buffer_get_iter_at_mark (buffer, &end, mark_end);
-               gtk_text_buffer_select_range (buffer, &end, &end);
-       }
-
-       // no selection
-       else if (text_if_no_selection != NULL)
-               gtk_text_buffer_insert_at_cursor (buffer, text_if_no_selection, -1);
-
-       // no selection
-       // move the cursor between the 2 texts inserted
-       else
-       {
-               gtk_text_buffer_insert_at_cursor (buffer, text_before, -1);
-
-               GtkTextIter between;
-               gtk_text_buffer_get_iter_at_mark (buffer, &between,
-                               gtk_text_buffer_get_insert (buffer));
-               GtkTextMark *mark = gtk_text_buffer_create_mark (buffer, NULL,
-                               &between, TRUE);
-
-               gtk_text_buffer_insert_at_cursor (buffer, text_after, -1);
-
-               gtk_text_buffer_get_iter_at_mark (buffer, &between, mark);
-               gtk_text_buffer_select_range (buffer, &between, &between);
-       }
-
-       gtk_text_buffer_end_user_action (buffer);
-}
-
-void
-cb_text_bold (void)
-{
-       text_buffer_insert ("\\textbf{", "}", NULL);
-}
-
-void
-cb_text_italic (void)
-{
-       text_buffer_insert ("\\textit{", "}", NULL);
-}
-
-void
-cb_text_typewriter (void)
-{
-       text_buffer_insert ("\\texttt{", "}", NULL);
-}
-
-void
-cb_text_underline (void)
-{
-       text_buffer_insert ("\\underline{", "}", NULL);
-}
-
-void
-cb_text_slanted (void)
-{
-       text_buffer_insert ("\\textsl{", "}", NULL);
-}
-
-void
-cb_text_small_caps (void)
-{
-       text_buffer_insert ("\\textsc{", "}", NULL);
-}
-
-void
-cb_text_emph (void)
-{
-       text_buffer_insert ("\\emph{", "}", NULL);
-}
-
-void
-cb_text_strong (void)
-{
-       text_buffer_insert ("\\strong{", "}", NULL);
-}
-
-void
-cb_text_font_family_roman (void)
-{
-       text_buffer_insert ("{\\rmfamily ", "}", "\\rmfamily ");
-}
-
-void
-cb_text_font_family_sans_serif (void)
-{
-       text_buffer_insert ("{\\sffamily ", "}", "\\sffamily ");
-}
-
-void
-cb_text_font_family_monospace (void)
-{
-       text_buffer_insert ("{\\ttfamily ", "}", "\\ttfamily ");
-}
-
-void
-cb_text_font_series_medium (void)
-{
-       text_buffer_insert ("{\\mdseries ", "}", "\\mdseries ");
-}
-
-void
-cb_text_font_series_bold (void)
-{
-       text_buffer_insert ("{\\bfseries ", "}", "\\bfseries ");
-}
-
-void
-cb_text_font_shape_upright (void)
-{
-       text_buffer_insert ("{\\upshape ", "}", "\\upshape ");
-}
-
-void
-cb_text_font_shape_italic (void)
-{
-       text_buffer_insert ("{\\itshape ", "}", "\\itshape ");
-}
-
-void
-cb_text_font_shape_slanted (void)
-{
-       text_buffer_insert ("{\\slshape ", "}", "\\slshape ");
-}
-
-void
-cb_text_font_shape_small_caps (void)
-{
-       text_buffer_insert ("{\\scshape ", "}", "\\scshape ");
-}
-
 void
 open_new_document (const gchar *filename, const gchar *uri)
 {
diff --git a/src/callbacks.h b/src/callbacks.h
index 735cdc6..c86b99e 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -67,24 +67,6 @@ void cb_category_symbols_selected (GtkIconView *icon_view, gpointer user_data);
 void cb_symbol_selected (GtkIconView *icon_view, gpointer user_data);
 void cb_show_symbol_tables (GtkToggleAction *toggle_action, gpointer user_data);
 
-void cb_text_bold (void);
-void cb_text_italic (void);
-void cb_text_typewriter (void);
-void cb_text_underline (void);
-void cb_text_slanted (void);
-void cb_text_small_caps (void);
-void cb_text_emph (void);
-void cb_text_strong (void);
-void cb_text_font_family_roman (void);
-void cb_text_font_family_sans_serif (void);
-void cb_text_font_family_monospace (void);
-void cb_text_font_series_medium (void);
-void cb_text_font_series_bold (void);
-void cb_text_font_shape_upright (void);
-void cb_text_font_shape_italic (void);
-void cb_text_font_shape_slanted (void);
-void cb_text_font_shape_small_caps (void);
-
 void open_new_document (const gchar *filename, const gchar *uri);
 
 #endif /* CALLBACKS_H */
diff --git a/src/cb_latex.c b/src/cb_latex.c
new file mode 100644
index 0000000..c579baf
--- /dev/null
+++ b/src/cb_latex.c
@@ -0,0 +1,233 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourceview.h>
+
+#include "main.h"
+#include "config.h"
+#include "print.h"
+
+static void text_buffer_insert (gchar *text_before, gchar *text_after,
+               gchar *text_if_no_selection);
+
+static void
+text_buffer_insert (gchar *text_before, gchar *text_after,
+               gchar *text_if_no_selection)
+{
+       if (latexila.active_doc == NULL)
+               return;
+
+       // we do not use the insert and selection_bound marks because the we don't
+       // know the order. With gtk_text_buffer_get_selection_bounds, we are certain
+       // that "start" points to the start of the selection, where we must insert
+       // "text_before".
+
+       GtkTextBuffer *buffer = GTK_TEXT_BUFFER (latexila.active_doc->source_buffer);
+       GtkTextIter start, end;
+       gboolean text_selected = gtk_text_buffer_get_selection_bounds (buffer,
+                       &start, &end);
+
+       gtk_text_buffer_begin_user_action (buffer);
+
+       // insert around the selected text
+       // move the cursor to the end
+       if (text_selected)
+       {
+               GtkTextMark *mark_end = gtk_text_buffer_create_mark (buffer, NULL,
+                               &end, FALSE);
+               gtk_text_buffer_insert (buffer, &start, text_before, -1);
+               gtk_text_buffer_get_iter_at_mark (buffer, &end, mark_end);
+               gtk_text_buffer_insert (buffer, &end, text_after, -1);
+
+               gtk_text_buffer_get_iter_at_mark (buffer, &end, mark_end);
+               gtk_text_buffer_select_range (buffer, &end, &end);
+       }
+
+       // no selection
+       else if (text_if_no_selection != NULL)
+               gtk_text_buffer_insert_at_cursor (buffer, text_if_no_selection, -1);
+
+       // no selection
+       // move the cursor between the 2 texts inserted
+       else
+       {
+               gtk_text_buffer_insert_at_cursor (buffer, text_before, -1);
+
+               GtkTextIter between;
+               gtk_text_buffer_get_iter_at_mark (buffer, &between,
+                               gtk_text_buffer_get_insert (buffer));
+               GtkTextMark *mark = gtk_text_buffer_create_mark (buffer, NULL,
+                               &between, TRUE);
+
+               gtk_text_buffer_insert_at_cursor (buffer, text_after, -1);
+
+               gtk_text_buffer_get_iter_at_mark (buffer, &between, mark);
+               gtk_text_buffer_select_range (buffer, &between, &between);
+       }
+
+       gtk_text_buffer_end_user_action (buffer);
+}
+
+void
+cb_text_bold (void)
+{
+       text_buffer_insert ("\\textbf{", "}", NULL);
+}
+
+void
+cb_text_italic (void)
+{
+       text_buffer_insert ("\\textit{", "}", NULL);
+}
+
+void
+cb_text_typewriter (void)
+{
+       text_buffer_insert ("\\texttt{", "}", NULL);
+}
+
+void
+cb_text_underline (void)
+{
+       text_buffer_insert ("\\underline{", "}", NULL);
+}
+
+void
+cb_text_slanted (void)
+{
+       text_buffer_insert ("\\textsl{", "}", NULL);
+}
+
+void
+cb_text_small_caps (void)
+{
+       text_buffer_insert ("\\textsc{", "}", NULL);
+}
+
+void
+cb_text_emph (void)
+{
+       text_buffer_insert ("\\emph{", "}", NULL);
+}
+
+void
+cb_text_strong (void)
+{
+       text_buffer_insert ("\\strong{", "}", NULL);
+}
+
+void
+cb_text_font_family_roman (void)
+{
+       text_buffer_insert ("{\\rmfamily ", "}", "\\rmfamily ");
+}
+
+void
+cb_text_font_family_sans_serif (void)
+{
+       text_buffer_insert ("{\\sffamily ", "}", "\\sffamily ");
+}
+
+void
+cb_text_font_family_monospace (void)
+{
+       text_buffer_insert ("{\\ttfamily ", "}", "\\ttfamily ");
+}
+
+void
+cb_text_font_series_medium (void)
+{
+       text_buffer_insert ("{\\mdseries ", "}", "\\mdseries ");
+}
+
+void
+cb_text_font_series_bold (void)
+{
+       text_buffer_insert ("{\\bfseries ", "}", "\\bfseries ");
+}
+
+void
+cb_text_font_shape_upright (void)
+{
+       text_buffer_insert ("{\\upshape ", "}", "\\upshape ");
+}
+
+void
+cb_text_font_shape_italic (void)
+{
+       text_buffer_insert ("{\\itshape ", "}", "\\itshape ");
+}
+
+void
+cb_text_font_shape_slanted (void)
+{
+       text_buffer_insert ("{\\slshape ", "}", "\\slshape ");
+}
+
+void
+cb_text_font_shape_small_caps (void)
+{
+       text_buffer_insert ("{\\scshape ", "}", "\\scshape ");
+}
+
+void
+cb_env_center (void)
+{
+       text_buffer_insert ("\\begin{center}\n", "\n\\end{center}", NULL);
+}
+
+void
+cb_env_left (void)
+{
+       text_buffer_insert ("\\begin{flushleft}\n", "\n\\end{flushleft}", NULL);
+}
+
+void
+cb_env_right (void)
+{
+       text_buffer_insert ("\\begin{flushright}\n", "\n\\end{flushright}", NULL);
+}
+
+void
+cb_env_minipage (void)
+{
+       text_buffer_insert ("\\begin{minipage}\n", "\n\\end{minipage}", NULL);
+}
+
+void
+cb_env_quote (void)
+{
+       text_buffer_insert ("\\begin{quote}\n", "\n\\end{quote}", NULL);
+}
+
+void
+cb_env_quotation (void)
+{
+       text_buffer_insert ("\\begin{quotation}\n", "\n\\end{quotation}", NULL);
+}
+
+void
+cb_env_verse (void)
+{
+       text_buffer_insert ("\\begin{verse}\n", "\n\\end{verse}", NULL);
+}
+
diff --git a/src/cb_latex.h b/src/cb_latex.h
new file mode 100644
index 0000000..362bd77
--- /dev/null
+++ b/src/cb_latex.h
@@ -0,0 +1,30 @@
+#ifndef CB_LATEX_H
+#define CB_LATEX_H
+
+void cb_text_bold (void);
+void cb_text_italic (void);
+void cb_text_typewriter (void);
+void cb_text_underline (void);
+void cb_text_slanted (void);
+void cb_text_small_caps (void);
+void cb_text_emph (void);
+void cb_text_strong (void);
+void cb_text_font_family_roman (void);
+void cb_text_font_family_sans_serif (void);
+void cb_text_font_family_monospace (void);
+void cb_text_font_series_medium (void);
+void cb_text_font_series_bold (void);
+void cb_text_font_shape_upright (void);
+void cb_text_font_shape_italic (void);
+void cb_text_font_shape_slanted (void);
+void cb_text_font_shape_small_caps (void);
+
+void cb_env_center (void);
+void cb_env_left (void);
+void cb_env_right (void);
+void cb_env_minipage (void);
+void cb_env_quote (void);
+void cb_env_quotation (void);
+void cb_env_verse (void);
+
+#endif /* CB_LATEX_H */
diff --git a/src/ui.c b/src/ui.c
index 21a2466..8175930 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "print.h"
 #include "callbacks.h"
+#include "cb_latex.h"
 
 static void register_my_stock_icons (void);
 
@@ -45,7 +46,10 @@ static struct {
        {DATA_DIR "/images/icons/textbf.png", "bold"},
        {DATA_DIR "/images/icons/textit.png", "italic"},
        {DATA_DIR "/images/icons/texttt.png", "typewriter"},
-       {DATA_DIR "/images/icons/underline.png", "underline"}
+       {DATA_DIR "/images/icons/underline.png", "underline"},
+       {DATA_DIR "/images/icons/justify-center.png", "justify_center"},
+       {DATA_DIR "/images/icons/justify-left.png", "justify_left"},
+       {DATA_DIR "/images/icons/justify-right.png", "justify_right"},
 };
 
 // all the actions (for the menu and the toolbar)
@@ -120,7 +124,7 @@ static GtkActionEntry entries[] = {
 };
 
 // {name, stock_id, label, accelerator, tooltip, callback}
-static GtkActionEntry edit_entries[] = {
+static GtkActionEntry latex_entries[] = {
        {"Latex", NULL, N_("LaTeX"), NULL, NULL, NULL},
 
        {"FontStyles", NULL, N_("Font Styles"), NULL, NULL, NULL},
@@ -163,8 +167,23 @@ static GtkActionEntry edit_entries[] = {
        {"FontShapeSlanted", NULL, N_("Slanted - \\slshape"), NULL,
                N_("Slanted - \\slshape"), G_CALLBACK (cb_text_font_shape_slanted)},
        {"FontShapeSmallCaps", NULL, N_("Small Capitals - \\scshape"), NULL,
-               N_("Small Capitals - \\scshape"), G_CALLBACK (cb_text_font_shape_small_caps)}
+               N_("Small Capitals - \\scshape"), G_CALLBACK (cb_text_font_shape_small_caps)},
 
+       {"Environments", NULL, N_("Environments"), NULL, NULL, NULL},
+       {"EnvironmentCenter", "justify_center", N_("Center - \\begin{center}"), NULL,
+               N_("Center - \\begin{center}"), G_CALLBACK (cb_env_center)},
+       {"EnvironmentLeft", "justify_left", N_("Align Left - \\begin{flushleft}"), NULL,
+               N_("Align Left - \\begin{flushleft}"), G_CALLBACK (cb_env_left)},
+       {"EnvironmentRight", "justify_right", N_("Align Right - \\begin{flushright}"), NULL,
+               N_("Align Right - \\begin{flushright}"), G_CALLBACK (cb_env_right)},
+       {"EnvironmentMinipage", NULL, N_("Minipage - \\begin{minipage}"), NULL,
+               N_("Minipage - \\begin{minipage}"), G_CALLBACK (cb_env_minipage)},
+       {"EnvironmentQuote", NULL, N_("Quote - \\begin{quote}"), NULL,
+               N_("Quote - \\begin{quote}"), G_CALLBACK (cb_env_quote)},
+       {"EnvironmentQuotation", NULL, N_("Quotation - \\begin{quotation}"), NULL,
+               N_("Quotation - \\begin{quotation}"), G_CALLBACK (cb_env_quotation)},
+       {"EnvironmentVerse", NULL, N_("Verse - \\begin{verse}"), NULL,
+               N_("Verse - \\begin{verse}"), G_CALLBACK (cb_env_verse)}
 };
 
 // {name, stock_id, label, accelerator, tooltip, callback}
@@ -176,7 +195,7 @@ static GtkToggleActionEntry toggle_entries[] = {
 
 static guint n_stock_icons = G_N_ELEMENTS (stock_icons);
 static guint nb_entries = G_N_ELEMENTS (entries);
-static guint nb_edit_entries = G_N_ELEMENTS (edit_entries);
+static guint nb_latex_entries = G_N_ELEMENTS (latex_entries);
 static guint nb_toggle_entries = G_N_ELEMENTS (toggle_entries);
 
 static void
@@ -222,7 +241,7 @@ init_ui (GtkWidget *box)
        gtk_action_group_set_translation_domain (action_group, LATEXILA_NLS_PACKAGE);
 #endif
        gtk_action_group_add_actions (action_group, entries, nb_entries, NULL);
-       gtk_action_group_add_actions (action_group, edit_entries, nb_edit_entries,
+       gtk_action_group_add_actions (action_group, latex_entries, nb_latex_entries,
                        NULL);
        gtk_action_group_add_toggle_actions (action_group, toggle_entries,
                        nb_toggle_entries, NULL);
diff --git a/src/ui.xml b/src/ui.xml
index dbd6082..0a29288 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -75,6 +75,18 @@ In the code, GtkUIManager is used to construct them.
     </menu>
 
     <menu action="Latex">
+      <menu action="Environments">
+        <menuitem action="EnvironmentCenter" />
+        <menuitem action="EnvironmentLeft" />
+        <menuitem action="EnvironmentRight" />
+        <separator />
+        <menuitem action="EnvironmentMinipage" />
+        <separator />
+        <menuitem action="EnvironmentQuote" />
+        <menuitem action="EnvironmentQuotation" />
+        <menuitem action="EnvironmentVerse" />
+      </menu>
+      
       <menu action="FontStyles">
         <menuitem action="Bold" />
         <menuitem action="Italic" />
@@ -137,5 +149,7 @@ In the code, GtkUIManager is used to construct them.
     <toolitem action="Italic" />
     <toolitem action="Typewriter" />
     <toolitem action="Underline" />
+    <separator />
+    <toolitem action="EnvironmentCenter" />
   </toolbar>
 </ui>


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