[gtk/wip/sadiq/fixes] examples: Simplify counting buffer lines



commit bc606a1c99ea24cb709440d4ce430fca7a551f69
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date:   Tue May 8 21:24:29 2018 +0530

    examples: Simplify counting buffer lines
    
    We do have a gtk_text_buffer_get_line_count() function
    to get the line count.x

 examples/application10/exampleappwin.c | 11 +----------
 examples/application9/exampleappwin.c  | 11 +----------
 2 files changed, 2 insertions(+), 20 deletions(-)
---
diff --git a/examples/application10/exampleappwin.c b/examples/application10/exampleappwin.c
index d5933d1e9e..dbc9c334b7 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 8aebf1a7a5..83cbd05993 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);


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