[gtk+/wip/matthiasc/emoji-picker] Don't recreate pickers all the time
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/emoji-picker] Don't recreate pickers all the time
- Date: Fri, 11 Aug 2017 03:27:20 +0000 (UTC)
commit fdc6679b8476ff7f6666b0d5b10e5fa61a86e949
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Aug 10 21:34:23 2017 -0400
Don't recreate pickers all the time
Keep the first picker around. This lets us test the recent
list without persisting it yet.
tests/testentryicons.c | 19 +++++++++++--------
1 files changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/tests/testentryicons.c b/tests/testentryicons.c
index eb70c8e..9548038 100644
--- a/tests/testentryicons.c
+++ b/tests/testentryicons.c
@@ -8,10 +8,7 @@ emoji_activated (GtkEmojiPicker *picker, const char *text, GtkEntry *entry)
int pos, start, end;
if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
-{
-g_print ("selection: %d %d\n", start, end);
gtk_editable_delete_text (GTK_EDITABLE (entry), start, end);
-}
pos = MIN (start, end);
gtk_editable_insert_text (GTK_EDITABLE (entry), text, -1, &pos);
@@ -21,13 +18,19 @@ g_print ("selection: %d %d\n", start, end);
static void
pick_emoji (GtkEntry *entry, gint icon, GdkEvent *event, gpointer data)
{
- GtkWidget *picker = gtk_emoji_picker_new ();
+ GtkWidget *picker;
GdkRectangle rect;
- gtk_popover_set_relative_to (GTK_POPOVER (picker), GTK_WIDGET (entry));
- gtk_entry_get_icon_area (entry, GTK_ENTRY_ICON_SECONDARY, &rect);
- gtk_popover_set_pointing_to (GTK_POPOVER (picker), &rect);
- g_signal_connect (picker, "activated", G_CALLBACK (emoji_activated), entry);
+ picker = GTK_WIDGET (g_object_get_data (G_OBJECT (entry), "emoji-picker"));
+ if (!picker) {
+ picker = gtk_emoji_picker_new ();
+ g_object_set_data_full (G_OBJECT (entry), "emoji-picker", picker,
(GDestroyNotify)gtk_widget_destroy);
+
+ gtk_popover_set_relative_to (GTK_POPOVER (picker), GTK_WIDGET (entry));
+ gtk_entry_get_icon_area (entry, GTK_ENTRY_ICON_SECONDARY, &rect);
+ gtk_popover_set_pointing_to (GTK_POPOVER (picker), &rect);
+ g_signal_connect (picker, "activated", G_CALLBACK (emoji_activated), entry);
+ }
gtk_popover_popup (GTK_POPOVER (picker));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]