[gtk/wip/matthiasc/context-menu: 3/13] password entry: Adapt to new context menu api
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/context-menu: 3/13] password entry: Adapt to new context menu api
- Date: Thu, 13 Jun 2019 12:02:55 +0000 (UTC)
commit 1b21d6ecba4aac1f787e18513dc54f75253f9c28
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 | 2 +
gtk/gtkentry.c | 16 -----
gtk/gtkentry.h | 3 -
gtk/gtkpasswordentry.c | 112 +++++++++++++++++++++++++++--------
gtk/gtkpasswordentry.h | 6 ++
5 files changed, 96 insertions(+), 43 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index e42715a721..3d7fcdcd54 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -989,6 +989,8 @@ GtkPasswordEntry
gtk_password_entry_new
gtk_password_entry_set_show_peek_icon
gtk_password_entry_get_show_peek_icon
+gtk_password_entry_set_extra_menu
+gtk_password_entry_get_extra_menu
<SUBSECTION Private>
gtk_password_entry_get_type
</SECTION>
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index c9a6cfed24..878cfee2f3 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_EXTRA_MENU,
PROP_SHOW_EMOJI_ICON,
@@ -799,19 +798,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);
@@ -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 66d0742c64..b71c4d3ac6 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..ef0651600c 100644
--- a/gtk/gtkpasswordentry.c
+++ b/gtk/gtkpasswordentry.c
@@ -58,6 +58,7 @@ typedef struct {
GtkWidget *icon;
GtkWidget *peek_icon;
GdkKeymap *keymap;
+ GMenuModel *extra_menu;
} GtkPasswordEntryPrivate;
struct _GtkPasswordEntryClass
@@ -69,6 +70,7 @@ enum {
PROP_PLACEHOLDER_TEXT = 1,
PROP_ACTIVATES_DEFAULT,
PROP_SHOW_PEEK_ICON,
+ PROP_EXTRA_MENU,
NUM_PROPERTIES
};
@@ -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,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_set_extra_menu (entry, NULL);
}
static void
@@ -195,6 +177,7 @@ gtk_password_entry_dispose (GObject *object)
g_clear_pointer (&priv->entry, gtk_widget_unparent);
g_clear_pointer (&priv->icon, gtk_widget_unparent);
g_clear_pointer (&priv->peek_icon, gtk_widget_unparent);
+ g_clear_object (&priv->extra_menu);
G_OBJECT_CLASS (gtk_password_entry_parent_class)->dispose (object);
}
@@ -235,6 +218,10 @@ gtk_password_entry_set_property (GObject *object,
gtk_password_entry_set_show_peek_icon (entry, g_value_get_boolean (value));
break;
+ case PROP_EXTRA_MENU:
+ gtk_password_entry_set_extra_menu (entry, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -267,6 +254,10 @@ gtk_password_entry_get_property (GObject *object,
g_value_set_boolean (value, gtk_password_entry_get_show_peek_icon (entry));
break;
+ case PROP_EXTRA_MENU:
+ g_value_set_object (value, priv->extra_menu);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -389,7 +380,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"),
@@ -411,6 +401,19 @@ gtk_password_entry_class_init (GtkPasswordEntryClass *klass)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GtkPasswordEntry:extra-menu:
+ *
+ * A menu model whose contents will be appended to
+ * the context menu.
+ */
+ props[PROP_EXTRA_MENU] =
+ g_param_spec_object ("extra-menu",
+ P_("Extra menu"),
+ P_("Model menu to append to the context menu"),
+ G_TYPE_MENU_MODEL,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
gtk_editable_install_properties (object_class, NUM_PROPERTIES);
@@ -509,3 +512,64 @@ gtk_password_entry_get_show_peek_icon (GtkPasswordEntry *entry)
return priv->peek_icon != NULL;
}
+
+/**
+ * gtk_password_entry_set_extra_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_set_extra_menu (GtkPasswordEntry *entry,
+ GMenuModel *model)
+{
+ GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
+ GMenu *menu;
+ GMenu *section;
+ GMenuItem *item;
+
+ g_return_if_fail (GTK_IS_PASSWORD_ENTRY (entry));
+
+ if (!g_set_object (&priv->extra_menu, model))
+ return;
+
+ 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_set_extra_menu (GTK_TEXT (priv->entry), G_MENU_MODEL (menu));
+
+ g_object_unref (menu);
+
+ g_object_notify_by_pspec (G_OBJECT (entry), props[PROP_EXTRA_MENU]);
+}
+
+/**
+ * gtk_password_entry_get_extra_menu:
+ * @self: a #GtkText
+ *
+ * Gets the menu model set with gtk_password_entry_set_extra_menu().
+ *
+ * Returns: (transfer none): (nullable): the menu model
+ */
+GMenuModel *
+gtk_password_entry_get_extra_menu (GtkPasswordEntry *entry)
+{
+ GtkPasswordEntryPrivate *priv = gtk_password_entry_get_instance_private (entry);
+
+ g_return_val_if_fail (GTK_IS_PASSWORD_ENTRY (entry), NULL);
+
+ return priv->extra_menu;
+}
diff --git a/gtk/gtkpasswordentry.h b/gtk/gtkpasswordentry.h
index 3e1bc82099..171b1bd7f3 100644
--- a/gtk/gtkpasswordentry.h
+++ b/gtk/gtkpasswordentry.h
@@ -53,6 +53,12 @@ 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_set_extra_menu (GtkPasswordEntry *entry,
+ GMenuModel *model);
+GDK_AVAILABLE_IN_ALL
+GMenuModel * gtk_password_entry_get_extra_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]