From: Mohammed Sadiq Date: Tue, 8 May 2018 15:54:29 +0000 (+0530) Subject: examples: Simplify counting buffer lines X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~22^2~284 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=65b423eb05ba2e31c57a7f9d029f5312719366d1;p=gtk4.git examples: Simplify counting buffer lines We do have a gtk_text_buffer_get_line_count() function to get the line count. --- diff --git a/examples/application10/exampleappwin.c b/examples/application10/exampleappwin.c index a9311ec5a2..7b0dc46575 100644 --- a/examples/application10/exampleappwin.c +++ b/examples/application10/exampleappwin.c @@ -134,16 +134,7 @@ update_lines (ExampleAppWindow *win) view = gtk_bin_get_child (GTK_BIN (tab)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - count = 0; - - gtk_text_buffer_get_start_iter (buffer, &iter); - while (!gtk_text_iter_is_end (&iter)) - { - count++; - if (!gtk_text_iter_forward_line (&iter)) - break; - } - + count = gtk_text_buffer_get_line_count (buffer); lines = g_strdup_printf ("%d", count); gtk_label_set_text (GTK_LABEL (win->lines), lines); g_free (lines); diff --git a/examples/application9/exampleappwin.c b/examples/application9/exampleappwin.c index 50ad92a4ac..6d6ae980e9 100644 --- a/examples/application9/exampleappwin.c +++ b/examples/application9/exampleappwin.c @@ -134,16 +134,7 @@ update_lines (ExampleAppWindow *win) view = gtk_bin_get_child (GTK_BIN (tab)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - count = 0; - - gtk_text_buffer_get_start_iter (buffer, &iter); - while (!gtk_text_iter_is_end (&iter)) - { - count++; - if (!gtk_text_iter_forward_line (&iter)) - break; - } - + count = gtk_text_buffer_get_line_count (buffer); lines = g_strdup_printf ("%d", count); gtk_label_set_text (GTK_LABEL (win->lines), lines); g_free (lines);