[gtksourceview/wip/update-test-widget: 2/2] test-widget: continue the clean-up



commit cde69dd893a341d217a5c7332e730b26c32f0cce
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Sep 1 18:59:08 2013 +0200

    test-widget: continue the clean-up

 tests/test-widget.c |   97 +++++++++++++++++++++++++++++---------------------
 1 files changed, 56 insertions(+), 41 deletions(-)
---
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 48115d3..e16a81d 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -464,7 +464,8 @@ open_file (GtkSourceBuffer *buffer,
 /* View action callbacks -------------------------------------------------------- */
 
 static void
-numbers_toggled_cb (GtkAction *action, gpointer user_data)
+numbers_toggled_cb (GtkAction *action,
+                   gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_source_view_set_show_line_numbers (
@@ -473,7 +474,8 @@ numbers_toggled_cb (GtkAction *action, gpointer user_data)
 }
 
 static void
-marks_toggled_cb (GtkAction *action, gpointer user_data)
+marks_toggled_cb (GtkAction *action,
+                 gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_source_view_set_show_line_marks (
@@ -482,7 +484,8 @@ marks_toggled_cb (GtkAction *action, gpointer user_data)
 }
 
 static void
-margin_toggled_cb (GtkAction *action, gpointer user_data)
+margin_toggled_cb (GtkAction *action,
+                  gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_source_view_set_show_right_margin (
@@ -491,7 +494,8 @@ margin_toggled_cb (GtkAction *action, gpointer user_data)
 }
 
 static void
-hl_syntax_toggled_cb (GtkAction *action, gpointer user_data)
+hl_syntax_toggled_cb (GtkAction *action,
+                     gpointer   user_data)
 {
        GtkTextBuffer *buffer;
        g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
@@ -502,7 +506,8 @@ hl_syntax_toggled_cb (GtkAction *action, gpointer user_data)
 }
 
 static void
-hl_bracket_toggled_cb (GtkAction *action, gpointer user_data)
+hl_bracket_toggled_cb (GtkAction *action,
+                      gpointer   user_data)
 {
        GtkTextBuffer *buffer;
        g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
@@ -513,7 +518,8 @@ hl_bracket_toggled_cb (GtkAction *action, gpointer user_data)
 }
 
 static void
-hl_line_toggled_cb (GtkAction *action, gpointer user_data)
+hl_line_toggled_cb (GtkAction *action,
+                   gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_source_view_set_highlight_current_line (
@@ -522,7 +528,8 @@ hl_line_toggled_cb (GtkAction *action, gpointer user_data)
 }
 
 static void
-draw_spaces_toggled_cb (GtkAction *action, gpointer user_data)
+draw_spaces_toggled_cb (GtkAction *action,
+                       gpointer   user_data)
 {
        gboolean draw_spaces;
 
@@ -530,15 +537,20 @@ draw_spaces_toggled_cb (GtkAction *action, gpointer user_data)
        draw_spaces = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
 
        if (draw_spaces)
+       {
                gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (user_data),
                                                 GTK_SOURCE_DRAW_SPACES_ALL);
+       }
        else
+       {
                gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (user_data),
                                                 0);
+       }
 }
 
 static void
-wrap_lines_toggled_cb (GtkAction *action, gpointer user_data)
+wrap_lines_toggled_cb (GtkAction *action,
+                      gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_TOGGLE_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_text_view_set_wrap_mode (user_data,
@@ -569,7 +581,7 @@ insert_spaces_toggled_cb (GtkAction *action,
 static void
 tabs_toggled_cb (GtkAction *action,
                 GtkAction *current,
-                gpointer user_data)
+                gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_RADIO_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_source_view_set_tab_width (
@@ -580,7 +592,7 @@ tabs_toggled_cb (GtkAction *action,
 static void
 indent_toggled_cb (GtkAction *action,
                   GtkAction *current,
-                  gpointer user_data)
+                  gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_RADIO_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_source_view_set_indent_width (
@@ -591,7 +603,7 @@ indent_toggled_cb (GtkAction *action,
 static void
 smart_home_end_toggled_cb (GtkAction *action,
                           GtkAction *current,
-                          gpointer user_data)
+                          gpointer   user_data)
 {
        g_return_if_fail (GTK_IS_RADIO_ACTION (action) && GTK_SOURCE_IS_VIEW (user_data));
        gtk_source_view_set_smart_home_end (
@@ -600,7 +612,8 @@ smart_home_end_toggled_cb (GtkAction *action,
 }
 
 static void
-new_view_cb (GtkAction *action, gpointer user_data)
+new_view_cb (GtkAction *action,
+            gpointer   user_data)
 {
        GtkSourceBuffer *buffer;
        GtkSourceView *view;
@@ -675,7 +688,8 @@ backward_string_cb (GtkAction *action,
 /* Buffer action callbacks ------------------------------------------------------------ */
 
 static void
-open_file_cb (GtkAction *action, gpointer user_data)
+open_file_cb (GtkAction *action,
+             gpointer   user_data)
 {
        GtkWidget *chooser;
        gint response;
@@ -844,7 +858,8 @@ end_print (GtkPrintOperation        *operation,
 
 
 static void
-print_file_cb (GtkAction *action, gpointer user_data)
+print_file_cb (GtkAction *action,
+              gpointer   user_data)
 {
        GtkSourceView *view;
        GtkSourceBuffer *buffer;
@@ -933,22 +948,18 @@ print_file_cb (GtkAction *action, gpointer user_data)
 /* View UI callbacks ------------------------------------------------------------------ */
 
 static void
-update_cursor_position (GtkTextBuffer *buffer, gpointer user_data)
+update_cursor_position_info (GtkTextBuffer *buffer,
+                            GtkSourceView *view)
 {
        gchar *msg;
-       gint row, chars;
+       gint row;
+       gint chars;
        guint col;
        GtkTextIter iter;
-       GtkSourceView *view;
        GtkLabel *pos_label;
        gchar **classes;
        gchar **classes_ptr;
-       GString *str;
-
-       g_return_if_fail (GTK_SOURCE_IS_VIEW (user_data));
-
-       view = GTK_SOURCE_VIEW (user_data);
-       pos_label = GTK_LABEL (g_object_get_data (G_OBJECT (view), "pos_label"));
+       GString *classes_str;
 
        gtk_text_buffer_get_iter_at_mark (buffer,
                                          &iter,
@@ -961,39 +972,43 @@ update_cursor_position (GtkTextBuffer *buffer, gpointer user_data)
        classes = gtk_source_buffer_get_context_classes_at_iter (GTK_SOURCE_BUFFER (buffer),
                                                                 &iter);
 
-       str = g_string_new ("");
-       classes_ptr = classes;
+       classes_str = g_string_new ("");
 
-       while (classes_ptr && *classes_ptr)
+       for (classes_ptr = classes; classes_ptr != NULL && *classes_ptr != NULL; classes_ptr++)
        {
                if (classes_ptr != classes)
                {
-                       g_string_append (str, ", ");
+                       g_string_append (classes_str, ", ");
                }
 
-               g_string_append_printf (str, "%s", *classes_ptr);
-               ++classes_ptr;
+               g_string_append_printf (classes_str, "%s", *classes_ptr);
        }
 
        g_strfreev (classes);
 
-       msg = g_strdup_printf ("char: %d, line: %d, column: %d, classes: %s", chars, row, col, str->str);
+       msg = g_strdup_printf ("char: %d, line: %d, column: %u, classes: %s",
+                              chars,
+                              row,
+                              col,
+                              classes_str->str);
+
+       pos_label = GTK_LABEL (g_object_get_data (G_OBJECT (view), "pos_label"));
        gtk_label_set_text (pos_label, msg);
 
        g_free (msg);
-       g_string_free (str, TRUE);
+       g_string_free (classes_str, TRUE);
 }
 
 static void
-move_cursor_cb (GtkTextBuffer *buffer,
-               GtkTextIter   *cursoriter,
-               GtkTextMark   *mark,
-               gpointer       user_data)
+mark_set_cb (GtkTextBuffer *buffer,
+            GtkTextIter   *cursoriter,
+            GtkTextMark   *mark,
+            GtkSourceView *view)
 {
-       if (mark != gtk_text_buffer_get_insert (buffer))
-               return;
-
-       update_cursor_position (buffer, user_data);
+       if (mark == gtk_text_buffer_get_insert (buffer))
+       {
+               update_cursor_position_info (buffer, view);
+       }
 }
 
 static gboolean
@@ -1187,8 +1202,8 @@ create_view_window (GtkSourceBuffer *buffer, GtkSourceView *from)
        if (style_scheme)
                gtk_source_buffer_set_style_scheme (buffer, style_scheme);
 
-       g_signal_connect (buffer, "mark-set", G_CALLBACK (move_cursor_cb), view);
-       g_signal_connect (buffer, "changed", G_CALLBACK (update_cursor_position), view);
+       g_signal_connect (buffer, "mark-set", G_CALLBACK (mark_set_cb), view);
+       g_signal_connect (buffer, "changed", G_CALLBACK (update_cursor_position_info), view);
        g_signal_connect (view, "line-mark-activated", G_CALLBACK (line_mark_activated), view);
        g_signal_connect (window, "delete-event", (GCallback) window_deleted_cb, view);
        g_signal_connect (buffer, "bracket-matched", G_CALLBACK (bracket_matched), 0);


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