[gnome-builder] Remove "get_actions" from the perspective



commit 897a8d3d1c1126f05ab09d54db5a7d3bd45d0950
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 27 16:25:07 2017 -0700

    Remove "get_actions" from the perspective
    
    We don't need this now that we can mux actions from perspectives.
    Just add the action groups to your perspective and that should be
    enough to make things work.

 TODO.txt                                         |   11 +++++-
 libide/buildui/ide-build-configuration-row.ui    |    4 +-
 libide/buildui/ide-build-perspective.c           |   29 +++++----------
 libide/greeter/ide-greeter-perspective.c         |   41 +++++++++-------------
 libide/greeter/ide-greeter-perspective.ui        |    4 +-
 libide/preferences/ide-preferences-perspective.c |   13 -------
 libide/workbench/ide-perspective.c               |   27 --------------
 libide/workbench/ide-perspective.h               |    2 -
 libide/workbench/ide-workbench.c                 |   14 +++-----
 9 files changed, 44 insertions(+), 101 deletions(-)
---
diff --git a/TODO.txt b/TODO.txt
index ada637d..c5832af 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -2,6 +2,10 @@
  - Search entry context menu (use a GMenu and merging this time)
    Might also require DzlWidgetActionGroup.
 
+ - Make sure search entry actually works
+
+ - Be able to add an editor view
+
  - Enter, Up, and Down accelerators for search/replace entries.
 
  - perspective focus_location
@@ -10,8 +14,6 @@
 
  - can we make perspectives the plugin interface?
 
- - Check if buffer is already in visible stack before adding new view
-
  - view-added/removed/etc on IdeLayoutGrid
 
  - Remove get_right_edge() etc, switch with "classification" for panels
@@ -30,3 +32,8 @@
  - Move panel position settings to org.gnome.builder.editor maybe
 
 
+
+Done
+
+ - Check if buffer is already in visible stack before adding new view
+ - Perspective actions, copy them across
diff --git a/libide/buildui/ide-build-configuration-row.ui b/libide/buildui/ide-build-configuration-row.ui
index b29a414..336f96c 100644
--- a/libide/buildui/ide-build-configuration-row.ui
+++ b/libide/buildui/ide-build-configuration-row.ui
@@ -39,7 +39,7 @@
                 <property name="visible">true</property>
                 <child>
                   <object class="GtkButton" id="duplicate">
-                    <property name="action-name">perspective.duplicate-configuration</property>
+                    <property name="action-name">build-preferences.duplicate-configuration</property>
                     <property name="tooltip-text" translatable="yes">Duplicate the configuration</property>
                     <property name="visible">true</property>
                     <style>
@@ -55,7 +55,7 @@
                 </child>
                 <child>
                   <object class="GtkButton" id="delete">
-                    <property name="action-name">perspective.delete-configuration</property>
+                    <property name="action-name">build-preferences.delete-configuration</property>
                     <property name="tooltip-text" translatable="yes">Delete the configuration</property>
                     <property name="visible">true</property>
                     <style>
diff --git a/libide/buildui/ide-build-perspective.c b/libide/buildui/ide-build-perspective.c
index 2b17bd6..bf552af 100644
--- a/libide/buildui/ide-build-perspective.c
+++ b/libide/buildui/ide-build-perspective.c
@@ -28,7 +28,6 @@ struct _IdeBuildPerspective
 {
   GtkBin                     parent_instance;
 
-  GActionGroup              *actions;
   IdeConfiguration          *configuration;
   IdeConfigurationManager   *configuration_manager;
 
@@ -260,7 +259,6 @@ ide_build_perspective_finalize (GObject *object)
 {
   IdeBuildPerspective *self = (IdeBuildPerspective *)object;
 
-  g_clear_object (&self->actions);
   g_clear_object (&self->configuration);
 
   G_OBJECT_CLASS (ide_build_perspective_parent_class)->finalize (object);
@@ -346,13 +344,15 @@ ide_build_perspective_class_init (IdeBuildPerspectiveClass *klass)
   g_type_ensure (IDE_TYPE_BUILD_CONFIGURATION_VIEW);
 }
 
+static const GActionEntry actions[] = {
+  { "delete-configuration", delete_configuration },
+  { "duplicate-configuration", duplicate_configuration },
+};
+
 static void
 ide_build_perspective_init (IdeBuildPerspective *self)
 {
-  static GActionEntry actions[] = {
-    { "delete-configuration", delete_configuration },
-    { "duplicate-configuration", duplicate_configuration },
-  };
+  g_autoptr(GSimpleActionGroup) group = NULL;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -368,9 +368,9 @@ ide_build_perspective_init (IdeBuildPerspective *self)
                            self,
                            G_CONNECT_SWAPPED);
 
-  self->actions = G_ACTION_GROUP (g_simple_action_group_new ());
-  g_action_map_add_action_entries (G_ACTION_MAP (self->actions), actions,
-                                   G_N_ELEMENTS (actions), self);
+  group = g_simple_action_group_new ();
+  g_action_map_add_action_entries (G_ACTION_MAP (group), actions, G_N_ELEMENTS (actions), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "build-preferences", G_ACTION_GROUP (group));
 }
 
 GtkWidget *
@@ -450,16 +450,6 @@ ide_build_perspective_get_priority (IdePerspective *perspective)
   return 80000;
 }
 
-static GActionGroup *
-ide_build_perspective_get_actions (IdePerspective *perspective)
-{
-  IdeBuildPerspective *self = (IdeBuildPerspective *)perspective;
-
-  g_assert (IDE_IS_BUILD_PERSPECTIVE (self));
-
-  return g_object_ref (self->actions);
-}
-
 static gchar *
 ide_build_perspective_get_accelerator (IdePerspective *perspective)
 {
@@ -469,7 +459,6 @@ ide_build_perspective_get_accelerator (IdePerspective *perspective)
 static void
 perspective_iface_init (IdePerspectiveInterface *iface)
 {
-  iface->get_actions = ide_build_perspective_get_actions;
   iface->get_icon_name = ide_build_perspective_get_icon_name;
   iface->get_title = ide_build_perspective_get_title;
   iface->get_id = ide_build_perspective_get_id;
diff --git a/libide/greeter/ide-greeter-perspective.c b/libide/greeter/ide-greeter-perspective.c
index 41ec4e9..438e148 100644
--- a/libide/greeter/ide-greeter-perspective.c
+++ b/libide/greeter/ide-greeter-perspective.c
@@ -40,7 +40,6 @@ struct _IdeGreeterPerspective
   DzlSignalGroup       *signal_group;
   IdeRecentProjects    *recent_projects;
   DzlPatternSpec       *pattern_spec;
-  GActionMap           *actions;
   PeasExtensionSet     *genesis_set;
 
   GBinding             *ready_binding;
@@ -94,12 +93,6 @@ ide_greeter_perspective_get_titlebar (IdePerspective *perspective)
   return IDE_GREETER_PERSPECTIVE (perspective)->titlebar;
 }
 
-static GActionGroup *
-ide_greeter_perspective_get_actions (IdePerspective *perspective)
-{
-  return g_object_ref (IDE_GREETER_PERSPECTIVE (perspective)->actions);
-}
-
 static gchar *
 ide_greeter_perspective_get_id (IdePerspective *perspective)
 {
@@ -116,7 +109,6 @@ 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;
 }
@@ -301,7 +293,6 @@ ide_greeter_perspective__row_notify_selected (IdeGreeterPerspective *self,
                                               IdeGreeterProjectRow  *row)
 {
   gboolean selected = FALSE;
-  GAction *action;
 
   g_assert (IDE_IS_GREETER_PERSPECTIVE (self));
   g_assert (pspec != NULL);
@@ -310,8 +301,9 @@ ide_greeter_perspective__row_notify_selected (IdeGreeterPerspective *self,
   g_object_get (row, "selected", &selected, NULL);
   self->selected_count += selected ? 1 : -1;
 
-  action = g_action_map_lookup_action (self->actions, "delete-selected-rows");
-  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (self->selected_count > 0));
+  dzl_gtk_widget_action_set (GTK_WIDGET (self), "greeter", "delete-selected-rows",
+                             "enabled", self->selected_count > 0,
+                             NULL);
 }
 
 static void
@@ -1222,13 +1214,15 @@ ide_greeter_perspective_class_init (IdeGreeterPerspectiveClass *klass)
   gtk_widget_class_bind_template_child (widget_class, IdeGreeterPerspective, no_projects_found);
 }
 
+static const GActionEntry actions[] = {
+  { "delete-selected-rows", delete_selected_rows },
+};
+
 static void
 ide_greeter_perspective_init (IdeGreeterPerspective *self)
 {
-  GActionEntry actions[] = {
-    { "delete-selected-rows", delete_selected_rows },
-  };
-  GAction *action;
+  g_autoptr(GSimpleActionGroup) group = NULL;
+  g_autoptr(GAction) state = NULL;
 
   self->signal_group = dzl_signal_group_new (IDE_TYPE_RECENT_PROJECTS);
   dzl_signal_group_connect_object (self->signal_group,
@@ -1330,14 +1324,13 @@ ide_greeter_perspective_init (IdeGreeterPerspective *self)
                                 ide_greeter_perspective_filter_row,
                                 self, NULL);
 
-  self->actions = G_ACTION_MAP (g_simple_action_group_new ());
-
-  action = dzl_state_machine_create_action (self->state_machine, "state");
-  g_action_map_add_action (self->actions, action);
-  g_object_unref (action);
-
-  g_action_map_add_action_entries (self->actions, actions, G_N_ELEMENTS (actions), self);
+  group = g_simple_action_group_new ();
+  state = dzl_state_machine_create_action (self->state_machine, "state");
+  g_action_map_add_action (G_ACTION_MAP (group), state);
+  g_action_map_add_action_entries (G_ACTION_MAP (group), actions, G_N_ELEMENTS (actions), self);
+  gtk_widget_insert_action_group (GTK_WIDGET (self), "greeter", G_ACTION_GROUP (group));
 
-  action = g_action_map_lookup_action (self->actions, "delete-selected-rows");
-  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+  dzl_gtk_widget_action_set (GTK_WIDGET (self), "greeter", "delete-selected-rows",
+                             "enabled", FALSE,
+                             NULL);
 }
diff --git a/libide/greeter/ide-greeter-perspective.ui b/libide/greeter/ide-greeter-perspective.ui
index dbdd10d..2a75df2 100644
--- a/libide/greeter/ide-greeter-perspective.ui
+++ b/libide/greeter/ide-greeter-perspective.ui
@@ -211,7 +211,7 @@
                             <property name="visible">false</property>
                             <child>
                               <object class="GtkButton" id="remove_button">
-                                <property name="action-name">perspective.delete-selected-rows</property>
+                                <property name="action-name">greeter.delete-selected-rows</property>
                                 <property name="label" translatable="yes">_Remove</property>
                                 <property name="use-underline">true</property>
                                 <property name="visible">true</property>
@@ -351,7 +351,7 @@
     <child>
       <object class="GtkToggleButton" id="selection_button">
         <property name="tooltip-text" translatable="yes">Select projects for removal</property>
-        <property name="action-name">perspective.state</property>
+        <property name="action-name">greeter.state</property>
         <property name="action-target">'selection'</property>
         <style>
           <class name="image-button"/>
diff --git a/libide/preferences/ide-preferences-perspective.c 
b/libide/preferences/ide-preferences-perspective.c
index 7d62710..79d6a66 100644
--- a/libide/preferences/ide-preferences-perspective.c
+++ b/libide/preferences/ide-preferences-perspective.c
@@ -130,18 +130,6 @@ ide_preferences_perspective_get_icon_name (IdePerspective *perspective)
   return g_strdup ("preferences-system-symbolic");
 }
 
-static GActionGroup *
-ide_preferences_perspective_get_actions (IdePerspective *perspective)
-{
-  IdePreferencesPerspective *self = (IdePreferencesPerspective *)perspective;
-
-  g_assert (IDE_IS_PREFERENCES_PERSPECTIVE (self));
-
-  /* TODO: Get the action group for the back button */
-
-  return NULL;
-}
-
 static gint
 ide_preferences_perspective_get_priority (IdePerspective *perspective)
 {
@@ -160,7 +148,6 @@ ide_perspective_iface_init (IdePerspectiveInterface *iface)
   iface->get_id = ide_preferences_perspective_get_id;
   iface->get_icon_name = ide_preferences_perspective_get_icon_name;
   iface->get_title = ide_preferences_perspective_get_title;
-  iface->get_actions = ide_preferences_perspective_get_actions;
   iface->get_priority = ide_preferences_perspective_get_priority;
   iface->get_accelerator = ide_preferences_perspective_get_accelerator;
 }
diff --git a/libide/workbench/ide-perspective.c b/libide/workbench/ide-perspective.c
index 66fa694..bbfac34 100644
--- a/libide/workbench/ide-perspective.c
+++ b/libide/workbench/ide-perspective.c
@@ -26,12 +26,6 @@ ide_perspective_real_agree_to_shutdown (IdePerspective *self)
   return TRUE;
 }
 
-static GActionGroup *
-ide_perspective_real_get_actions (IdePerspective *self)
-{
-  return NULL;
-}
-
 static gchar *
 ide_perspective_real_get_icon_name (IdePerspective *self)
 {
@@ -85,7 +79,6 @@ static void
 ide_perspective_default_init (IdePerspectiveInterface *iface)
 {
   iface->agree_to_shutdown = ide_perspective_real_agree_to_shutdown;
-  iface->get_actions = ide_perspective_real_get_actions;
   iface->get_icon_name = ide_perspective_real_get_icon_name;
   iface->get_id = ide_perspective_real_get_id;
   iface->get_needs_attention = ide_perspective_real_get_needs_attention;
@@ -258,26 +251,6 @@ ide_perspective_views_foreach (IdePerspective *self,
   IDE_PERSPECTIVE_GET_IFACE (self)->views_foreach (self, callback, user_data);
 }
 
-/**
- * ide_perspective_get_actions:
- * @self: An #IdePerspective.
- *
- * This interface method should retrieve a #GActionGroup associated with the
- * perspective, if necessary. The #GActionGroup will automatically be
- * registered with the "perspective" action prefix while the perspective is
- * active. A perspective is "active" when it is currently displayed in the
- * workbench.
- *
- * Returns: (nullable) (transfer full): A #GActionGroup or %NULL.
- */
-GActionGroup *
-ide_perspective_get_actions (IdePerspective *self)
-{
-  g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), NULL);
-
-  return IDE_PERSPECTIVE_GET_IFACE (self)->get_actions (self);
-}
-
 gint
 ide_perspective_get_priority (IdePerspective *self)
 {
diff --git a/libide/workbench/ide-perspective.h b/libide/workbench/ide-perspective.h
index 7f15c40..bcca282 100644
--- a/libide/workbench/ide-perspective.h
+++ b/libide/workbench/ide-perspective.h
@@ -32,7 +32,6 @@ struct _IdePerspectiveInterface
   GTypeInterface parent;
 
   gboolean      (*agree_to_shutdown)   (IdePerspective *self);
-  GActionGroup *(*get_actions)         (IdePerspective *self);
   gchar        *(*get_icon_name)       (IdePerspective *self);
   gchar        *(*get_id)              (IdePerspective *self);
   gboolean      (*get_needs_attention) (IdePerspective *self);
@@ -50,7 +49,6 @@ struct _IdePerspectiveInterface
 };
 
 gboolean      ide_perspective_agree_to_shutdown   (IdePerspective *self);
-GActionGroup *ide_perspective_get_actions         (IdePerspective *self);
 gchar        *ide_perspective_get_icon_name       (IdePerspective *self);
 gchar        *ide_perspective_get_id              (IdePerspective *self);
 gboolean      ide_perspective_get_needs_attention (IdePerspective *self);
diff --git a/libide/workbench/ide-workbench.c b/libide/workbench/ide-workbench.c
index c80239e..ce80775 100644
--- a/libide/workbench/ide-workbench.c
+++ b/libide/workbench/ide-workbench.c
@@ -18,6 +18,7 @@
 
 #define G_LOG_DOMAIN "ide-workbench"
 
+#include <dazzle.h>
 #include <glib/gi18n.h>
 
 #include "ide-debug.h"
@@ -123,19 +124,17 @@ ide_workbench_notify_visible_child (IdeWorkbench *self,
                                     GParamSpec   *pspec,
                                     GtkStack     *stack)
 {
-  GActionGroup *actions = NULL;
   IdePerspective *perspective;
 
   g_assert (IDE_IS_WORKBENCH (self));
   g_assert (GTK_IS_STACK (stack));
 
   perspective = IDE_PERSPECTIVE (gtk_stack_get_visible_child (stack));
-  if (perspective != NULL)
-    actions = ide_perspective_get_actions (perspective);
-
-  gtk_widget_insert_action_group (GTK_WIDGET (self), "perspective", actions);
 
-  g_clear_object (&actions);
+  /* Mux the actions from the perspective for the header bar */
+  dzl_gtk_widget_mux_action_groups (GTK_WIDGET (self),
+                                    perspective ? GTK_WIDGET (perspective) : NULL,
+                                    "IDE_PERSPECTIVE_ACTIONS");
 }
 
 static gint
@@ -974,9 +973,6 @@ ide_workbench_set_visible_perspective (IdeWorkbench   *self,
   else
     gtk_stack_set_visible_child (self->header_stack, GTK_WIDGET (self->header_bar));
 
-  actions = ide_perspective_get_actions (perspective);
-  gtk_widget_insert_action_group (GTK_WIDGET (self), "perspective", actions);
-
   /*
    * If we are transitioning to the editor the first time, we can
    * remove the early perspectives (greeter, etc).


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