[gtk/wip/matthiasc/context-menu] password entry: Adapt to new context menu api



commit d8e889de04dd36ff50ac19280c4d5128db39554a
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 11 14:46:55 2019 -0400

    password entry: Adapt to new context menu api

 gtk/gtkentry.c         | 16 --------------
 gtk/gtkentry.h         |  3 ---
 gtk/gtkpasswordentry.c | 58 ++++++++++++++++++++++++++++++--------------------
 gtk/gtkpasswordentry.h |  3 +++
 4 files changed, 38 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 01ed5ff7f6..03bfa9703c 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -223,7 +223,6 @@ enum {
   PROP_INPUT_PURPOSE,
   PROP_INPUT_HINTS,
   PROP_ATTRIBUTES,
-  PROP_POPULATE_ALL,
   PROP_TABS,
   PROP_SHOW_EMOJI_ICON,
   PROP_ENABLE_EMOJI_COMPLETION,
@@ -816,19 +815,6 @@ gtk_entry_class_init (GtkEntryClass *class)
                           PANGO_TYPE_ATTR_LIST,
                           GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
 
-  /**
-   * GtkEntry:populate-all:
-   *
-   * If :populate-all is %TRUE, the #GtkEntry::populate-popup
-   * signal is also emitted for touch popups.
-   */
-  entry_props[PROP_POPULATE_ALL] =
-      g_param_spec_boolean ("populate-all",
-                            P_("Populate all"),
-                            P_("Whether to emit ::populate-popup for touch popups"),
-                            FALSE,
-                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
-
   /**
    * GtkEntry::tabs:
    *
@@ -962,7 +948,6 @@ gtk_entry_set_property (GObject         *object,
     case PROP_INPUT_PURPOSE:
     case PROP_INPUT_HINTS:
     case PROP_ATTRIBUTES:
-    case PROP_POPULATE_ALL:
     case PROP_TABS:
     case PROP_ENABLE_EMOJI_COMPLETION:
       g_object_set_property (G_OBJECT (priv->text), pspec->name, value);
@@ -1114,7 +1099,6 @@ gtk_entry_get_property (GObject         *object,
     case PROP_INPUT_PURPOSE:
     case PROP_INPUT_HINTS:
     case PROP_ATTRIBUTES:
-    case PROP_POPULATE_ALL:
     case PROP_TABS:
     case PROP_ENABLE_EMOJI_COMPLETION:
       g_object_get_property (G_OBJECT (priv->text), pspec->name, value);
diff --git a/gtk/gtkentry.h b/gtk/gtkentry.h
index 6b1352fa79..f46d19c1c1 100644
--- a/gtk/gtkentry.h
+++ b/gtk/gtkentry.h
@@ -78,9 +78,6 @@ struct _GtkEntry
 /**
  * GtkEntryClass:
  * @parent_class: The parent class.
- * @populate_popup: Class handler for the #GtkEntry::populate-popup signal. If
- *   non-%NULL, this will be called to add additional entries to the context
- *   menu when it is displayed.
  * @activate: Class handler for the #GtkEntry::activate signal. The default
  *   implementation calls gtk_window_activate_default() on the entry’s top-level
  *   window.
diff --git a/gtk/gtkpasswordentry.c b/gtk/gtkpasswordentry.c
index 36fd830db3..8e0341664e 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -100,7 +100,7 @@ focus_changed (GtkWidget *widget)
   if (priv->keymap)
     keymap_state_changed (priv->keymap, widget);
 }
-
+ 
 static void
 gtk_password_entry_toggle_peek (GtkPasswordEntry *entry)
 {
@@ -120,27 +120,6 @@ gtk_password_entry_toggle_peek (GtkPasswordEntry *entry)
     }
 }
 
-static void
-populate_popup (GtkText          *text,
-                GtkWidget        *popup,
-                GtkPasswordEntry *entry)
-{
-  GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
-
-  if (priv->peek_icon != NULL)
-    {
-      GtkWidget *item;
-
-      item = gtk_check_menu_item_new_with_mnemonic (_("_Show text"));
-      gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
-                                      gtk_text_get_visibility (text));
-      g_signal_connect_swapped (item, "activate",
-                                G_CALLBACK (gtk_password_entry_toggle_peek), entry);
-      gtk_widget_show (item);
-      gtk_menu_shell_append (GTK_MENU_SHELL (popup), item);
-    }
-}
-
 static void
 gtk_password_entry_init (GtkPasswordEntry *entry)
 {
@@ -149,11 +128,11 @@ gtk_password_entry_init (GtkPasswordEntry *entry)
   gtk_widget_set_has_surface (GTK_WIDGET (entry), FALSE);
 
   priv->entry = gtk_text_new ();
+  gtk_widget_set_context_menu (priv->entry, gtk_password_entry_get_default_context_menu (entry));
   gtk_text_set_visibility (GTK_TEXT (priv->entry), FALSE);
   gtk_widget_set_parent (priv->entry, GTK_WIDGET (entry));
   gtk_editable_init_delegate (GTK_EDITABLE (entry));
   g_signal_connect_swapped (priv->entry, "notify::has-focus", G_CALLBACK (focus_changed), entry);
-  g_signal_connect (priv->entry, "populate-popup", G_CALLBACK (populate_popup), entry);
 
   priv->icon = gtk_image_new_from_icon_name ("caps-lock-symbolic");
   gtk_widget_set_tooltip_text (priv->icon, _("Caps Lock is on"));
@@ -368,6 +347,22 @@ gtk_password_entry_mnemonic_activate (GtkWidget *widget,
   return TRUE;
 }
 
+static void
+gtk_password_entry_notify (GObject    *object,
+                           GParamSpec *pspec)
+{
+  if (strcmp (pspec->name, "context-menu") == 0)
+    {
+      GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (object);
+      GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
+      GMenuModel *menu = gtk_widget_get_context_menu (GTK_WIDGET (entry));
+      gtk_widget_set_context_menu (priv->entry, menu);
+    }
+
+  if (G_OBJECT_CLASS (gtk_password_entry_parent_class)->notify)
+    G_OBJECT_CLASS (gtk_password_entry_parent_class)->notify (object, pspec);
+}
+
 static void
 gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
 {
@@ -378,6 +373,7 @@ gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
   object_class->finalize = gtk_password_entry_finalize;
   object_class->get_property = gtk_password_entry_get_property;
   object_class->set_property = gtk_password_entry_set_property;
+  object_class->notify = gtk_password_entry_notify;
 
   widget_class->realize = gtk_password_entry_realize;
   widget_class->measure = gtk_password_entry_measure;
@@ -505,3 +501,19 @@ gtk_password_entry_get_show_peek_icon (GtkPasswordEntry *entry)
 
   return priv->peek_icon != NULL;
 }
+
+GMenuModel *
+gtk_password_entry_get_default_context_menu (GtkPasswordEntry *entry)
+{
+  GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
+  GMenuModel *menu;
+  GMenuItem *item;
+
+  menu = gtk_text_get_default_context_menu (GTK_TEXT (priv->entry));
+  item = g_menu_item_new (_("_Show Text"), "context.toggle-visibility");
+  g_menu_item_set_attribute (item, "touch-icon", "s", "eye-not-looking-symbolic");
+  g_menu_append_item (G_MENU (menu), item);
+
+  return menu;
+}
+
diff --git a/gtk/gtkpasswordentry.h b/gtk/gtkpasswordentry.h
index 2527c58ca2..9289ee4f08 100644
--- a/gtk/gtkpasswordentry.h
+++ b/gtk/gtkpasswordentry.h
@@ -61,6 +61,9 @@ void            gtk_password_entry_set_show_peek_icon (GtkPasswordEntry *entry,
 GDK_AVAILABLE_IN_ALL
 gboolean        gtk_password_entry_get_show_peek_icon (GtkPasswordEntry *entry);
 
+GDK_AVAILABLE_IN_ALL
+GMenuModel   * gtk_password_entry_get_default_context_menu (GtkPasswordEntry *entry);
+
 G_END_DECLS
 
 #endif /* __GTK_PASSWORD_ENTRY_H__ */


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