[gtk/wip/matthiasc/shortcut-4: 46/85] Use an action for the context menu keybinding



commit 778d884f70408e3a3852036c1b720da534a59817
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 15 22:25:09 2020 -0400

    Use an action for the context menu keybinding
    
    The ::popup-menu signal is going away.

 gtk/gtkcolorswatch.c   | 21 +++++++++++++++------
 gtk/gtklabel.c         | 23 ++++++++++++++++++-----
 gtk/gtklinkbutton.c    | 24 ++++++++++++++++++------
 gtk/gtknotebook.c      | 30 +++++++++++++++++++-----------
 gtk/gtktext.c          | 22 +++++++++++++++++-----
 gtk/gtktextview.c      | 23 +++++++++++++++++------
 testsuite/gtk/action.c |  7 ++++---
 7 files changed, 108 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index ca6ab4d54f..f68003cc69 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -348,13 +348,12 @@ gtk_color_swatch_measure (GtkWidget *widget,
   *natural = MAX (*natural, min);
 }
 
-
-
-static gboolean
-swatch_popup_menu (GtkWidget *widget)
+static void
+swatch_popup_menu (GtkWidget  *widget,
+                   const char *action_name,
+                   GVariant   *parameters)
 {
   do_popup (GTK_COLOR_SWATCH (widget));
-  return TRUE;
 }
 
 static void
@@ -480,7 +479,6 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
 
   widget_class->measure = gtk_color_swatch_measure;
   widget_class->snapshot = swatch_snapshot;
-  widget_class->popup_menu = swatch_popup_menu;
   widget_class->size_allocate = swatch_size_allocate;
   widget_class->state_flags_changed = swatch_state_flags_changed;
 
@@ -497,6 +495,17 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
       g_param_spec_boolean ("can-drop", P_("Can Drop"), P_("Whether the swatch should accept drops"),
                             FALSE, GTK_PARAM_READWRITE));
 
+  gtk_widget_class_install_action (widget_class, "menu.popup", NULL, swatch_popup_menu);
+
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_F10, GDK_SHIFT_MASK,
+                                       "menu.popup",
+                                       NULL);
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_Menu, 0,
+                                       "menu.popup",
+                                       NULL);
+
   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_COLOR_SWATCH_ACCESSIBLE);
   gtk_widget_class_set_css_name (widget_class, I_("colorswatch"));
 }
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 049927ef2c..b1f12d12e7 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -480,7 +480,9 @@ static void gtk_label_set_markup_internal        (GtkLabel      *label,
 static void gtk_label_recalculate                (GtkLabel      *label);
 static void gtk_label_root                       (GtkWidget     *widget);
 static void gtk_label_unroot                     (GtkWidget     *widget);
-static gboolean gtk_label_popup_menu             (GtkWidget     *widget);
+static void gtk_label_popup_menu                 (GtkWidget     *widget,
+                                                  const char    *action_name,
+                                                  GVariant      *parameters);
 static void gtk_label_do_popup                   (GtkLabel      *label,
                                                   double         x,
                                                   double         y);
@@ -645,7 +647,6 @@ gtk_label_class_init (GtkLabelClass *class)
   widget_class->root = gtk_label_root;
   widget_class->unroot = gtk_label_unroot;
   widget_class->mnemonic_activate = gtk_label_mnemonic_activate;
-  widget_class->popup_menu = gtk_label_popup_menu;
   widget_class->grab_focus = gtk_label_grab_focus;
   widget_class->focus = gtk_label_focus;
   widget_class->get_request_mode = gtk_label_get_request_mode;
@@ -1022,10 +1023,21 @@ gtk_label_class_init (GtkLabelClass *class)
 
   g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props);
 
+  gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_label_popup_menu);
+
   /*
    * Key bindings
    */
 
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_F10, GDK_SHIFT_MASK,
+                                       "menu.popup",
+                                       NULL);
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_Menu, 0,
+                                       "menu.popup",
+                                       NULL);
+
   /* Moving the insertion point */
   add_move_binding (widget_class, GDK_KEY_Right, 0,
                    GTK_MOVEMENT_VISUAL_POSITIONS, 1);
@@ -6059,13 +6071,14 @@ gtk_label_do_popup (GtkLabel *label,
   gtk_popover_popup (GTK_POPOVER (priv->popup_menu));
 }
 
-static gboolean
-gtk_label_popup_menu (GtkWidget *widget)
+static void
+gtk_label_popup_menu (GtkWidget  *widget,
+                      const char *action_name,
+                      GVariant   *parameters)
 {
   GtkLabel *label = GTK_LABEL (widget);
 
   gtk_label_do_popup (label, -1, -1);
-  return TRUE;
 }
 
 static void
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index d64c3f3a83..96831ec083 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -123,7 +123,9 @@ static void     gtk_link_button_set_property (GObject          *object,
                                              const GValue     *value,
                                              GParamSpec       *pspec);
 static void     gtk_link_button_clicked      (GtkButton        *button);
-static gboolean gtk_link_button_popup_menu   (GtkWidget        *widget);
+static void     gtk_link_button_popup_menu   (GtkWidget        *widget,
+                                              const char       *action_name,
+                                              GVariant         *parameters);
 static gboolean gtk_link_button_query_tooltip_cb (GtkWidget    *widget,
                                                   gint          x,
                                                   gint          y,
@@ -169,8 +171,6 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
   gobject_class->get_property = gtk_link_button_get_property;
   gobject_class->finalize = gtk_link_button_finalize;
 
-  widget_class->popup_menu = gtk_link_button_popup_menu;
-
   button_class->clicked = gtk_link_button_clicked;
 
   klass->activate_link = gtk_link_button_activate_link;
@@ -230,6 +230,17 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
 
   gtk_widget_class_install_action (widget_class, "clipboard.copy", NULL,
                                    gtk_link_button_activate_clipboard_copy);
+
+  gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_link_button_popup_menu);
+
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_F10, GDK_SHIFT_MASK,
+                                       "menu.popup",
+                                       NULL);
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_Menu, 0,
+                                       "menu.popup",
+                                       NULL);
 }
 
 static GMenuModel *
@@ -503,11 +514,12 @@ gtk_link_button_clicked (GtkButton *button)
   g_signal_emit (button, link_signals[ACTIVATE_LINK], 0, &retval);
 }
 
-static gboolean
-gtk_link_button_popup_menu (GtkWidget *widget)
+static void
+gtk_link_button_popup_menu (GtkWidget  *widget,
+                            const char *action_name,
+                            GVariant   *parameters)
 {
   gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), -1, -1);
-  return TRUE;
 }
 
 /**
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 1c2a095a6f..a625013109 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -772,7 +772,9 @@ static void gtk_notebook_dispose             (GObject         *object);
 /*** GtkWidget Methods ***/
 static void gtk_notebook_destroy             (GtkWidget        *widget);
 static void gtk_notebook_unmap               (GtkWidget        *widget);
-static gboolean gtk_notebook_popup_menu      (GtkWidget        *widget);
+static void gtk_notebook_popup_menu          (GtkWidget        *widget,
+                                              const char       *action_name,
+                                              GVariant         *parameters);
 static void gtk_notebook_motion              (GtkEventController *controller,
                                               double              x,
                                               double              y,
@@ -1046,7 +1048,6 @@ gtk_notebook_class_init (GtkNotebookClass *class)
 
   widget_class->destroy = gtk_notebook_destroy;
   widget_class->unmap = gtk_notebook_unmap;
-  widget_class->popup_menu = gtk_notebook_popup_menu;
   widget_class->grab_notify = gtk_notebook_grab_notify;
   widget_class->state_flags_changed = gtk_notebook_state_flags_changed;
   widget_class->direction_changed = gtk_notebook_direction_changed;
@@ -1310,6 +1311,8 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                               G_TYPE_FROM_CLASS (gobject_class),
                               _gtk_marshal_OBJECT__OBJECTv);
 
+  gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_notebook_popup_menu);
+
   gtk_widget_class_add_binding_signal (widget_class,
                                        GDK_KEY_space, 0,
                                        "select-page",
@@ -1336,6 +1339,15 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                                        "focus-tab",
                                        "(i)", GTK_NOTEBOOK_TAB_LAST);
 
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_F10, GDK_SHIFT_MASK,
+                                       "menu.popup",
+                                       NULL);
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_Menu, 0,
+                                       "menu.popup",
+                                       NULL);
+
   gtk_widget_class_add_binding_signal (widget_class,
                                        GDK_KEY_Page_Up, GDK_CONTROL_MASK,
                                        "change-current-page",
@@ -2599,20 +2611,16 @@ gtk_notebook_gesture_pressed (GtkGestureClick *gesture,
     }
 }
 
-
-static gboolean
-gtk_notebook_popup_menu (GtkWidget *widget)
+static void
+gtk_notebook_popup_menu (GtkWidget  *widget,
+                         const char *action_name,
+                         GVariant   *parameters)
 {
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
 
   if (priv->menu)
-    {
-      gtk_popover_popup (GTK_POPOVER (priv->menu));
-      return TRUE;
-    }
-
-  return FALSE;
+    gtk_popover_popup (GTK_POPOVER (priv->menu));
 }
 
 static void
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 494f95f2f2..6825c7e88a 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -389,7 +389,9 @@ static void        gtk_text_set_alignment        (GtkText    *self,
 /* Default signal handlers
  */
 static GMenuModel *gtk_text_get_menu_model  (GtkText         *self);
-static gboolean gtk_text_popup_menu         (GtkWidget       *widget);
+static void     gtk_text_popup_menu         (GtkWidget       *widget,
+                                             const char      *action_name,
+                                             GVariant        *parameters);
 static void     gtk_text_move_cursor        (GtkText         *self,
                                              GtkMovementStep  step,
                                              int              count,
@@ -727,7 +729,6 @@ gtk_text_class_init (GtkTextClass *class)
   widget_class->state_flags_changed = gtk_text_state_flags_changed;
   widget_class->root = gtk_text_root;
   widget_class->mnemonic_activate = gtk_text_mnemonic_activate;
-  widget_class->popup_menu = gtk_text_popup_menu;
 
   class->move_cursor = gtk_text_move_cursor;
   class->insert_at_cursor = gtk_text_insert_at_cursor;
@@ -1195,11 +1196,21 @@ gtk_text_class_init (GtkTextClass *class)
 
   gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_real_undo);
   gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_real_redo);
+  gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_text_popup_menu);
 
   /*
    * Key bindings
    */
 
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_F10, GDK_SHIFT_MASK,
+                                       "menu.popup",
+                                       NULL);
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_Menu, 0,
+                                       "menu.popup",
+                                       NULL);
+
   /* Moving the insertion point */
   add_move_binding (widget_class, GDK_KEY_Right, 0,
                     GTK_MOVEMENT_VISUAL_POSITIONS, 1);
@@ -5871,11 +5882,12 @@ gtk_text_mnemonic_activate (GtkWidget *widget,
   return GDK_EVENT_STOP;
 }
 
-static gboolean
-gtk_text_popup_menu (GtkWidget *widget)
+static void
+gtk_text_popup_menu (GtkWidget  *widget,
+                     const char *action_name,
+                     GVariant   *parameters)
 {
   gtk_text_do_popup (GTK_TEXT (widget), -1, -1);
-  return TRUE;
 }
 
 static void
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 30e55352d4..7b4ec0a3d4 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -443,7 +443,9 @@ static gboolean gtk_text_view_drag_drop          (GtkDropTarget    *dest,
                                                   double            y,
                                                   GtkTextView      *text_view);
 
-static gboolean gtk_text_view_popup_menu         (GtkWidget     *widget);
+static void gtk_text_view_popup_menu        (GtkWidget  *widget,
+                                             const char *action_name,
+                                             GVariant   *parameters);
 static void gtk_text_view_move_cursor       (GtkTextView           *text_view,
                                              GtkMovementStep        step,
                                              gint                   count,
@@ -823,8 +825,6 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
   widget_class->snapshot = gtk_text_view_snapshot;
   widget_class->focus = gtk_text_view_focus;
 
-  widget_class->popup_menu = gtk_text_view_popup_menu;
-
   container_class->add = gtk_text_view_add;
   container_class->remove = gtk_text_view_remove;
   container_class->forall = gtk_text_view_forall;
@@ -1467,11 +1467,21 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
 
   gtk_widget_class_install_action (widget_class, "text.undo", NULL, gtk_text_view_real_undo);
   gtk_widget_class_install_action (widget_class, "text.redo", NULL, gtk_text_view_real_redo);
+  gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_text_view_popup_menu);
 
   /*
    * Key bindings
    */
 
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_F10, GDK_SHIFT_MASK,
+                                       "menu.popup",
+                                       NULL);
+  gtk_widget_class_add_binding_action (widget_class,
+                                       GDK_KEY_Menu, 0,
+                                       "menu.popup",
+                                       NULL);
+
   /* Moving the insertion point */
   add_move_binding (widget_class, GDK_KEY_Right, 0,
                     GTK_MOVEMENT_VISUAL_POSITIONS, 1);
@@ -8677,11 +8687,12 @@ gtk_text_view_do_popup (GtkTextView    *text_view,
     gdk_event_unref (trigger_event);
 }
 
-static gboolean
-gtk_text_view_popup_menu (GtkWidget *widget)
+static void
+gtk_text_view_popup_menu (GtkWidget  *widget,
+                          const char *action_name,
+                          GVariant   *parameters)
 {
   gtk_text_view_do_popup (GTK_TEXT_VIEW (widget), NULL);
-  return TRUE;
 }
 
 static void
diff --git a/testsuite/gtk/action.c b/testsuite/gtk/action.c
index 1812d45ba5..f8076de5d0 100644
--- a/testsuite/gtk/action.c
+++ b/testsuite/gtk/action.c
@@ -365,6 +365,7 @@ test_introspection (void)
     { GTK_TYPE_TEXT, "clipboard.paste", NULL, NULL },
     { GTK_TYPE_TEXT, "clipboard.copy", NULL, NULL },
     { GTK_TYPE_TEXT, "clipboard.cut", NULL, NULL },
+    { GTK_TYPE_TEXT, "menu.popup", NULL, NULL },
     { GTK_TYPE_TEXT, "text.redo", NULL, NULL },
     { GTK_TYPE_TEXT, "text.undo", NULL, NULL },
   };
@@ -378,9 +379,9 @@ test_introspection (void)
                                         &property))
     {
       g_assert (expected[i].owner == owner);
-      g_assert (strcmp (expected[i].name, name) == 0);
-      g_assert (g_strcmp0 (expected[i].params, params ? g_variant_type_peek_string (params) : NULL) == 0);
-      g_assert (g_strcmp0 (expected[i].property, property) == 0);
+      g_assert_cmpstr (expected[i].name, ==, name);
+      g_assert_cmpstr (expected[i].params, ==, params ? g_variant_type_peek_string (params) : NULL);
+      g_assert_cmpstr (expected[i].property, ==, property);
       i++;
     }
   g_assert (i == G_N_ELEMENTS (expected));


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