entry: Add emoji completion

Pop up completions when the text in the entry matches :word:
This functionality has to be enabled using the enable-emoji-completion
property.
This commit is contained in:
Matthias Clasen 2017-08-19 14:08:15 -04:00
parent 65bb238a3f
commit 09e3529d0e

View File

@ -39,6 +39,9 @@
#include "gtkentry.h"
#include "gtkentrybuffer.h"
#include "gtkiconhelperprivate.h"
#include "gtkemojichooser.h"
#include "gtkemojicompletion.h"
#include "gtkentrybuffer.h"
#include "gtkimcontextsimple.h"
#include "gtkimmulticontext.h"
#include "gtkintl.h"
@ -72,6 +75,7 @@
#include "gtkcsscustomgadgetprivate.h"
#include "gtkprogresstrackerprivate.h"
#include "gtkemojichooser.h"
#include "gtkwindow.h"
#include "a11y/gtkentryaccessible.h"
@ -250,6 +254,7 @@ struct _GtkEntryPrivate
guint shadow_type : 4;
guint editable : 1;
guint show_emoji_icon : 1;
guint enable_emoji_completion : 1;
guint in_drag : 1;
guint overwrite_mode : 1;
guint visible : 1;
@ -378,6 +383,7 @@ enum {
PROP_POPULATE_ALL,
PROP_TABS,
PROP_SHOW_EMOJI_ICON,
PROP_ENABLE_EMOJI_COMPLETION,
PROP_EDITING_CANCELED,
NUM_PROPERTIES = PROP_EDITING_CANCELED
};
@ -698,6 +704,8 @@ static void buffer_disconnect_signals (GtkEntry *entry);
static GtkEntryBuffer *get_buffer (GtkEntry *entry);
static void set_show_emoji_icon (GtkEntry *entry,
gboolean value);
static void set_enable_emoji_completion (GtkEntry *entry,
gboolean value);
static void gtk_entry_measure (GtkCssGadget *gadget,
GtkOrientation orientation,
@ -1531,6 +1539,13 @@ gtk_entry_class_init (GtkEntryClass *class)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
entry_props[PROP_ENABLE_EMOJI_COMPLETION] =
g_param_spec_boolean ("enable-emoji-completion",
P_("Enable Emoji completion"),
P_("Whether to suggest Emoji replacements"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, entry_props);
/**
@ -2441,6 +2456,10 @@ gtk_entry_set_property (GObject *object,
set_show_emoji_icon (entry, g_value_get_boolean (value));
break;
case PROP_ENABLE_EMOJI_COMPLETION:
set_enable_emoji_completion (entry, g_value_get_boolean (value));
break;
case PROP_SCROLL_OFFSET:
case PROP_CURSOR_POSITION:
default:
@ -2697,6 +2716,10 @@ gtk_entry_get_property (GObject *object,
g_value_set_boolean (value, priv->show_emoji_icon);
break;
case PROP_ENABLE_EMOJI_COMPLETION:
g_value_set_boolean (value, priv->enable_emoji_completion);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -11138,3 +11161,23 @@ set_show_emoji_icon (GtkEntry *entry,
g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_SHOW_EMOJI_ICON]);
gtk_widget_queue_resize (GTK_WIDGET (entry));
}
static void
set_enable_emoji_completion (GtkEntry *entry,
gboolean value)
{
GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
if (priv->enable_emoji_completion == value)
return;
priv->enable_emoji_completion = value;
if (priv->enable_emoji_completion)
g_object_set_data (G_OBJECT (entry), "emoji-completion-popup",
gtk_emoji_completion_new (entry));
else
g_object_set_data (G_OBJECT (entry), "emoji-completion-popup", NULL);
g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_ENABLE_EMOJI_COMPLETION]);
}