[gnome-builder] editor: provide line number information in goto-line popover



commit 193d7d96617230e133932a0a220622f2dc782d00
Author: Christian Hergert <christian hergert me>
Date:   Fri Sep 18 16:47:04 2015 -0700

    editor: provide line number information in goto-line popover

 src/editor/gb-editor-view.c |   35 ++++++++++++++++++++++++++++-------
 1 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index a32d811..39232cb 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -558,22 +558,43 @@ static void
 gb_editor_view_goto_line_changed (GbEditorView    *self,
                                   GbSimplePopover *popover)
 {
+  gchar *message;
   const gchar *text;
+  GtkTextIter begin;
+  GtkTextIter end;
 
   g_assert (GB_IS_EDITOR_VIEW (self));
   g_assert (GB_IS_SIMPLE_POPOVER (popover));
 
   text = gb_simple_popover_get_text (popover);
 
-  if (gb_str_empty0 (text))
-    {
-      gb_simple_popover_set_ready (popover, FALSE);
-    }
-  else
+  gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (self->document), &begin, &end);
+
+  if (!gb_str_empty0 (text))
     {
-      /* TODO: check if the line exists */
-      gb_simple_popover_set_ready (popover, TRUE);
+      gint64 value;
+
+      value = g_ascii_strtoll (text, NULL, 10);
+
+      if (value > 0)
+        {
+          if (value <= gtk_text_iter_get_line (&end) + 1)
+            {
+              gb_simple_popover_set_message (popover, NULL);
+              gb_simple_popover_set_ready (popover, TRUE);
+              return;
+            }
+
+        }
     }
+
+  /* translators: the user selected a number outside the value range for the document. */
+  message = g_strdup_printf (_("Provide a number between 1 and %u"),
+                             gtk_text_iter_get_line (&end) + 1);
+  gb_simple_popover_set_message (popover, message);
+  gb_simple_popover_set_ready (popover, FALSE);
+
+  g_free (message);
 }
 
 static void


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