[gnome-latex: 15/205] show/hide line numbers



commit 198c084f22d9c50fc55dda891b9bdebd937e40e5
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Wed Aug 5 18:36:14 2009 +0200

    show/hide line numbers

 TODO            |  2 +-
 src/callbacks.c | 19 +++++++++++++++++++
 src/callbacks.h |  1 +
 src/main.c      | 11 +++++++++++
 src/ui.xml      |  4 ++++
 5 files changed, 36 insertions(+), 1 deletion(-)
---
diff --git a/TODO b/TODO
index 8fbbc3f..cd4db6e 100644
--- a/TODO
+++ b/TODO
@@ -16,6 +16,6 @@ Jul 31, 2009 to Aug 7, 2009
 
 [-] GtkSourceView
        x syntaxic color
-       - show/hide line numbers
+       x show/hide line numbers
        - undo/redo
 
diff --git a/src/callbacks.c b/src/callbacks.c
index 4ef7292..ee9689d 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -182,6 +182,22 @@ cb_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
        return TRUE;
 }
 
+void
+cb_line_numbers (GtkToggleAction *action, gpointer user_data)
+{
+       gboolean show = gtk_toggle_action_get_active (action);
+
+       //TODO optimisation?
+       guint nb_docs = g_list_length (docs.all);
+       for (guint i = 0 ; i < nb_docs ; i++)
+       {
+               document_t *doc = g_list_nth_data (docs.all, i);
+               gtk_source_view_set_show_line_numbers (
+                               GTK_SOURCE_VIEW (doc->source_view), show);
+       }
+}
+
+
 void
 cb_about_dialog (void)
 {
@@ -270,6 +286,9 @@ create_document_in_new_tab (gchar *path, gchar *text, GtkWidget *label)
                gtk_source_buffer_set_language (new_doc->source_buffer, lang);
        }
 
+       // set auto indentation
+       gtk_source_view_set_auto_indent (GTK_SOURCE_VIEW (new_doc->source_view), TRUE);
+
        // put the text into the buffer
        gtk_text_buffer_set_text (GTK_TEXT_BUFFER (new_doc->source_buffer), text, -1);
 
diff --git a/src/callbacks.h b/src/callbacks.h
index ad4fe3a..b2850a8 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -11,5 +11,6 @@ void cb_about_dialog (void);
 void cb_text_changed (GtkWidget *widget, gpointer user_data);
 void cb_page_change (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data);
 gboolean cb_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data);
+void cb_line_numbers (GtkToggleAction *action, gpointer user_data);
 
 #endif /* CALLBACKS_H */
diff --git a/src/main.c b/src/main.c
index 0741316..8293dbb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -66,6 +66,8 @@ main (int argc, char *argv[])
                        _("Undo the last action"), NULL},
                {"EditRedo", GTK_STOCK_REDO, _("Redo"), "<Shift><Control>Z",
                        _("Redo the last undone action"), NULL},
+
+               {"View", NULL, _("View"), NULL, NULL, NULL},
                
                {"LaTeX", NULL, "LaTeX", NULL, NULL, NULL},
                {"compile_latex", GTK_STOCK_EXECUTE, _("Compile (latex)"), "<Release>F5",
@@ -82,11 +84,20 @@ main (int argc, char *argv[])
                        _("About LaTeXila"), G_CALLBACK (cb_about_dialog)}
        };
 
+       // name, stock_id, label, accelerator, tooltip, callback
+       GtkToggleActionEntry toggle_entries[] =
+       {
+               {"ViewLineNumbers", NULL, _("Line numbers"), NULL,
+                       _("Display line numbers"), G_CALLBACK (cb_line_numbers)}
+       };
+
        guint nb_entries = G_N_ELEMENTS (entries);
+       guint nb_toggle_entries = G_N_ELEMENTS (toggle_entries);
 
        // create the action group and the ui manager
        GtkActionGroup *action_group = gtk_action_group_new ("menuActionGroup");
        gtk_action_group_add_actions (action_group, entries, nb_entries, NULL);
+       gtk_action_group_add_toggle_actions (action_group, toggle_entries, nb_toggle_entries, NULL);
        GtkUIManager *ui_manager = gtk_ui_manager_new ();
        gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
 
diff --git a/src/ui.xml b/src/ui.xml
index 4c5abb1..37242a4 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -20,6 +20,10 @@ In the code, GtkUIManager is used to construct them.
       <menuitem action="EditUndo" />
       <menuitem action="EditRedo" />
     </menu>
+
+    <menu action="View">
+      <menuitem action="ViewLineNumbers" />
+    </menu>
     
     <menu action="LaTeX">
       <menuitem action="compile_latex" />


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