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



commit 71e651baf03c86bb6b25ec189d40bfea4883b344
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 | 64 +++++++++++++++++++++++++++++++-------------------
 3 files changed, 40 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index ff538481ff..c00ca29cde 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -219,7 +219,6 @@ enum {
   PROP_INPUT_PURPOSE,
   PROP_INPUT_HINTS,
   PROP_ATTRIBUTES,
-  PROP_POPULATE_ALL,
   PROP_TABS,
   PROP_SHOW_EMOJI_ICON,
   PROP_ENABLE_EMOJI_COMPLETION,
@@ -812,19 +811,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:
    *
@@ -958,7 +944,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);
@@ -1110,7 +1095,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 66da3da822..880121c8d4 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 725ef96a0d..688efe2d4c 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -69,6 +69,8 @@ enum {
 
 static GParamSpec *props[NUM_PROPERTIES] = { NULL, };
 
+static GMenuModel *gtk_password_entry_get_default_menu (GtkWidget *widget);
+
 static void gtk_password_entry_editable_init (GtkEditableInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkPasswordEntry, gtk_password_entry, GTK_TYPE_WIDGET,
@@ -100,7 +102,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 +122,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)
 {
@@ -153,7 +134,6 @@ gtk_password_entry_init (GtkPasswordEntry *entry)
   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"));
@@ -162,6 +142,9 @@ gtk_password_entry_init (GtkPasswordEntry *entry)
   gtk_widget_set_parent (priv->icon, GTK_WIDGET (entry));
 
   gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (entry)), I_("password"));
+
+  gtk_widget_set_context_menu (GTK_WIDGET (entry),
+                               gtk_password_entry_get_default_menu (GTK_WIDGET (entry)));
 }
 
 static void
@@ -369,6 +352,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)
 {
@@ -379,6 +378,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;
@@ -386,7 +386,6 @@ gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
   widget_class->get_accessible = gtk_password_entry_get_accessible;
   widget_class->grab_focus = gtk_password_entry_grab_focus;
   widget_class->mnemonic_activate = gtk_password_entry_mnemonic_activate;
- 
   props[PROP_PLACEHOLDER_TEXT] =
       g_param_spec_string ("placeholder-text",
                            P_("Placeholder text"),
@@ -506,3 +505,20 @@ gtk_password_entry_get_show_peek_icon (GtkPasswordEntry *entry)
 
   return priv->peek_icon != NULL;
 }
+
+static GMenuModel *
+gtk_password_entry_get_default_menu (GtkWidget *widget)
+{
+  GtkPasswordEntry *entry = GTK_PASSWORD_ENTRY (widget);
+  GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
+  GMenuModel *menu;
+  GMenuItem *item;
+
+  menu = gtk_widget_get_context_menu (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;
+}
+


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