entry: Add a key binding for the emoji chooser

Make Ctrl-. and Ctrl-; bring up the emoji chooser.

https://bugzilla.gnome.org/show_bug.cgi?id=789160
This commit is contained in:
Matthias Clasen 2017-11-18 22:44:12 -05:00 committed by Daniel Boles
parent 6b126a70e2
commit d3eacaf840
2 changed files with 34 additions and 6 deletions

View File

@ -322,6 +322,7 @@ enum {
ICON_PRESS,
ICON_RELEASE,
PREEDIT_CHANGED,
INSERT_EMOJI,
LAST_SIGNAL
};
@ -546,6 +547,7 @@ static void gtk_entry_cut_clipboard (GtkEntry *entry);
static void gtk_entry_copy_clipboard (GtkEntry *entry);
static void gtk_entry_paste_clipboard (GtkEntry *entry);
static void gtk_entry_toggle_overwrite (GtkEntry *entry);
static void gtk_entry_insert_emoji (GtkEntry *entry);
static void gtk_entry_select_all (GtkEntry *entry);
static void gtk_entry_real_activate (GtkEntry *entry);
static gboolean gtk_entry_popup_menu (GtkWidget *widget);
@ -812,6 +814,7 @@ gtk_entry_class_init (GtkEntryClass *class)
class->copy_clipboard = gtk_entry_copy_clipboard;
class->paste_clipboard = gtk_entry_paste_clipboard;
class->toggle_overwrite = gtk_entry_toggle_overwrite;
class->insert_emoji = gtk_entry_insert_emoji;
class->activate = gtk_entry_real_activate;
class->get_text_area_size = gtk_entry_get_text_area_size;
class->get_frame_size = gtk_entry_get_frame_size;
@ -1900,6 +1903,25 @@ gtk_entry_class_init (GtkEntryClass *class)
G_TYPE_STRING);
/**
* GtkEntry::insert-emoji:
* @entry: the object which received the signal
*
* The ::insert-emoji signal is a
* [keybinding signal][GtkBindingSignal]
* which gets emitted to present the Emoji chooser for the entry.
*
* The default bindings for this signal are Ctrl-. and Ctrl-;
*/
signals[INSERT_EMOJI] =
g_signal_new (I_("insert-emoji"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkEntryClass, insert_emoji),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
/*
* Key bindings
*/
@ -2085,6 +2107,11 @@ gtk_entry_class_init (GtkEntryClass *class)
GTK_TYPE_BORDER,
GTK_PARAM_READABLE |
G_PARAM_DEPRECATED));
/* Emoji */
gtk_binding_entry_add_signal (binding_set, GDK_KEY_period, GDK_CONTROL_MASK,
"insert-emoji", 0);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_semicolon, GDK_CONTROL_MASK,
"insert-emoji", 0);
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_ENTRY_ACCESSIBLE);
gtk_widget_class_set_css_name (widget_class, "entry");
@ -9522,8 +9549,6 @@ typedef struct
GdkEvent *trigger_event;
} PopupInfo;
static void gtk_entry_choose_emoji (GtkEntry *entry);
static void
popup_targets_received (GtkClipboard *clipboard,
GtkSelectionData *data,
@ -9589,7 +9614,7 @@ popup_targets_received (GtkClipboard *clipboard,
mode == DISPLAY_NORMAL &&
info_entry_priv->editable);
g_signal_connect_swapped (menuitem, "activate",
G_CALLBACK (gtk_entry_choose_emoji), entry);
G_CALLBACK (gtk_entry_insert_emoji), entry);
gtk_widget_show (menuitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
}
@ -11048,11 +11073,14 @@ gtk_entry_get_tabs (GtkEntry *entry)
}
static void
gtk_entry_choose_emoji (GtkEntry *entry)
gtk_entry_insert_emoji (GtkEntry *entry)
{
GtkWidget *chooser;
GdkRectangle rect;
if (gtk_widget_get_ancestor (GTK_WIDGET (entry), GTK_TYPE_EMOJI_CHOOSER) != NULL)
return;
chooser = GTK_WIDGET (g_object_get_data (G_OBJECT (entry), "gtk-emoji-chooser"));
if (!chooser)
{
@ -11078,7 +11106,7 @@ pick_emoji (GtkEntry *entry,
gpointer data)
{
if (icon == GTK_ENTRY_ICON_SECONDARY)
gtk_entry_choose_emoji (entry);
gtk_entry_insert_emoji (entry);
}
static void

View File

@ -146,6 +146,7 @@ struct _GtkEntryClass
void (* copy_clipboard) (GtkEntry *entry);
void (* paste_clipboard) (GtkEntry *entry);
void (* toggle_overwrite) (GtkEntry *entry);
void (* insert_emoji) (GtkEntry *entry);
/* hooks to add other objects beside the entry (like in GtkSpinButton) */
void (* get_text_area_size) (GtkEntry *entry,
@ -168,7 +169,6 @@ struct _GtkEntryClass
void (*_gtk_reserved4) (void);
void (*_gtk_reserved5) (void);
void (*_gtk_reserved6) (void);
void (*_gtk_reserved7) (void);
};
GDK_AVAILABLE_IN_ALL