[gnome-latex: 32/205] - zoom in, zoom out, zoom reset - take into account the line numbers (show or hide) for new document



commit 1ab48491024b32c888618a650af0885081209ac6
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Wed Aug 26 12:45:33 2009 +0200

    - zoom in, zoom out, zoom reset
    - take into account the line numbers (show or hide) for new documents

 TODO            |  3 ++-
 src/callbacks.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
 src/callbacks.h |  3 +++
 src/main.c      | 11 +++++++++++
 src/main.h      |  2 ++
 src/ui.xml      |  4 ++++
 6 files changed, 67 insertions(+), 4 deletions(-)
---
diff --git a/TODO b/TODO
index 69e1888..9b9ec5f 100644
--- a/TODO
+++ b/TODO
@@ -12,7 +12,7 @@ Mon Aug 24, 2009 to Mon Aug 31, 2009
 
 [-] printing
 
-[-] enlarge/shrink font
+[x] enlarge/shrink font
 
 [-] Preferences
        - show line numbers
@@ -24,6 +24,7 @@ Mon Aug 24, 2009 to Mon Aug 31, 2009
          Gtk-CRITICAL **: gtk_text_buffer_emit_insert: assertion `g_utf8_validate (text, len, NULL)' failed
        x sometimes after making a replacement and then undo:
          GtkSourceView-CRITICAL **: gtk_source_undo_manager_undo: assertion `undo_action != NULL' failed
+       x show line numbers and new document...
 
 [-] CMake
 
diff --git a/src/callbacks.c b/src/callbacks.c
index cb4305e..6b552b7 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -34,6 +34,7 @@ static void update_cursor_position_statusbar (void);
 static void scroll_to_cursor (void);
 static gboolean find_next_match (const gchar *what, GtkSourceSearchFlags flags,
                gboolean backward, GtkTextIter *match_start, GtkTextIter *match_end);
+static void change_font_source_view (void);
 
 void
 cb_new (void)
@@ -256,6 +257,27 @@ cb_select_all (void)
        gtk_text_buffer_select_range (buffer, &start, &end);
 }
 
+void
+cb_zoom_in (void)
+{
+       latexila.font_size++;
+       change_font_source_view ();
+}
+
+void
+cb_zoom_out (void)
+{
+       latexila.font_size--;
+       change_font_source_view ();
+}
+
+void
+cb_zoom_reset (void)
+{
+       latexila.font_size = 10;
+       change_font_source_view ();
+}
+
 void
 cb_find (void)
 {
@@ -484,7 +506,7 @@ cb_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
 void
 cb_line_numbers (GtkToggleAction *action, gpointer user_data)
 {
-       gboolean show = gtk_toggle_action_get_active (action);
+       latexila.show_line_numbers = gtk_toggle_action_get_active (action);
 
        //TODO optimisation?
        guint nb_docs = g_list_length (latexila.all_docs);
@@ -492,7 +514,7 @@ cb_line_numbers (GtkToggleAction *action, gpointer user_data)
        {
                document_t *doc = g_list_nth_data (latexila.all_docs, i);
                gtk_source_view_set_show_line_numbers (
-                               GTK_SOURCE_VIEW (doc->source_view), show);
+                               GTK_SOURCE_VIEW (doc->source_view), latexila.show_line_numbers);
        }
 }
 
@@ -732,13 +754,19 @@ create_document_in_new_tab (const gchar *path, const gchar *text, const gchar *t
        gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (new_doc->source_view), TRUE);
 
        // set the font
-       PangoFontDescription *font_desc = pango_font_description_from_string (FONT);
+       gchar *font_string = g_strdup_printf ("%s %d", FONT, latexila.font_size);
+       PangoFontDescription *font_desc;
+       font_desc = pango_font_description_from_string (font_string);
        gtk_widget_modify_font (new_doc->source_view, font_desc);
 
        // enable text wrapping (between words only)
        gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (new_doc->source_view),
                        GTK_WRAP_WORD);
 
+       // show line numbers?
+       gtk_source_view_set_show_line_numbers (
+                       GTK_SOURCE_VIEW (new_doc->source_view), latexila.show_line_numbers);
+
        // put the text into the buffer
        gtk_source_buffer_begin_not_undoable_action (new_doc->source_buffer);
        gtk_text_buffer_set_text (GTK_TEXT_BUFFER (new_doc->source_buffer), text, -1);
@@ -1327,3 +1355,17 @@ find_next_match (const gchar *what, GtkSourceSearchFlags flags,
        }
 }
 
+static void
+change_font_source_view (void)
+{
+       guint nb_docs = g_list_length (latexila.all_docs);
+       for (guint i = 0 ; i < nb_docs ; i++)
+       {
+               document_t *doc = g_list_nth_data (latexila.all_docs, i);
+               gchar *font_string = g_strdup_printf ("%s %d", FONT, latexila.font_size);
+               PangoFontDescription *font_desc;
+               font_desc = pango_font_description_from_string (font_string);
+               gtk_widget_modify_font (doc->source_view, font_desc);
+       }
+}
+
diff --git a/src/callbacks.h b/src/callbacks.h
index 44f8731..048d84f 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -15,6 +15,9 @@ void cb_copy (void);
 void cb_paste (void);
 void cb_delete (void);
 void cb_select_all (void);
+void cb_zoom_in (void);
+void cb_zoom_out (void);
+void cb_zoom_reset (void);
 void cb_find (void);
 void cb_replace (void);
 void cb_latex (void);
diff --git a/src/main.c b/src/main.c
index 39a8898..64e5f8b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -128,6 +128,12 @@ main (int argc, char *argv[])
                        _("Select the entire document"), G_CALLBACK (cb_select_all)},
 
                {"View", NULL, _("View"), NULL, NULL, NULL},
+               {"ViewZoomIn", GTK_STOCK_ZOOM_IN, _("Zoom In"), "<Control>plus",
+                       _("Enlarge the font"), G_CALLBACK (cb_zoom_in)},
+               {"ViewZoomOut", GTK_STOCK_ZOOM_OUT, _("Zoom Out"), "<Control>minus",
+                       _("Shrink the font"), G_CALLBACK (cb_zoom_out)},
+               {"ViewZoomReset", GTK_STOCK_ZOOM_100, _("Reset Zoom"), "<Control>0",
+                       _("Reset the size of the font"), G_CALLBACK (cb_zoom_reset)},
 
                {"Search", NULL, _("Search"), NULL, NULL, NULL},
                {"SearchFind", GTK_STOCK_FIND, _("Find..."), "<Control>F",
@@ -198,6 +204,8 @@ main (int argc, char *argv[])
        GtkWidget *menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");
        gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, FALSE, 0);
        GtkWidget *toolbar = gtk_ui_manager_get_widget (ui_manager, "/MainToolbar");
+       // toolbar with icons only
+       gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
        gtk_box_pack_start (GTK_BOX (main_vbox), toolbar, FALSE, FALSE, 0);
 
        // accelerators
@@ -221,6 +229,9 @@ main (int argc, char *argv[])
        gtk_paned_pack1 (GTK_PANED (vpaned), notebook, TRUE, TRUE);
        latexila.notebook = GTK_NOTEBOOK (notebook);
 
+       latexila.font_size = 10;
+       latexila.show_line_numbers = FALSE;
+
        /* log zone */
        //TODO set default height and width
        GtkWidget *hpaned = gtk_hpaned_new ();
diff --git a/src/main.h b/src/main.h
index 90c5206..062c6c0 100644
--- a/src/main.h
+++ b/src/main.h
@@ -34,6 +34,8 @@ typedef struct
        GtkStatusbar            *cursor_position;
        GtkAction                       *undo;
        GtkAction                       *redo;
+       gint                            font_size;
+       gboolean                        show_line_numbers;
 } latexila_t;
 
 // all the documents are accessible by the docs variable
diff --git a/src/ui.xml b/src/ui.xml
index 0049634..20c6d5e 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -31,6 +31,10 @@ In the code, GtkUIManager is used to construct them.
 
     <menu action="View">
       <menuitem action="ViewLineNumbers" />
+      <separator />
+      <menuitem action="ViewZoomIn" />
+      <menuitem action="ViewZoomOut" />
+      <menuitem action="ViewZoomReset" />
     </menu>
 
     <menu action="Search">


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