[gnome-builder] workbench: add IdeWorkbench:visible-perspective-name



commit c34b04c3b488bd010504681f011d3bf576447b1c
Author: Christian Hergert <chergert redhat com>
Date:   Wed Nov 11 00:01:44 2015 -0800

    workbench: add IdeWorkbench:visible-perspective-name
    
    Similar to GtkStack:visible-child-name

 libide/ide-workbench.c |   55 ++++++++++++++++++++++++++++++++++++
 libide/ide-workbench.h |   73 +++++++++++++++++++++++++-----------------------
 2 files changed, 93 insertions(+), 35 deletions(-)
---
diff --git a/libide/ide-workbench.c b/libide/ide-workbench.c
index 748aa4c..beb058e 100644
--- a/libide/ide-workbench.c
+++ b/libide/ide-workbench.c
@@ -30,6 +30,7 @@ G_DEFINE_TYPE (IdeWorkbench, ide_workbench, GTK_TYPE_APPLICATION_WINDOW)
 enum {
   PROP_0,
   PROP_VISIBLE_PERSPECTIVE,
+  PROP_VISIBLE_PERSPECTIVE_NAME,
   LAST_PROP
 };
 
@@ -104,6 +105,10 @@ ide_workbench_get_property (GObject    *object,
       g_value_set_object (value, ide_workbench_get_visible_perspective (self));
       break;
 
+    case PROP_VISIBLE_PERSPECTIVE_NAME:
+      g_value_set_string (value, ide_workbench_get_visible_perspective_name (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -123,6 +128,10 @@ ide_workbench_set_property (GObject      *object,
       ide_workbench_set_visible_perspective (self, g_value_get_object (value));
       break;
 
+    case PROP_VISIBLE_PERSPECTIVE_NAME:
+      ide_workbench_set_visible_perspective_name (self, g_value_get_string (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -148,6 +157,13 @@ ide_workbench_class_init (IdeWorkbenchClass *klass)
                          IDE_TYPE_PERSPECTIVE,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_VISIBLE_PERSPECTIVE_NAME] =
+    g_param_spec_string ("visible-perspective-name",
+                         "visible-Perspective-name",
+                         "visible-Perspective-name",
+                         NULL,
+                         (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, LAST_PROP, properties);
 
   gtk_widget_class_set_css_name (widget_class, "workbench");
@@ -479,3 +495,42 @@ ide_workbench_set_visible_perspective (IdeWorkbench   *self,
 
   g_free (id);
 }
+
+const gchar *
+ide_workbench_get_visible_perspective_name (IdeWorkbench *self)
+{
+  IdePerspective *perspective;
+
+  g_return_val_if_fail (IDE_IS_WORKBENCH (self), NULL);
+
+  perspective = ide_workbench_get_visible_perspective (self);
+
+  if (perspective != NULL)
+    {
+      GtkWidget *parent;
+
+      /*
+       * Normally we would call ide_perspective_get_id(), but we want to be
+       * able to return a const gchar*. So instead we just use the registered
+       * name in the stack, which is the same thing.
+       */
+      parent = gtk_widget_get_parent (GTK_WIDGET (perspective));
+      return gtk_stack_get_visible_child_name (GTK_STACK (parent));
+    }
+
+  return NULL;
+}
+
+void
+ide_workbench_set_visible_perspective_name (IdeWorkbench *self,
+                                            const gchar  *name)
+{
+  IdePerspective *perspective;
+
+  g_return_if_fail (IDE_IS_WORKBENCH (self));
+  g_return_if_fail (name != NULL);
+
+  perspective = ide_workbench_get_perspective_by_name (self, name);
+  if (perspective != NULL)
+    ide_workbench_set_visible_perspective (self, perspective);
+}
diff --git a/libide/ide-workbench.h b/libide/ide-workbench.h
index d58829b..007afe6 100644
--- a/libide/ide-workbench.h
+++ b/libide/ide-workbench.h
@@ -30,41 +30,44 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (IdeWorkbench, ide_workbench, IDE, WORKBENCH, GtkApplicationWindow)
 
-void            ide_workbench_open_async                 (IdeWorkbench         *self,
-                                                          GFile               **files,
-                                                          gint                  n_files,
-                                                          GCancellable         *cancellable,
-                                                          GAsyncReadyCallback   callback,
-                                                          gpointer              user_data);
-gboolean        ide_workbench_open_finish                (IdeWorkbench         *self,
-                                                          GAsyncResult         *result,
-                                                          GError              **error);
-void            ide_workbench_save_all_async             (IdeWorkbench         *self,
-                                                          GCancellable         *cancellable,
-                                                          GAsyncReadyCallback   callback,
-                                                          gpointer              user_data);
-gboolean        ide_workbench_save_all_finish            (IdeWorkbench         *self,
-                                                          GAsyncResult         *result,
-                                                          GError              **error);
-void            ide_workbench_focus                      (IdeWorkbench         *self,
-                                                          GtkWidget            *widget);
-void            ide_workbench_close                      (IdeWorkbench         *self);
-IdeContext     *ide_workbench_get_context                (IdeWorkbench         *self);
-void            ide_workbench_add_perspective            (IdeWorkbench         *self,
-                                                          IdePerspective       *perspective);
-void            ide_workbench_remove_perspective         (IdeWorkbench         *self,
-                                                          IdePerspective       *perspective);
-IdePerspective *ide_workbench_get_perspective_by_name    (IdeWorkbench         *self,
-                                                          const gchar          *name);
-IdePerspective *ide_workbench_get_visible_perspective    (IdeWorkbench         *self);
-void            ide_workbench_set_visible_perspective    (IdeWorkbench         *self,
-                                                          IdePerspective       *perspective);
-gboolean        ide_workbench_get_fullscreen             (IdeWorkbench         *self);
-void            ide_workbench_set_fullscreen             (IdeWorkbench         *self,
-                                                          gboolean              fullscreen);
-void            ide_workbench_views_foreach              (IdeWorkbench         *self,
-                                                          GtkCallback           callback,
-                                                          gpointer              user_data);
+void            ide_workbench_open_async                   (IdeWorkbench         *self,
+                                                            GFile               **files,
+                                                            gint                  n_files,
+                                                            GCancellable         *cancellable,
+                                                            GAsyncReadyCallback   callback,
+                                                            gpointer              user_data);
+gboolean        ide_workbench_open_finish                  (IdeWorkbench         *self,
+                                                            GAsyncResult         *result,
+                                                            GError              **error);
+void            ide_workbench_save_all_async               (IdeWorkbench         *self,
+                                                            GCancellable         *cancellable,
+                                                            GAsyncReadyCallback   callback,
+                                                            gpointer              user_data);
+gboolean        ide_workbench_save_all_finish              (IdeWorkbench         *self,
+                                                            GAsyncResult         *result,
+                                                            GError              **error);
+void            ide_workbench_focus                        (IdeWorkbench         *self,
+                                                            GtkWidget            *widget);
+void            ide_workbench_close                        (IdeWorkbench         *self);
+IdeContext     *ide_workbench_get_context                  (IdeWorkbench         *self);
+void            ide_workbench_add_perspective              (IdeWorkbench         *self,
+                                                            IdePerspective       *perspective);
+void            ide_workbench_remove_perspective           (IdeWorkbench         *self,
+                                                            IdePerspective       *perspective);
+IdePerspective *ide_workbench_get_perspective_by_name      (IdeWorkbench         *self,
+                                                            const gchar          *name);
+IdePerspective *ide_workbench_get_visible_perspective      (IdeWorkbench         *self);
+void            ide_workbench_set_visible_perspective      (IdeWorkbench         *self,
+                                                            IdePerspective       *perspective);
+const gchar    *ide_workbench_get_visible_perspective_name (IdeWorkbench         *self);
+void            ide_workbench_set_visible_perspective_name (IdeWorkbench         *self,
+                                                            const gchar          *name);
+gboolean        ide_workbench_get_fullscreen               (IdeWorkbench         *self);
+void            ide_workbench_set_fullscreen               (IdeWorkbench         *self,
+                                                            gboolean              fullscreen);
+void            ide_workbench_views_foreach                (IdeWorkbench         *self,
+                                                            GtkCallback           callback,
+                                                            gpointer              user_data);
 
 G_END_DECLS
 


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