examples: Simplify counting buffer lines

We do have a gtk_text_buffer_get_line_count() function
to get the line count.
This commit is contained in:
Mohammed Sadiq 2018-05-08 21:24:29 +05:30
parent 88ddda6d60
commit 65b423eb05
2 changed files with 2 additions and 20 deletions

View File

@ -134,16 +134,7 @@ update_lines (ExampleAppWindow *win)
view = gtk_bin_get_child (GTK_BIN (tab)); view = gtk_bin_get_child (GTK_BIN (tab));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
count = 0; count = gtk_text_buffer_get_line_count (buffer);
gtk_text_buffer_get_start_iter (buffer, &iter);
while (!gtk_text_iter_is_end (&iter))
{
count++;
if (!gtk_text_iter_forward_line (&iter))
break;
}
lines = g_strdup_printf ("%d", count); lines = g_strdup_printf ("%d", count);
gtk_label_set_text (GTK_LABEL (win->lines), lines); gtk_label_set_text (GTK_LABEL (win->lines), lines);
g_free (lines); g_free (lines);

View File

@ -134,16 +134,7 @@ update_lines (ExampleAppWindow *win)
view = gtk_bin_get_child (GTK_BIN (tab)); view = gtk_bin_get_child (GTK_BIN (tab));
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
count = 0; count = gtk_text_buffer_get_line_count (buffer);
gtk_text_buffer_get_start_iter (buffer, &iter);
while (!gtk_text_iter_is_end (&iter))
{
count++;
if (!gtk_text_iter_forward_line (&iter))
break;
}
lines = g_strdup_printf ("%d", count); lines = g_strdup_printf ("%d", count);
gtk_label_set_text (GTK_LABEL (win->lines), lines); gtk_label_set_text (GTK_LABEL (win->lines), lines);
g_free (lines); g_free (lines);