[gnome-builder] glade: move action state changed tracking to view



commit e32ac51a1795f82559e0dfc3c3c2f5a8e88101e5
Author: Christian Hergert <chergert redhat com>
Date:   Mon Oct 22 16:02:17 2018 -0700

    glade: move action state changed tracking to view

 src/plugins/glade/gbp-glade-private.h      |  1 +
 src/plugins/glade/gbp-glade-view-actions.c | 21 ++++++---------------
 src/plugins/glade/gbp-glade-view.c         | 21 +++++++++++++++++++++
 3 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/glade/gbp-glade-private.h b/src/plugins/glade/gbp-glade-private.h
index debbbea8c..00098dee2 100644
--- a/src/plugins/glade/gbp-glade-private.h
+++ b/src/plugins/glade/gbp-glade-private.h
@@ -39,6 +39,7 @@ struct _GbpGladeView
 
 void     _gbp_glade_view_init_actions   (GbpGladeView  *self);
 void     _gbp_glade_view_init_shortcuts (GtkWidget     *widget);
+void     _gbp_glade_view_update_actions (GbpGladeView  *self);
 gboolean _gbp_glade_view_save           (GbpGladeView  *self,
                                          GError       **error);
 
diff --git a/src/plugins/glade/gbp-glade-view-actions.c b/src/plugins/glade/gbp-glade-view-actions.c
index 41f5105dd..1064901b1 100644
--- a/src/plugins/glade/gbp-glade-view-actions.c
+++ b/src/plugins/glade/gbp-glade-view-actions.c
@@ -149,21 +149,17 @@ static GActionEntry actions[] = {
   { "pointer-mode", gbp_glade_view_action_pointer_mode, "s" },
 };
 
-static void
-gbp_glade_view_update_actions_cb (GbpGladeView *self,
-                                  GladeCommand *command,
-                                  gboolean      execute,
-                                  GladeProject *project)
+void
+_gbp_glade_view_update_actions (GbpGladeView *self)
 {
   GladeCommand *redo;
   GladeCommand *undo;
 
   g_assert (GBP_IS_GLADE_VIEW (self));
-  g_assert (!command || GLADE_IS_COMMAND (command));
-  g_assert (GLADE_IS_PROJECT (project));
+  g_assert (GLADE_IS_PROJECT (self->project));
 
-  redo = glade_project_next_redo_item (project);
-  undo = glade_project_next_undo_item (project);
+  redo = glade_project_next_redo_item (self->project);
+  undo = glade_project_next_undo_item (self->project);
 
   dzl_gtk_widget_action_set (GTK_WIDGET (self), "glade-view", "undo",
                              "enabled", undo != NULL,
@@ -189,10 +185,5 @@ _gbp_glade_view_init_actions (GbpGladeView *self)
                                   "glade-view",
                                   G_ACTION_GROUP (group));
 
-  g_signal_connect_object (self->project,
-                           "changed",
-                           G_CALLBACK (gbp_glade_view_update_actions_cb),
-                           self,
-                           G_CONNECT_SWAPPED);
-  gbp_glade_view_update_actions_cb (self, NULL, FALSE, self->project);
+  _gbp_glade_view_update_actions (self);
 }
diff --git a/src/plugins/glade/gbp-glade-view.c b/src/plugins/glade/gbp-glade-view.c
index 77304d6fa..92d235435 100644
--- a/src/plugins/glade/gbp-glade-view.c
+++ b/src/plugins/glade/gbp-glade-view.c
@@ -42,6 +42,22 @@ gbp_glade_view_new (void)
   return g_object_new (GBP_TYPE_GLADE_VIEW, NULL);
 }
 
+static void
+gbp_glade_view_changed_cb (GbpGladeView *self,
+                           GladeCommand *command,
+                           gboolean      execute,
+                           GladeProject *project)
+{
+  g_assert (GBP_IS_GLADE_VIEW (self));
+  g_assert (!command || GLADE_IS_COMMAND (command));
+  g_assert (GLADE_IS_PROJECT (project));
+
+  if (project != self->project)
+    return;
+
+  _gbp_glade_view_update_actions (self);
+}
+
 gboolean
 _gbp_glade_view_save (GbpGladeView  *self,
                       GError       **error)
@@ -171,6 +187,11 @@ gbp_glade_view_init (GbpGladeView *self)
   ide_layout_view_set_menu_id (IDE_LAYOUT_VIEW (self), "gbp-glade-view-document-menu");
 
   self->project = glade_project_new ();
+  g_signal_connect_object (self->project,
+                           "changed",
+                           G_CALLBACK (gbp_glade_view_changed_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
 
   box = g_object_new (GTK_TYPE_BOX,
                       "orientation", GTK_ORIENTATION_VERTICAL,


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