[gtk/widget-class-actions: 20/22] link button: Use the new action machinery



commit d35be08d33d3cee095d059d77b60a44bfa96952c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 15 02:25:46 2019 +0000

    link button: Use the new action machinery

 gtk/gtklinkbutton.c | 50 ++++++++++++++------------------------------------
 1 file changed, 14 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 7c68d9380f..af908670a9 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -96,7 +96,6 @@ struct _GtkLinkButtonPrivate
 
   gboolean visited;
 
-  GActionMap *context_actions;
   GtkWidget *popup_menu;
 };
 
@@ -152,6 +151,17 @@ static guint link_signals[LAST_SIGNAL] = { 0, };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkLinkButton, gtk_link_button, GTK_TYPE_BUTTON)
 
+static void
+gtk_link_button_activate_clipboard_copy (GtkWidget  *widget,
+                                         const char *name,
+                                         GVariant   *parameter)
+{
+  GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
+  GtkLinkButtonPrivate *priv = gtk_link_button_get_instance_private (link_button);
+
+  gdk_clipboard_set_text (gtk_widget_get_clipboard (widget), priv->uri);
+}
+
 static void
 gtk_link_button_class_init (GtkLinkButtonClass *klass)
 {
@@ -221,28 +231,10 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
 
   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LINK_BUTTON_ACCESSIBLE);
   gtk_widget_class_set_css_name (widget_class, I_("button"));
-}
-
-static void copy_activate_cb (GSimpleAction *action,
-                              GVariant      *parameter,
-                              gpointer       user_data);
-
-static void
-gtk_link_button_add_context_actions (GtkLinkButton *link_button)
-{
-  GtkLinkButtonPrivate *priv = gtk_link_button_get_instance_private (link_button);
-
-  GActionEntry entries[] = {
-    { "copy-clipboard", copy_activate_cb, NULL, NULL, NULL },
-  };
-
-  GSimpleActionGroup *actions = g_simple_action_group_new ();
 
-  priv->context_actions = G_ACTION_MAP (actions);
-
-  g_action_map_add_action_entries (G_ACTION_MAP (actions), entries, G_N_ELEMENTS (entries), link_button);
-
-  gtk_widget_insert_action_group (GTK_WIDGET (link_button), "context", G_ACTION_GROUP (actions));
+  gtk_widget_class_install_action (widget_class, "clipboard.copy",
+                                   gtk_link_button_activate_clipboard_copy,
+                                   NULL);
 }
 
 static GMenuModel *
@@ -298,7 +290,6 @@ gtk_link_button_init (GtkLinkButton *link_button)
   gtk_style_context_add_class (context, "link");
 
   gtk_widget_set_cursor_from_name (GTK_WIDGET (link_button), "pointer");
-  gtk_link_button_add_context_actions (link_button);
 }
 
 static void
@@ -309,7 +300,6 @@ gtk_link_button_finalize (GObject *object)
 
   g_free (priv->uri);
 
-  g_clear_object (&priv->context_actions);
   g_clear_pointer (&priv->popup_menu, gtk_widget_unparent);
 
   G_OBJECT_CLASS (gtk_link_button_parent_class)->finalize (object);
@@ -360,18 +350,6 @@ gtk_link_button_set_property (GObject      *object,
     }
 }
 
-static void
-copy_activate_cb (GSimpleAction *action,
-                  GVariant      *parameter,
-                  gpointer       user_data)
-{
-  GtkLinkButton *link_button = user_data;
-  GtkLinkButtonPrivate *priv = gtk_link_button_get_instance_private (link_button);
-
-  gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (link_button)),
-                         priv->uri);
-}
-
 static void
 gtk_link_button_do_popup (GtkLinkButton *link_button,
                           double         x,


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