[gnome-builder] Tab, View: track changes from tabs to views.



commit e0ba9bd99b9df1cef3d84d0fa811d5d4ee063e7e
Author: Christian Hergert <christian hergert me>
Date:   Wed Dec 10 00:26:32 2014 -0800

    Tab, View: track changes from tabs to views.
    
    This gets vim commands working again for instance.

 src/commands/gb-command-gaction-provider.c |    8 ++--
 src/commands/gb-command-provider.c         |   71 ++++++++++++++-------------
 src/commands/gb-command-provider.h         |   26 +++++-----
 src/commands/gb-command-vim-provider.c     |   20 +++++--
 src/commands/gb-command-vim.c              |   73 +++++++++++++---------------
 5 files changed, 101 insertions(+), 97 deletions(-)
---
diff --git a/src/commands/gb-command-gaction-provider.c b/src/commands/gb-command-gaction-provider.c
index 1d7ae0b..2a63558 100644
--- a/src/commands/gb-command-gaction-provider.c
+++ b/src/commands/gb-command-gaction-provider.c
@@ -104,7 +104,7 @@ gb_command_gaction_provider_lookup (GbCommandProvider *provider,
    *       ApplicationWindow which is a GActionMap.
    */
 
-  widget = GTK_WIDGET (gb_command_provider_get_active_tab (provider));
+  widget = GTK_WIDGET (gb_command_provider_get_active_view (provider));
   while (widget)
     {
       if (G_IS_ACTION_MAP (widget))
@@ -119,7 +119,7 @@ gb_command_gaction_provider_lookup (GbCommandProvider *provider,
 
   /*
    * Now try to lookup the action from the workspace up, which is the case if
-   * we don't have an active tab.
+   * we don't have an active view.
    */
   if (!action)
     {
@@ -236,7 +236,7 @@ gb_command_gaction_provider_complete (GbCommandProvider *provider,
 
   prefix = g_strndup (initial_command_text, tmp - initial_command_text);
 
-  widget = GTK_WIDGET (gb_command_provider_get_active_tab (provider));
+  widget = GTK_WIDGET (gb_command_provider_get_active_view (provider));
   while (widget)
     {
       if (G_IS_ACTION_GROUP (widget))
@@ -247,7 +247,7 @@ gb_command_gaction_provider_complete (GbCommandProvider *provider,
 
   /*
    * Now try to lookup the action from the workspace up, which is the case if
-   * we don't have an active tab.
+   * we don't have an active view.
    */
   workbench = gb_command_provider_get_workbench (provider);
   workspace = gb_workbench_get_active_workspace (workbench);
diff --git a/src/commands/gb-command-provider.c b/src/commands/gb-command-provider.c
index 1c65f86..d7c5380 100644
--- a/src/commands/gb-command-provider.c
+++ b/src/commands/gb-command-provider.c
@@ -22,9 +22,9 @@
 
 struct _GbCommandProviderPrivate
 {
-  GbWorkbench *workbench;
-  GbTab       *active_tab;
-  gint         priority;
+  GbWorkbench    *workbench;
+  GbDocumentView *active_view;
+  gint            priority;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GbCommandProvider, gb_command_provider,
@@ -32,7 +32,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GbCommandProvider, gb_command_provider,
 
 enum {
   PROP_0,
-  PROP_ACTIVE_TAB,
+  PROP_ACTIVE_VIEW,
   PROP_PRIORITY,
   PROP_WORKBENCH,
   LAST_PROP
@@ -56,48 +56,48 @@ gb_command_provider_new (GbWorkbench *workbench)
 }
 
 /**
- * gb_command_provider_get_active_tab:
+ * gb_command_provider_get_active_view:
  *
  * Returns the "active-tab" property. The active-tab is the last tab that
  * was focused in the workbench.
  *
- * Returns: (transfer none): A #GbTab or %NULL.
+ * Returns: (transfer none): A #GbDocumentView or %NULL.
  */
-GbTab *
-gb_command_provider_get_active_tab (GbCommandProvider *provider)
+GbDocumentView *
+gb_command_provider_get_active_view (GbCommandProvider *provider)
 {
   g_return_val_if_fail (GB_IS_COMMAND_PROVIDER (provider), NULL);
 
-  return provider->priv->active_tab;
+  return provider->priv->active_view;
 }
 
 static void
-gb_command_provider_set_active_tab (GbCommandProvider *provider,
-                                    GbTab             *tab)
+gb_command_provider_set_active_view (GbCommandProvider *provider,
+                                    GbDocumentView             *tab)
 {
   GbCommandProviderPrivate *priv;
 
   g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider));
-  g_return_if_fail (!tab || GB_IS_TAB (tab));
+  g_return_if_fail (!tab || GB_IS_DOCUMENT_VIEW (tab));
 
   priv = provider->priv;
 
-  if (priv->active_tab)
+  if (priv->active_view)
     {
-      g_object_remove_weak_pointer (G_OBJECT (priv->active_tab),
-                                    (gpointer *)&priv->active_tab);
-      priv->active_tab = NULL;
+      g_object_remove_weak_pointer (G_OBJECT (priv->active_view),
+                                    (gpointer *)&priv->active_view);
+      priv->active_view = NULL;
     }
 
   if (tab)
     {
-      priv->active_tab = tab;
-      g_object_add_weak_pointer (G_OBJECT (priv->active_tab),
-                                 (gpointer *)&priv->active_tab);
+      priv->active_view = tab;
+      g_object_add_weak_pointer (G_OBJECT (priv->active_view),
+                                 (gpointer *)&priv->active_view);
     }
 
   g_object_notify_by_pspec (G_OBJECT (provider),
-                            gParamSpecs [PROP_ACTIVE_TAB]);
+                            gParamSpecs [PROP_ACTIVE_VIEW]);
 }
 
 static void
@@ -111,12 +111,13 @@ on_workbench_set_focus (GbCommandProvider *provider,
 
   /* walk the hierarchy to find a tab */
   if (widget)
-    while (!GB_IS_TAB (widget))
+    while (!GB_IS_DOCUMENT_VIEW (widget))
       if (!(widget = gtk_widget_get_parent (widget)))
         break;
 
-  if (GB_IS_TAB (widget))
-    gb_command_provider_set_active_tab (provider, GB_TAB (widget));
+  if (GB_IS_DOCUMENT_VIEW (widget))
+    gb_command_provider_set_active_view (provider,
+                                         GB_DOCUMENT_VIEW (widget));
 }
 
 static void
@@ -173,7 +174,7 @@ gb_command_provider_set_workbench (GbCommandProvider *provider,
                                         (gpointer *)&priv->workbench);
           priv->workbench = NULL;
         }
-    
+
       if (workbench)
         {
           priv->workbench = workbench;
@@ -181,7 +182,7 @@ gb_command_provider_set_workbench (GbCommandProvider *provider,
                                      (gpointer *)&priv->workbench);
           gb_command_provider_connect (provider, workbench);
         }
-    
+
       g_object_notify_by_pspec (G_OBJECT (provider),
                                 gParamSpecs [PROP_WORKBENCH]);
   }
@@ -261,8 +262,8 @@ gb_command_provider_get_property (GObject    *object,
 
   switch (prop_id)
     {
-    case PROP_ACTIVE_TAB:
-      g_value_set_object (value, gb_command_provider_get_active_tab (self));
+    case PROP_ACTIVE_VIEW:
+      g_value_set_object (value, gb_command_provider_get_active_view (self));
       break;
 
     case PROP_PRIORITY:
@@ -309,15 +310,15 @@ gb_command_provider_class_init (GbCommandProviderClass *klass)
   object_class->get_property = gb_command_provider_get_property;
   object_class->set_property = gb_command_provider_set_property;
 
-  gParamSpecs [PROP_ACTIVE_TAB] =
+  gParamSpecs [PROP_ACTIVE_VIEW] =
     g_param_spec_object ("active-tab",
-                         _("Active Tab"),
-                         _("The last focused GbTab widget."),
-                         GB_TYPE_TAB,
+                         _("Active DocumentView"),
+                         _("The last focused GbDocumentView widget."),
+                         GB_TYPE_DOCUMENT_VIEW,
                          (G_PARAM_READABLE |
                           G_PARAM_STATIC_STRINGS));
-  g_object_class_install_property (object_class, PROP_ACTIVE_TAB,
-                                   gParamSpecs [PROP_ACTIVE_TAB]);
+  g_object_class_install_property (object_class, PROP_ACTIVE_VIEW,
+                                   gParamSpecs [PROP_ACTIVE_VIEW]);
 
   /**
    * GbCommandProvider:priority:
@@ -344,7 +345,7 @@ gb_command_provider_class_init (GbCommandProviderClass *klass)
 
   /**
    * GbCommandProvider:workbench:
-   * 
+   *
    * The "workbench" property is the top-level window containing our project
    * and the workbench to work on it. It keeps track of the last focused tab
    * for convenience by action providers.
@@ -368,7 +369,7 @@ gb_command_provider_class_init (GbCommandProviderClass *klass)
    * This signal is emitted when a request to parse the command text is
    * received. Only the first handler will respond to the action. The
    * callee should return a GAction if successful, otherwise %NULL.
-   * 
+   *
    * If successful, the callee can set @parameter, to specify the
    * parameters that should be passed to the resulting action.
    */
diff --git a/src/commands/gb-command-provider.h b/src/commands/gb-command-provider.h
index 2ba5ae5..c636f6d 100644
--- a/src/commands/gb-command-provider.h
+++ b/src/commands/gb-command-provider.h
@@ -22,7 +22,7 @@
 #include <gio/gio.h>
 
 #include "gb-command.h"
-#include "gb-tab.h"
+#include "gb-document-view.h"
 #include "gb-workbench.h"
 
 G_BEGIN_DECLS
@@ -58,18 +58,18 @@ struct _GbCommandProviderClass
                           const gchar       *command_text);
 };
 
-GType              gb_command_provider_get_type       (void) G_GNUC_CONST;
-GbCommandProvider *gb_command_provider_new            (GbWorkbench       *workbench);
-GbWorkbench       *gb_command_provider_get_workbench  (GbCommandProvider *provider);
-GbTab             *gb_command_provider_get_active_tab (GbCommandProvider *provider);
-gint               gb_command_provider_get_priority   (GbCommandProvider *provider);
-void               gb_command_provider_set_priority   (GbCommandProvider *provider,
-                                                       gint               priority);
-GbCommand         *gb_command_provider_lookup         (GbCommandProvider *provider,
-                                                       const gchar       *command_text);
-void               gb_command_provider_complete      (GbCommandProvider  *provider,
-                                                      GPtrArray          *completions,
-                                                      const gchar        *initial_command_text);
+GType              gb_command_provider_get_type        (void);
+GbCommandProvider *gb_command_provider_new             (GbWorkbench       *workbench);
+GbWorkbench       *gb_command_provider_get_workbench   (GbCommandProvider *provider);
+GbDocumentView    *gb_command_provider_get_active_view (GbCommandProvider *provider);
+gint               gb_command_provider_get_priority    (GbCommandProvider *provider);
+void               gb_command_provider_set_priority    (GbCommandProvider *provider,
+                                                        gint               priority);
+GbCommand         *gb_command_provider_lookup          (GbCommandProvider *provider,
+                                                        const gchar       *command_text);
+void               gb_command_provider_complete        (GbCommandProvider *provider,
+                                                        GPtrArray         *completions,
+                                                        const gchar       *initial_command_text);
 
 G_END_DECLS
 
diff --git a/src/commands/gb-command-vim-provider.c b/src/commands/gb-command-vim-provider.c
index 0c3a519..0842ab0 100644
--- a/src/commands/gb-command-vim-provider.c
+++ b/src/commands/gb-command-vim-provider.c
@@ -18,9 +18,11 @@
 
 #define G_LOG_DOMAIN "vim-command-provider"
 
+#include "gb-editor-view.h"
+#include "gb-editor-frame-private.h"
 #include "gb-command-vim.h"
 #include "gb-command-vim-provider.h"
-#include "gb-editor-tab.h"
+#include "gb-source-view.h"
 #include "gb-source-vim.h"
 
 G_DEFINE_TYPE (GbCommandVimProvider, gb_command_vim_provider,
@@ -40,7 +42,8 @@ gb_command_vim_provider_lookup (GbCommandProvider *provider,
 {
   GbWorkbench *workbench;
   GSettings *settings;
-  GbTab *active_tab;
+  GbDocumentView *active_view;
+  GbEditorFrame *frame;
 
   g_return_val_if_fail (GB_IS_COMMAND_VIM_PROVIDER (provider), NULL);
   g_return_val_if_fail (command_text, NULL);
@@ -53,22 +56,27 @@ gb_command_vim_provider_lookup (GbCommandProvider *provider,
   /* Make sure vim-mode is enabled */
   if (!g_settings_get_boolean (settings, "vim-mode"))
     return NULL;
-  
+
   /* Make sure we have a workbench */
   workbench = gb_command_provider_get_workbench (provider);
   if (!GB_IS_WORKBENCH (workbench))
     return NULL;
 
   /* Make sure we have an editor tab last focused */
-  active_tab = gb_command_provider_get_active_tab (provider);
-  if (!GB_IS_EDITOR_TAB (active_tab))
+  active_view = gb_command_provider_get_active_view (provider);
+  if (!GB_IS_EDITOR_VIEW (active_view))
+    return NULL;
+
+  /* TODO: Perhaps get the last focused frame? */
+  frame = gb_editor_view_get_frame1 (GB_EDITOR_VIEW (active_view));
+  if (!GB_IS_EDITOR_FRAME (frame))
     return NULL;
 
   /* See if GbEditorVim recognizes this command */
   if (gb_source_vim_is_command (command_text))
     return g_object_new (GB_TYPE_COMMAND_VIM,
                          "command-text", command_text,
-                         "tab", active_tab,
+                         "source-view", frame->priv->source_view,
                          NULL);
 
   return NULL;
diff --git a/src/commands/gb-command-vim.c b/src/commands/gb-command-vim.c
index f96520e..daee4a5 100644
--- a/src/commands/gb-command-vim.c
+++ b/src/commands/gb-command-vim.c
@@ -19,15 +19,12 @@
 #include <glib/gi18n.h>
 
 #include "gb-command-vim.h"
-#include "gb-editor-frame-private.h"
-#include "gb-editor-tab.h"
-#include "gb-editor-tab-private.h"
-#include "gb-source-vim.h"
+#include "gb-source-view.h"
 
 struct _GbCommandVimPrivate
 {
-  GbEditorTab *tab;
-  gchar       *command_text;
+  GbSourceView *source_view;
+  gchar        *command_text;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GbCommandVim, gb_command_vim, GB_TYPE_COMMAND)
@@ -35,44 +32,44 @@ G_DEFINE_TYPE_WITH_PRIVATE (GbCommandVim, gb_command_vim, GB_TYPE_COMMAND)
 enum {
   PROP_0,
   PROP_COMMAND_TEXT,
-  PROP_TAB,
+  PROP_SOURCE_VIEW,
   LAST_PROP
 };
 
 static GParamSpec *gParamSpecs [LAST_PROP];
 
-GbEditorTab *
-gb_command_vim_get_tab (GbCommandVim *vim)
+GbSourceView *
+gb_command_vim_get_source_view (GbCommandVim *vim)
 {
   g_return_val_if_fail (GB_IS_COMMAND_VIM (vim), NULL);
 
-  return vim->priv->tab;
+  return vim->priv->source_view;
 }
 
 static void
-gb_command_vim_set_tab (GbCommandVim *vim,
-                        GbEditorTab  *tab)
+gb_command_vim_set_source_view (GbCommandVim *vim,
+                                GbSourceView *source_view)
 {
   g_return_if_fail (GB_IS_COMMAND_VIM (vim));
-  g_return_if_fail (!tab || GB_IS_EDITOR_TAB (tab));
+  g_return_if_fail (!source_view || GB_IS_SOURCE_VIEW (source_view));
 
-  if (tab != vim->priv->tab)
+  if (source_view != vim->priv->source_view)
     {
-      if (vim->priv->tab)
+      if (vim->priv->source_view)
         {
-          g_object_remove_weak_pointer (G_OBJECT (vim->priv->tab),
-                                        (gpointer *)&vim->priv->tab);
-          vim->priv->tab = NULL;
+          g_object_remove_weak_pointer (G_OBJECT (vim->priv->source_view),
+                                        (gpointer *)&vim->priv->source_view);
+          vim->priv->source_view = NULL;
         }
 
-      if (tab)
+      if (source_view)
         {
-          vim->priv->tab = tab;
-          g_object_add_weak_pointer (G_OBJECT (vim->priv->tab),
-                                     (gpointer *)&vim->priv->tab);
+          vim->priv->source_view = source_view;
+          g_object_add_weak_pointer (G_OBJECT (vim->priv->source_view),
+                                     (gpointer *)&vim->priv->source_view);
         }
 
-      g_object_notify_by_pspec (G_OBJECT (vim), gParamSpecs [PROP_TAB]);
+      g_object_notify_by_pspec (G_OBJECT (vim), gParamSpecs [PROP_SOURCE_VIEW]);
     }
 }
 
@@ -107,13 +104,11 @@ gb_command_vim_execute (GbCommand *command)
 
   g_return_val_if_fail (GB_IS_COMMAND_VIM (self), NULL);
 
-  if (self->priv->tab && self->priv->command_text)
+  if (self->priv->source_view)
     {
       GbSourceVim *vim;
-      GbEditorFrame *frame;
 
-      frame = gb_editor_tab_get_last_frame (self->priv->tab);
-      vim = gb_source_view_get_vim (frame->priv->source_view);
+      vim = gb_source_view_get_vim (self->priv->source_view);
       gb_source_vim_execute_command (vim, self->priv->command_text);
     }
 
@@ -125,7 +120,7 @@ gb_command_vim_finalize (GObject *object)
 {
   GbCommandVimPrivate *priv = GB_COMMAND_VIM (object)->priv;
 
-  gb_command_vim_set_tab (GB_COMMAND_VIM (object), NULL);
+  gb_command_vim_set_source_view (GB_COMMAND_VIM (object), NULL);
   g_clear_pointer (&priv->command_text, g_free);
 
   G_OBJECT_CLASS (gb_command_vim_parent_class)->finalize (object);
@@ -145,8 +140,8 @@ gb_command_vim_get_property (GObject    *object,
       g_value_set_string (value, gb_command_vim_get_command_text (self));
       break;
 
-    case PROP_TAB:
-      g_value_set_object (value, gb_command_vim_get_tab (self));
+    case PROP_SOURCE_VIEW:
+      g_value_set_object (value, gb_command_vim_get_source_view (self));
       break;
 
     default:
@@ -168,8 +163,8 @@ gb_command_vim_set_property (GObject      *object,
       gb_command_vim_set_command_text (self, g_value_get_string (value));
       break;
 
-    case PROP_TAB:
-      gb_command_vim_set_tab (self, g_value_get_object (value));
+    case PROP_SOURCE_VIEW:
+      gb_command_vim_set_source_view (self, g_value_get_object (value));
       break;
 
     default:
@@ -199,15 +194,15 @@ gb_command_vim_class_init (GbCommandVimClass *klass)
   g_object_class_install_property (object_class, PROP_COMMAND_TEXT,
                                    gParamSpecs [PROP_COMMAND_TEXT]);
 
-  gParamSpecs [PROP_TAB] =
-    g_param_spec_object ("tab",
-                         _("Tab"),
-                         _("The editor tab to modify."),
-                         GB_TYPE_EDITOR_TAB,
+  gParamSpecs [PROP_SOURCE_VIEW] =
+    g_param_spec_object ("source-view",
+                         _("Source View"),
+                         _("The source view to modify."),
+                         GB_TYPE_SOURCE_VIEW,
                          (G_PARAM_READWRITE |
                           G_PARAM_STATIC_STRINGS));
-  g_object_class_install_property (object_class, PROP_TAB,
-                                   gParamSpecs [PROP_TAB]);
+  g_object_class_install_property (object_class, PROP_SOURCE_VIEW,
+                                   gParamSpecs [PROP_SOURCE_VIEW]);
 }
 
 static void


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