[gnome-builder] workbench: simplify early stage perspective



commit 74ef8428dff1841ff6131e78ef60dd0ceccc3f39
Author: Christian Hergert <chergert redhat com>
Date:   Sun Nov 29 23:42:37 2015 -0800

    workbench: simplify early stage perspective

 data/ui/ide-greeter-perspective.ui       |    3 +-
 libide/greeter/ide-greeter-perspective.c |    7 +++
 libide/ide-perspective.c                 |   15 ++++++
 libide/ide-perspective.h                 |    2 +
 libide/ide-workbench-private.h           |    5 +--
 libide/ide-workbench.c                   |   79 ++++++++---------------------
 6 files changed, 49 insertions(+), 62 deletions(-)
---
diff --git a/data/ui/ide-greeter-perspective.ui b/data/ui/ide-greeter-perspective.ui
index da93514..28e1a1a 100644
--- a/data/ui/ide-greeter-perspective.ui
+++ b/data/ui/ide-greeter-perspective.ui
@@ -208,7 +208,8 @@
     </child>
     <child>
       <object class="GtkButton" id="new_button">
-        <property name="action-name">app.new-project</property>
+        <property name="action-name">win.perspective</property>
+        <property name="action-target">'genesis'</property>
         <property name="visible">true</property>
         <property name="label" translatable="yes">_New</property>
         <property name="use-underline">true</property>
diff --git a/libide/greeter/ide-greeter-perspective.c b/libide/greeter/ide-greeter-perspective.c
index de385af..8055d1b 100644
--- a/libide/greeter/ide-greeter-perspective.c
+++ b/libide/greeter/ide-greeter-perspective.c
@@ -88,12 +88,19 @@ ide_greeter_perspective_get_id (IdePerspective *perspective)
   return g_strdup ("greeter");
 }
 
+static gboolean
+ide_greeter_perspective_is_early (IdePerspective *perspective)
+{
+  return TRUE;
+};
+
 static void
 ide_perspective_iface_init (IdePerspectiveInterface *iface)
 {
   iface->get_id = ide_greeter_perspective_get_id;
   iface->get_actions = ide_greeter_perspective_get_actions;
   iface->get_titlebar = ide_greeter_perspective_get_titlebar;
+  iface->is_early = ide_greeter_perspective_is_early;
 }
 
 static void
diff --git a/libide/ide-perspective.c b/libide/ide-perspective.c
index 6770507..abfafcb 100644
--- a/libide/ide-perspective.c
+++ b/libide/ide-perspective.c
@@ -277,3 +277,18 @@ ide_perspective_get_priority (IdePerspective *self)
 
   return IDE_PERSPECTIVE_GET_IFACE (self)->get_priority (self);
 }
+
+/**
+ * ide_perspective_is_early:
+ *
+ * If %TRUE, the perspective can be used before loading a project.
+ */
+gboolean
+ide_perspective_is_early (IdePerspective *self)
+{
+  g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), FALSE);
+
+  if (IDE_PERSPECTIVE_GET_IFACE (self)->is_early)
+    return IDE_PERSPECTIVE_GET_IFACE (self)->is_early (self);
+  return FALSE;
+}
diff --git a/libide/ide-perspective.h b/libide/ide-perspective.h
index e7ef628..749324e 100644
--- a/libide/ide-perspective.h
+++ b/libide/ide-perspective.h
@@ -39,6 +39,7 @@ struct _IdePerspectiveInterface
   gint          (*get_priority)        (IdePerspective *self);
   gchar        *(*get_title)           (IdePerspective *self);
   GtkWidget    *(*get_titlebar)        (IdePerspective *self);
+  gboolean      (*is_early)            (IdePerspective *self);
   void          (*set_fullscreen)      (IdePerspective *self,
                                         gboolean        fullscreen);
   void          (*views_foreach)       (IdePerspective *self,
@@ -54,6 +55,7 @@ gboolean      ide_perspective_get_needs_attention (IdePerspective *self);
 gint          ide_perspective_get_priority        (IdePerspective *self);
 gchar        *ide_perspective_get_title           (IdePerspective *self);
 GtkWidget    *ide_perspective_get_titlebar        (IdePerspective *self);
+gboolean      ide_perspective_is_early            (IdePerspective *self);
 void          ide_perspective_set_fullscreen      (IdePerspective *self,
                                                    gboolean        fullscreen);
 void          ide_perspective_views_foreach       (IdePerspective *self,
diff --git a/libide/ide-workbench-private.h b/libide/ide-workbench-private.h
index e2b1d8e..eca6783 100644
--- a/libide/ide-workbench-private.h
+++ b/libide/ide-workbench-private.h
@@ -21,8 +21,7 @@
 
 #include <libpeas/peas.h>
 
-#include "ide-greeter-perspective.h"
-#include "ide-preferences-perspective.h"
+#include "ide-perspective.h"
 #include "ide-workbench.h"
 
 G_BEGIN_DECLS
@@ -38,8 +37,6 @@ struct _IdeWorkbench
 
   GtkStack                  *top_stack;
   GtkStack                  *titlebar_stack;
-  IdeGreeterPerspective     *greeter_perspective;
-  IdePreferencesPerspective *preferences_perspective;
   GtkStack                  *perspectives_stack;
   GtkStackSwitcher          *perspectives_stack_switcher;
   GtkPopover                *perspectives_popover;
diff --git a/libide/ide-workbench.c b/libide/ide-workbench.c
index 7b674b5..505b17f 100644
--- a/libide/ide-workbench.c
+++ b/libide/ide-workbench.c
@@ -19,8 +19,10 @@
 #define G_LOG_DOMAIN "ide-workbench"
 
 #include "ide-debug.h"
+#include "ide-greeter-perspective.h"
 #include "ide-gtk.h"
 #include "ide-macros.h"
+#include "ide-preferences-perspective.h"
 #include "ide-window-settings.h"
 #include "ide-workbench.h"
 #include "ide-workbench-addin.h"
@@ -258,45 +260,20 @@ ide_workbench_class_init (IdeWorkbenchClass *klass)
 }
 
 static void
-ide_workbench_init_greeter (IdeWorkbench *self)
-{
-  g_assert (IDE_IS_WORKBENCH (self));
-
-  self->greeter_perspective = g_object_new (IDE_TYPE_GREETER_PERSPECTIVE,
-                                            "visible", TRUE,
-                                            NULL);
-  ide_workbench_add_perspective (self, IDE_PERSPECTIVE (self->greeter_perspective));
-  gtk_container_child_set (GTK_CONTAINER (self->titlebar_stack),
-                           ide_perspective_get_titlebar (IDE_PERSPECTIVE (self->greeter_perspective)),
-                           "position", 0,
-                           NULL);
-  gtk_container_child_set (GTK_CONTAINER (self->top_stack),
-                           GTK_WIDGET (self->greeter_perspective),
-                           "position", 0,
-                           NULL);
-  ide_workbench_set_visible_perspective (self, IDE_PERSPECTIVE (self->greeter_perspective));
-}
-
-static void
-ide_workbench_init_preferences (IdeWorkbench *self)
-{
-  g_assert (IDE_IS_WORKBENCH (self));
-
-  self->preferences_perspective = g_object_new (IDE_TYPE_PREFERENCES_PERSPECTIVE,
-                                                "visible", TRUE,
-                                                NULL);
-  ide_workbench_add_perspective (self, IDE_PERSPECTIVE (self->preferences_perspective));
-}
-
-static void
 ide_workbench_init (IdeWorkbench *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
   ide_workbench_actions_init (self);
 
-  ide_workbench_init_greeter (self);
-  ide_workbench_init_preferences (self);
+  ide_workbench_add_perspective (self,
+                                 g_object_new (IDE_TYPE_GREETER_PERSPECTIVE,
+                                               "visible", TRUE,
+                                               NULL));
+  ide_workbench_add_perspective (self,
+                                 g_object_new (IDE_TYPE_PREFERENCES_PERSPECTIVE,
+                                               "visible", TRUE,
+                                               NULL));
 
   ide_window_settings_register (GTK_WINDOW (self));
 
@@ -306,7 +283,7 @@ ide_workbench_init (IdeWorkbench *self)
                            self,
                            G_CONNECT_SWAPPED);
 
-  gtk_stack_set_visible_child (self->top_stack, GTK_WIDGET (self->greeter_perspective));
+  ide_workbench_set_visible_perspective_name (self, "greeter");
 }
 
 static void
@@ -450,7 +427,7 @@ ide_workbench_add_perspective (IdeWorkbench   *self,
   title = ide_perspective_get_title (perspective);
   icon_name = ide_perspective_get_icon_name (perspective);
 
-  if (IDE_IS_GREETER_PERSPECTIVE (perspective))
+  if (ide_perspective_is_early (perspective))
     stack = self->top_stack;
   else
     stack = self->perspectives_stack;
@@ -532,10 +509,14 @@ ide_workbench_get_perspective_by_name (IdeWorkbench *self,
 IdePerspective *
 ide_workbench_get_visible_perspective (IdeWorkbench *self)
 {
+  GtkWidget *visible_child;
+
   g_return_val_if_fail (IDE_IS_WORKBENCH (self), NULL);
 
-  if (gtk_stack_get_visible_child (self->top_stack) == GTK_WIDGET (self->greeter_perspective))
-    return IDE_PERSPECTIVE (self->greeter_perspective);
+  visible_child = gtk_stack_get_visible_child (self->top_stack);
+
+  if (IDE_IS_PERSPECTIVE (visible_child))
+    return IDE_PERSPECTIVE (visible_child);
 
   return IDE_PERSPECTIVE (gtk_stack_get_visible_child (self->perspectives_stack));
 }
@@ -551,34 +532,18 @@ ide_workbench_set_visible_perspective (IdeWorkbench   *self,
   g_return_if_fail (IDE_IS_WORKBENCH (self));
   g_return_if_fail (IDE_IS_PERSPECTIVE (perspective));
 
-  /*
-   * NOTE:
-   *
-   * The greeter perspective is special cased. We want to use the same window for the greeter
-   * and the workbench, so it has a toplevel stack with slightly different semantics than the
-   * other perspectives. We don't show the perspective sidebar, and we use a slide-right-left
-   * animation.
-   *
-   * Once we leave the greeter, we do not come back to it. We only use crossfade animations from
-   * then on.
-   */
-
-  if (IDE_IS_GREETER_PERSPECTIVE (perspective))
-    stack = self->top_stack;
-  else
-    stack = self->perspectives_stack;
+  stack = GTK_STACK (gtk_widget_get_ancestor (GTK_WIDGET (perspective), GTK_TYPE_STACK));
 
   id = ide_perspective_get_id (perspective);
   gtk_stack_set_visible_child_name (stack, id);
   gtk_stack_set_visible_child_name (self->titlebar_stack, id);
+  g_free (id);
 
   actions = ide_perspective_get_actions (perspective);
   gtk_widget_insert_action_group (GTK_WIDGET (self), "perspective", actions);
 
-  if (!IDE_IS_GREETER_PERSPECTIVE (perspective))
-    gtk_stack_set_transition_type (self->titlebar_stack, GTK_STACK_TRANSITION_TYPE_CROSSFADE);
-
-  g_free (id);
+  if (stack == self->perspectives_stack)
+    gtk_stack_set_visible_child_name (self->top_stack, "perspectives");
 }
 
 const gchar *


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