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



commit 4537da8bde28a9f0b05c41353373d974feb99f68
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 9923f2ed17..aef9e3544f 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -222,7 +222,6 @@ enum {
   PROP_INPUT_PURPOSE,
   PROP_INPUT_HINTS,
   PROP_ATTRIBUTES,
-  PROP_POPULATE_ALL,
   PROP_TABS,
   PROP_SHOW_EMOJI_ICON,
   PROP_ENABLE_EMOJI_COMPLETION,
@@ -815,19 +814,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:
    *
@@ -961,7 +947,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);
@@ -1113,7 +1098,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 1048382271..b383ceafc3 100644
--- a/gtk/gtkentry.h
+++ b/gtk/gtkentry.h
@@ -77,9 +77,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 activates the gtk.activate-default action.
  * @move_cursor: Class handler for the #GtkEntry::move-cursor signal. The
diff --git a/gtk/gtkpasswordentry.c b/gtk/gtkpasswordentry.c
index ddf31467ba..2cc828cb25 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -74,6 +74,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,
@@ -105,7 +107,7 @@ focus_changed (GtkWidget *widget)
   if (priv->keymap)
     keymap_state_changed (priv->keymap, widget);
 }
-
+ 
 static void
 gtk_password_entry_toggle_peek (GtkPasswordEntry *entry)
 {
@@ -125,27 +127,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)
 {
@@ -156,7 +137,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"));
@@ -165,6 +145,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
@@ -372,6 +355,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)
 {
@@ -382,6 +381,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;
@@ -389,7 +389,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"),
@@ -509,3 +508,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]