[gnome-builder/wip/chergert/hide-floating-bar] editor: add line:column to top bar of editor views



commit a65f36eb88fab38a22ad7f8223acdb9bd3240803
Author: Christian Hergert <christian hergert me>
Date:   Wed Sep 16 01:13:10 2015 -0700

    editor: add line:column to top bar of editor views
    
    Work is in progress to get rid of the bottom overlay floating bar except
    for when it is needed. This is the first step to getting there.

 data/ui/gb-editor-view.ui           |   33 ++++++++++++++++++++++++
 data/ui/gb-view-stack.ui            |   19 ++++---------
 src/editor/gb-editor-view-private.h |    1 +
 src/editor/gb-editor-view.c         |   48 +++++++++++++++++++++++++++++++++++
 4 files changed, 88 insertions(+), 13 deletions(-)
---
diff --git a/data/ui/gb-editor-view.ui b/data/ui/gb-editor-view.ui
index 39f09c3..8184db1 100644
--- a/data/ui/gb-editor-view.ui
+++ b/data/ui/gb-editor-view.ui
@@ -88,6 +88,39 @@
         <child internal-child="controls">
           <object class="GtkBox">
             <child>
+              <object class="GtkSeparator">
+                <property name="margin-start">3</property>
+                <property name="margin-end">3</property>
+                <property name="margin-top">4</property>
+                <property name="margin-bottom">4</property>
+                <property name="orientation">vertical</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="cursor_label">
+                <property name="label">1:1</property>
+                <property name="valign">baseline</property>
+                <property name="visible">true</property>
+                <style>
+                  <class name="dim-label"/>
+                </style>
+              </object>
+              <packing>
+                <property name="padding">6</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkSeparator">
+                <property name="margin-start">3</property>
+                <property name="margin-end">3</property>
+                <property name="margin-top">4</property>
+                <property name="margin-bottom">4</property>
+                <property name="orientation">vertical</property>
+                <property name="visible">true</property>
+              </object>
+            </child>
+            <child>
               <object class="GtkMenuButton" id="tweak_button">
                 <property name="focus-on-click">false</property>
                 <property name="popover">popover</property>
diff --git a/data/ui/gb-view-stack.ui b/data/ui/gb-view-stack.ui
index 37e0138..6837650 100644
--- a/data/ui/gb-view-stack.ui
+++ b/data/ui/gb-view-stack.ui
@@ -197,6 +197,12 @@
                     <property name="visible">true</property>
                   </object>
                   <packing>
+                    <!--
+                        this padding is to make things line up with header bar.
+                        unfortunately, this was annoying to get right with css.
+                        feel free to come fix it.
+                    -->
+                    <property name="padding">1</property>
                     <property name="pack-type">end</property>
                   </packing>
                 </child>
@@ -209,19 +215,6 @@
                     <property name="pack-type">end</property>
                   </packing>
                 </child>
-                <child>
-                  <object class="GtkSeparator">
-                    <property name="margin-start">3</property>
-                    <property name="margin-end">3</property>
-                    <property name="margin-top">4</property>
-                    <property name="margin-bottom">4</property>
-                    <property name="orientation">vertical</property>
-                    <property name="visible">true</property>
-                  </object>
-                  <packing>
-                    <property name="pack-type">end</property>
-                  </packing>
-                </child>
               </object>
             </child>
           </object>
diff --git a/src/editor/gb-editor-view-private.h b/src/editor/gb-editor-view-private.h
index 4691200..6c278c4 100644
--- a/src/editor/gb-editor-view-private.h
+++ b/src/editor/gb-editor-view-private.h
@@ -38,6 +38,7 @@ struct _GbEditorView
   GSettings           *settings;
   gchar               *title;
 
+  GtkLabel            *cursor_label;
   GbEditorFrame       *frame1;
   GbEditorFrame       *frame2;
   GtkButton           *modified_cancel_button;
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index 80cb75e..445cd71 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -287,6 +287,47 @@ gb_editor_view__buffer_notify_language (GbEditorView     *self,
 }
 
 static void
+gb_editor_view__buffer_cursor_moved (GbEditorView      *self,
+                                     const GtkTextIter *iter,
+                                     GtkTextBuffer     *buffer)
+{
+  GtkTextIter bounds;
+  GtkTextMark *mark;
+  gchar *str;
+  guint line;
+  gint column;
+  gint column2;
+
+  g_assert (GB_IS_EDITOR_VIEW (self));
+  g_assert (iter != NULL);
+  g_assert (IDE_IS_BUFFER (buffer));
+
+  ide_source_view_get_visual_position (self->frame1->source_view, &line, (guint *)&column);
+
+  mark = gtk_text_buffer_get_selection_bound (buffer);
+  gtk_text_buffer_get_iter_at_mark (buffer, &bounds, mark);
+
+  if (!gtk_widget_has_focus (GTK_WIDGET (self->frame1->source_view)) ||
+      gtk_text_iter_equal (&bounds, iter) ||
+      (gtk_text_iter_get_line (iter) != gtk_text_iter_get_line (&bounds)))
+    {
+      str = g_strdup_printf ("%d:%d", line + 1, column + 1);
+      gtk_label_set_text (self->cursor_label, str);
+      g_free (str);
+      return;
+    }
+
+  /* We have a selection that is on the same line.
+   * Lets give some detail as to how long the selection is.
+   */
+  column2 = gtk_source_view_get_visual_column (GTK_SOURCE_VIEW (self->frame1->source_view),
+                                               &bounds);
+  str = g_strdup_printf ("%d:%d (%d)", line + 1, column + 1, ABS (column2 - column));
+  gtk_label_set_text (self->cursor_label, str);
+  g_free (str);
+}
+
+static void
 gb_editor_view_set_document (GbEditorView     *self,
                              GbEditorDocument *document)
 {
@@ -308,6 +349,12 @@ gb_editor_view_set_document (GbEditorView     *self,
                        document, "highlight-matching-brackets",
                        G_SETTINGS_BIND_GET);
 
+      g_signal_connect_object (document,
+                               "cursor-moved",
+                               G_CALLBACK (gb_editor_view__buffer_cursor_moved),
+                               self,
+                               G_CONNECT_SWAPPED);
+
       g_object_bind_property_full (document, "language", self->tweak_button,
                                    "label", G_BINDING_SYNC_CREATE,
                                    language_to_string, NULL, NULL, NULL);
@@ -614,6 +661,7 @@ gb_editor_view_class_init (GbEditorViewClass *klass)
 
   GB_WIDGET_CLASS_TEMPLATE (klass, "gb-editor-view.ui");
 
+  GB_WIDGET_CLASS_BIND (klass, GbEditorView, cursor_label);
   GB_WIDGET_CLASS_BIND (klass, GbEditorView, frame1);
   GB_WIDGET_CLASS_BIND (klass, GbEditorView, modified_cancel_button);
   GB_WIDGET_CLASS_BIND (klass, GbEditorView, modified_revealer);


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