[gnome-builder] glade: allow pointer mode selection



commit 974914d0a56e180c3ceaf6efe3b3a56ab6e7e008
Author: Christian Hergert <chergert redhat com>
Date:   Sun Oct 21 20:37:30 2018 -0700

    glade: allow pointer mode selection
    
    Glade doesn't generate 2x icons, so we probably want to make something new
    for these values.

 src/plugins/glade/gbp-glade-view-actions.c | 30 ++++++++++++++++++
 src/plugins/glade/gbp-glade-view.c         | 50 +++++++++++++++++++++++++++++-
 2 files changed, 79 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/glade/gbp-glade-view-actions.c b/src/plugins/glade/gbp-glade-view-actions.c
index 7a16e8be4..42170e368 100644
--- a/src/plugins/glade/gbp-glade-view-actions.c
+++ b/src/plugins/glade/gbp-glade-view-actions.c
@@ -80,9 +80,39 @@ gbp_glade_view_action_preview (GSimpleAction *action,
     }
 }
 
+static void
+gbp_glade_view_action_pointer_mode (GSimpleAction *action,
+                                    GVariant      *param,
+                                    gpointer       user_data)
+{
+  GbpGladeView *self = user_data;
+  g_autoptr(GEnumClass) klass = NULL;
+  GladeProject *project;
+  const gchar *nick;
+  GEnumValue *value;
+  GType type;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (param != NULL);
+  g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_STRING));
+  g_assert (GBP_IS_GLADE_VIEW (self));
+
+  project = gbp_glade_view_get_project (self);
+  nick = g_variant_get_string (param, NULL);
+
+  /* No GType to lookup from public API yet */
+  type = g_type_from_name ("GladePointerMode");
+  klass = g_type_class_ref (type);
+  value = g_enum_get_value_by_nick (klass, nick);
+
+  if (value != NULL)
+    glade_project_set_pointer_mode (project, value->value);
+}
+
 static GActionEntry actions[] = {
   { "save", gbp_glade_view_action_save },
   { "preview", gbp_glade_view_action_preview },
+  { "pointer-mode", gbp_glade_view_action_pointer_mode, "s" },
 };
 
 void
diff --git a/src/plugins/glade/gbp-glade-view.c b/src/plugins/glade/gbp-glade-view.c
index 38925b2b5..82ec6811c 100644
--- a/src/plugins/glade/gbp-glade-view.c
+++ b/src/plugins/glade/gbp-glade-view.c
@@ -87,6 +87,16 @@ gbp_glade_view_init (GbpGladeView *self)
   GtkBox *box;
   GtkViewport *viewport;
   GtkStyleContext *style_context;
+  static const struct {
+    const gchar *action_target;
+    const gchar *icon_name;
+    const gchar *tooltip;
+  } pointers[] = {
+    { "select", "glade-selector", N_("Switch to selection mode") },
+    { "drag-resize", "glade-drag-resize", N_("Switch to drag-resize mode") },
+    { "margin-edit", "glade-margin-edit", N_("Switch to margin editor") },
+    { "align-edit", "glade-align-edit", N_("Switch to alignment editor") },
+  };
 
   ide_layout_view_set_menu_id (IDE_LAYOUT_VIEW (self), "gbp-glade-view-menu");
   ide_layout_view_set_title (IDE_LAYOUT_VIEW (self), _("Unnamed Glade project"));
@@ -130,9 +140,47 @@ gbp_glade_view_init (GbpGladeView *self)
                            G_CONNECT_SWAPPED);
   viewport_style_changed_cb (self, style_context);
 
+  /* Setup pointer-mode controls */
+
+  box = g_object_new (GTK_TYPE_BOX,
+                      "visible", TRUE,
+                      NULL);
+  dzl_gtk_widget_add_style_class (GTK_WIDGET (box), "linked");
+  gtk_container_add (GTK_CONTAINER (self->chooser), GTK_WIDGET (box));
+
+  for (guint i = 0; i < G_N_ELEMENTS (pointers); i++)
+    {
+      g_autoptr(GVariant) param = NULL;
+      GtkButton *button;
+      GtkImage *image;
+
+      param = g_variant_take_ref (g_variant_new_string (pointers[i].action_target));
+
+      image = g_object_new (GTK_TYPE_IMAGE,
+                            "icon-name", pointers[i].icon_name,
+                            "visible", TRUE,
+                            NULL);
+      button = g_object_new (GTK_TYPE_BUTTON,
+                             "action-name", "glade-view.pointer-mode",
+                             "action-target", param,
+                             "child", image,
+                             "has-tooltip", TRUE,
+                             "tooltip-text", pointers[i].tooltip,
+                             "visible", TRUE,
+                             NULL);
+      dzl_gtk_widget_add_style_class (GTK_WIDGET (button), "image-button");
+      gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (button));
+    }
+
+  /* Setup project and bindings. */
+
   glade_app_add_project (self->project);
 
-  g_object_bind_property (G_OBJECT (self->project), "modified", self, "modified", G_BINDING_DEFAULT);
+  g_object_bind_property (G_OBJECT (self->project), "modified",
+                          self, "modified",
+                          G_BINDING_DEFAULT);
+
+  /* Setup action state and shortcuts */
 
   _gbp_glade_view_init_actions (self);
   _gbp_glade_view_init_shortcuts (GTK_WIDGET (self));


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