[gtk+/wip/matthiasc/emoji-picker: 593/593] entry: Add a key binding for the emoji chooser



commit 394786d128e3f66f717b10036bddef182fa74056
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Nov 18 22:44:12 2017 -0500

    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

 gtk/gtkentry.c |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index bcfdbc0..d03dcaf 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -315,6 +315,7 @@ enum {
   ICON_PRESS,
   ICON_RELEASE,
   PREEDIT_CHANGED,
+  INSERT_EMOJI,
   LAST_SIGNAL
 };
 
@@ -520,6 +521,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);
@@ -749,6 +751,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;
   
   quark_password_hint = g_quark_from_static_string ("gtk-entry-password-hint");
@@ -1717,6 +1720,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
    */
@@ -1884,6 +1906,12 @@ gtk_entry_class_init (GtkEntryClass *class)
   gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Insert, 0,
                                "toggle-overwrite", 0);
 
+  /* 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, I_("entry"));
 }
@@ -8462,8 +8490,6 @@ typedef struct
   GdkEvent *trigger_event;
 } PopupInfo;
 
-static void gtk_entry_choose_emoji (GtkEntry *entry);
-
 static void
 popup_targets_received (GtkClipboard     *clipboard,
                        GtkSelectionData *data,
@@ -8528,7 +8554,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);
         }
@@ -9863,11 +9889,15 @@ 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;
+
+  g_print ("insert emoji\n");
   chooser = GTK_WIDGET (g_object_get_data (G_OBJECT (entry), "gtk-emoji-chooser"));
   if (!chooser)
     {
@@ -9893,7 +9923,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


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