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



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

    password entry: Adapt to new context menu api

 docs/reference/gtk/gtk4-sections.txt |  1 +
 gtk/gtkentry.c                       | 16 ----------
 gtk/gtkentry.h                       |  3 --
 gtk/gtkpasswordentry.c               | 62 ++++++++++++++++++++++--------------
 gtk/gtkpasswordentry.h               |  4 +++
 5 files changed, 43 insertions(+), 43 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index e8393f5c1b..191500511c 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -987,6 +987,7 @@ GtkPasswordEntry
 gtk_password_entry_new
 gtk_password_entry_set_show_peek_icon
 gtk_password_entry_get_show_peek_icon
+gtk_password_entry_add_to_context_menu
 <SUBSECTION Private>
 gtk_password_entry_get_type
 </SECTION>
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index aee434f935..e60e25eab3 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,
@@ -798,19 +797,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:
    *
@@ -944,7 +930,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);
@@ -1096,7 +1081,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 a060d04fb5..c528aa4c82 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..a47d8f2c6d 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -105,7 +105,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 +125,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 +135,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 +143,8 @@ 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_password_entry_add_to_context_menu (entry, NULL);
 }
 
 static void
@@ -389,7 +369,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 +488,38 @@ gtk_password_entry_get_show_peek_icon (GtkPasswordEntry *entry)
 
   return priv->peek_icon != NULL;
 }
+
+/**
+ * gtk_password_entry_add_to_context_menu:
+ * @entry: a #GtkPasswordEntry
+ * @model: (allow-none): a #GMenuModel
+ *
+ * Sets a menu model to add when constructing
+ * the context menu for @entry.
+ */
+void
+gtk_password_entry_add_to_context_menu (GtkPasswordEntry *entry,
+                                        GMenuModel       *model)
+{
+  GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
+  GMenu *menu;
+  GMenu *section;
+  GMenuItem *item;
+
+  menu = g_menu_new ();
+
+  section = g_menu_new ();
+  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 (section, item);
+  g_object_unref (item);
+
+  g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
+  g_object_unref (section);
+
+  if (model)
+    g_menu_append_section (menu, NULL, model);
+
+  gtk_text_add_to_context_menu (GTK_TEXT (priv->entry), G_MENU_MODEL (menu));
+  g_object_unref (menu);
+}
diff --git a/gtk/gtkpasswordentry.h b/gtk/gtkpasswordentry.h
index 3e1bc82099..47837c94dd 100644
--- a/gtk/gtkpasswordentry.h
+++ b/gtk/gtkpasswordentry.h
@@ -53,6 +53,10 @@ 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
+void            gtk_password_entry_add_to_context_menu (GtkPasswordEntry *entry,
+                                                        GMenuModel       *model);
+
 G_END_DECLS
 
 #endif /* __GTK_PASSWORD_ENTRY_H__ */


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