[gnome-builder] navigation: plumb editor save points into navigation list.



commit 3ccea16cf331304e759932425f79790c8daa6d0b
Author: Christian Hergert <christian hergert me>
Date:   Wed Sep 24 16:05:55 2014 -0700

    navigation: plumb editor save points into navigation list.

 src/editor/gb-editor-commands.c        |   39 ++++++++++++++++++++++++++++++-
 src/editor/gb-editor-navigation-item.c |    4 +--
 src/navigation/gb-navigation-item.c    |    5 +--
 src/navigation/gb-navigation-item.h    |    8 +-----
 src/resources/ui/gb-workbench.ui       |    6 +---
 src/workbench/gb-workbench.c           |   13 +++++++++-
 src/workbench/gb-workbench.h           |   10 +++++---
 7 files changed, 62 insertions(+), 23 deletions(-)
---
diff --git a/src/editor/gb-editor-commands.c b/src/editor/gb-editor-commands.c
index d8e3dee..676b4aa 100644
--- a/src/editor/gb-editor-commands.c
+++ b/src/editor/gb-editor-commands.c
@@ -21,12 +21,15 @@
 #include <glib/gi18n.h>
 
 #include "gb-editor-commands.h"
+#include "gb-editor-navigation-item.h"
 #include "gb-editor-tab.h"
 #include "gb-editor-tab-private.h"
 #include "gb-editor-workspace.h"
 #include "gb-editor-workspace-private.h"
 #include "gb-log.h"
+#include "gb-navigation-list.h"
 #include "gb-source-formatter.h"
+#include "gb-workbench.h"
 
 typedef void (*GbEditorCommand) (GbEditorWorkspace *workspace,
                                  GbEditorTab       *tab);
@@ -463,13 +466,46 @@ gb_editor_tab_do_save (GbEditorTab *tab)
    * TODO: Tab needs a state machine for what are valid operations.
    */
 
+  /*
+   * Save the buffer position as an edit point in the global navigation.
+   */
+  {
+    GbWorkbench *workbench;
+    GbNavigationItem *item;
+    GbNavigationList *list = NULL;
+    GtkTextMark *insert;
+    GtkTextIter iter;
+    guint line;
+    guint line_offset;
+
+    workbench = GB_WORKBENCH (gtk_widget_get_toplevel (GTK_WIDGET (priv->source_view)));
+    list = gb_workbench_get_navigation_list (workbench);
+
+    insert = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (priv->document));
+    gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->document),
+                                      &iter, insert);
+    line = gtk_text_iter_get_line (&iter);
+    line_offset = gtk_text_iter_get_line_offset (&iter);
+    item = g_object_new (GB_TYPE_EDITOR_NAVIGATION_ITEM,
+                         "file", gtk_source_file_get_location (priv->file),
+                         "line", line,
+                         "line-offset", line_offset,
+                         NULL);
+    gb_navigation_list_append (list, item);
+  }
+
+  /*
+   * Reset progress bar to 0%.
+   */
   gtk_progress_bar_set_fraction (priv->progress_bar, 0.0);
   gtk_widget_set_opacity (GTK_WIDGET (priv->progress_bar), 1.0);
   gtk_widget_show (GTK_WIDGET (priv->progress_bar));
 
+  /*
+   * Use file saver to save the buffer to disk.
+   */
   saver = gtk_source_file_saver_new (GTK_SOURCE_BUFFER (priv->document),
                                      priv->file);
-
   gtk_source_file_saver_save_async (saver,
                                     G_PRIORITY_DEFAULT,
                                     NULL, /* TODO: Cancellable */
@@ -478,7 +514,6 @@ gb_editor_tab_do_save (GbEditorTab *tab)
                                     NULL,
                                     (GAsyncReadyCallback)on_save_cb,
                                     g_object_ref (tab));
-
   g_object_unref (saver);
 }
 
diff --git a/src/editor/gb-editor-navigation-item.c b/src/editor/gb-editor-navigation-item.c
index 9ece561..8f23c64 100644
--- a/src/editor/gb-editor-navigation-item.c
+++ b/src/editor/gb-editor-navigation-item.c
@@ -114,13 +114,11 @@ gb_editor_navigation_item_set_line_offset (GbEditorNavigationItem *item,
 }
 
 static void
-gb_editor_navigation_item_activate (GbNavigationItem *item,
-                                    GbWorkbench      *workbench)
+gb_editor_navigation_item_activate (GbNavigationItem *item)
 {
   GbEditorNavigationItem *self = (GbEditorNavigationItem *)item;
 
   g_return_if_fail (GB_IS_EDITOR_NAVIGATION_ITEM (self));
-  g_return_if_fail (GB_IS_WORKBENCH (workbench));
 
   g_print ("Activate item\n");
 }
diff --git a/src/navigation/gb-navigation-item.c b/src/navigation/gb-navigation-item.c
index 58ae131..cc35900 100644
--- a/src/navigation/gb-navigation-item.c
+++ b/src/navigation/gb-navigation-item.c
@@ -70,12 +70,11 @@ gb_navigation_item_set_label (GbNavigationItem *item,
 }
 
 void
-gb_navigation_item_emit_activate (GbNavigationItem *item,
-                                  GbWorkbench      *workbench)
+gb_navigation_item_emit_activate (GbNavigationItem *item)
 {
   g_return_if_fail (GB_IS_NAVIGATION_ITEM (item));
   
-  g_signal_emit (item, gSignals [ACTIVATE], 0, workbench);
+  g_signal_emit (item, gSignals [ACTIVATE], 0);
 }
 
 static void
diff --git a/src/navigation/gb-navigation-item.h b/src/navigation/gb-navigation-item.h
index 83a8ab9..b467f06 100644
--- a/src/navigation/gb-navigation-item.h
+++ b/src/navigation/gb-navigation-item.h
@@ -21,8 +21,6 @@
 
 #include <glib-object.h>
 
-#include "gb-workbench.h"
-
 G_BEGIN_DECLS
 
 #define GB_TYPE_NAVIGATION_ITEM            (gb_navigation_item_get_type())
@@ -49,14 +47,12 @@ struct _GbNavigationItemClass
 {
   GInitiallyUnownedClass parent;
   
-  void (*activate) (GbNavigationItem *item,
-                    GbWorkbench      *workbench);
+  void (*activate) (GbNavigationItem *item);
 };
 
 GType             gb_navigation_item_get_type      (void) G_GNUC_CONST;
 GbNavigationItem *gb_navigation_item_new           (const gchar      *label);
-void              gb_navigation_item_emit_activate (GbNavigationItem *item,
-                                                    GbWorkbench      *workbench);
+void              gb_navigation_item_emit_activate (GbNavigationItem *item);
 const gchar      *gb_navigation_item_get_label     (GbNavigationItem *item);
 void              gb_navigation_item_set_label     (GbNavigationItem *item,
                                                     const gchar      *label);
diff --git a/src/resources/ui/gb-workbench.ui b/src/resources/ui/gb-workbench.ui
index db34f5c..1094bd3 100644
--- a/src/resources/ui/gb-workbench.ui
+++ b/src/resources/ui/gb-workbench.ui
@@ -17,9 +17,8 @@
             </style>
             <child>
               <object class="GtkButton" id="back_button">
-                <property name="action-name">workbench.go-backward</property>
+                <property name="action-name">win.go-backward</property>
                 <property name="visible">True</property>
-                <property name="sensitive">False</property>
                 <style>
                   <class name="image-button"/>
                 </style>
@@ -37,9 +36,8 @@
                 <style>
                   <class name="image-button"/>
                 </style>
-                <property name="action-name">workbench.go-forward</property>
+                <property name="action-name">win.go-forward</property>
                 <property name="visible">True</property>
-                <property name="sensitive">False</property>
                 <child>
                   <object class="GtkImage" id="next_buton_image">
                     <property name="visible">True</property>
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 292334b..eafa928 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -23,7 +23,6 @@
 #include "gb-devhelp-workspace.h"
 #include "gb-editor-workspace.h"
 #include "gb-log.h"
-#include "gb-navigation-list.h"
 #include "gb-widget.h"
 #include "gb-workbench.h"
 #include "gb-workbench-actions.h"
@@ -216,6 +215,12 @@ on_go_forward_activate (GSimpleAction *action,
                         GVariant      *variant,
                         gpointer       user_data)
 {
+  GbWorkbench *workbench = user_data;
+
+  g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+  if (gb_navigation_list_get_can_go_forward (workbench->priv->navigation_list))
+    gb_navigation_list_go_forward (workbench->priv->navigation_list);
 }
 
 static void
@@ -223,6 +228,12 @@ on_go_backward_activate (GSimpleAction *action,
                          GVariant      *variant,
                          gpointer       user_data)
 {
+  GbWorkbench *workbench = user_data;
+
+  g_return_if_fail (GB_IS_WORKBENCH (workbench));
+
+  if (gb_navigation_list_get_can_go_backward (workbench->priv->navigation_list))
+    gb_navigation_list_go_backward (workbench->priv->navigation_list);
 }
 
 static void
diff --git a/src/workbench/gb-workbench.h b/src/workbench/gb-workbench.h
index 4de6a6d..368081a 100644
--- a/src/workbench/gb-workbench.h
+++ b/src/workbench/gb-workbench.h
@@ -21,6 +21,7 @@
 
 #include <gtk/gtk.h>
 
+#include "gb-navigation-list.h"
 #include "gb-workspace.h"
 
 G_BEGIN_DECLS
@@ -53,10 +54,11 @@ struct _GbWorkbenchClass
                              GbWorkspace *workspace);
 };
 
-GType        gb_workbench_get_type             (void) G_GNUC_CONST;
-GbWorkspace *gb_workbench_get_active_workspace (GbWorkbench *workbench);
-GbWorkspace *gb_workbench_get_workspace        (GbWorkbench *workbench,
-                                                GType        type);
+GType             gb_workbench_get_type             (void) G_GNUC_CONST;
+GbNavigationList *gb_workbench_get_navigation_list  (GbWorkbench *workbench);
+GbWorkspace      *gb_workbench_get_active_workspace (GbWorkbench *workbench);
+GbWorkspace      *gb_workbench_get_workspace        (GbWorkbench *workbench,
+                                                     GType        type);
 
 G_END_DECLS
 


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