Merge branch 'emoji-chooser-fixes' into 'master'

Emoji chooser fixes

See merge request GNOME/gtk!816
This commit is contained in:
Matthias Clasen 2019-05-05 06:41:31 +00:00
commit 96cce3ae23
3 changed files with 23 additions and 38 deletions

View File

@ -153,11 +153,9 @@ populate_recent_section (GtkEmojiChooser *chooser)
empty = FALSE;
}
if (!empty)
{
gtk_widget_show (chooser->recent.box);
gtk_widget_set_sensitive (chooser->recent.button, TRUE);
}
gtk_widget_set_visible (chooser->recent.box, !empty);
gtk_widget_set_sensitive (chooser->recent.button, !empty);
g_variant_unref (variant);
}
@ -458,15 +456,12 @@ populate_emoji_chooser (gpointer data)
return G_SOURCE_CONTINUE;
}
/* We scroll to the top on show, so check the right button for the 1st time */
gtk_widget_set_state_flags (chooser->recent.button, GTK_STATE_FLAG_CHECKED, FALSE);
g_variant_iter_free (chooser->iter);
chooser->iter = NULL;
chooser->box = NULL;
chooser->populate_idle = 0;
return G_SOURCE_REMOVE;
return G_SOURCE_REMOVE;
}
static void
@ -496,6 +491,9 @@ adj_value_changed (GtkAdjustment *adj,
EmojiSection const *section = sections[i];
GtkAllocation alloc;
if (!gtk_widget_get_visible (section->box))
continue;
if (section->heading)
gtk_widget_get_allocation (section->heading, &alloc);
else
@ -611,6 +609,13 @@ search_changed (GtkEntry *entry,
update_headings (chooser);
}
static void
stop_search (GtkEntry *entry,
gpointer data)
{
gtk_popover_popdown (GTK_POPOVER (data));
}
static void
setup_section (GtkEmojiChooser *chooser,
EmojiSection *section,
@ -693,6 +698,7 @@ gtk_emoji_chooser_show (GtkWidget *widget)
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (chooser->scrolled_window));
gtk_adjustment_set_value (adj, 0);
adj_value_changed (adj, chooser);
gtk_editable_set_text (GTK_EDITABLE (chooser->search_entry), "");
}
@ -761,6 +767,7 @@ gtk_emoji_chooser_class_init (GtkEmojiChooserClass *klass)
gtk_widget_class_bind_template_callback (widget_class, emoji_activated);
gtk_widget_class_bind_template_callback (widget_class, search_changed);
gtk_widget_class_bind_template_callback (widget_class, stop_search);
gtk_widget_class_bind_template_callback (widget_class, pressed_cb);
gtk_widget_class_bind_template_callback (widget_class, long_pressed_cb);
}

View File

@ -3447,42 +3447,19 @@ gtk_entry_enter_text (GtkEntry *entry,
gtk_text_enter_text (GTK_TEXT (priv->text), text);
}
static void
gtk_entry_insert_emoji (GtkEntry *entry)
{
GtkEntryPrivate *priv = gtk_entry_get_instance_private (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)
{
chooser = gtk_emoji_chooser_new ();
g_object_set_data (G_OBJECT (entry), "gtk-emoji-chooser", chooser);
gtk_popover_set_relative_to (GTK_POPOVER (chooser), GTK_WIDGET (entry));
if (priv->show_emoji_icon)
{
gtk_entry_get_icon_area (entry, GTK_ENTRY_ICON_SECONDARY, &rect);
gtk_popover_set_pointing_to (GTK_POPOVER (chooser), &rect);
}
g_signal_connect_swapped (chooser, "emoji-picked", G_CALLBACK (gtk_entry_enter_text), entry);
}
gtk_popover_popup (GTK_POPOVER (chooser));
}
static void
pick_emoji (GtkEntry *entry,
int icon,
GdkEvent *event,
gpointer data)
{
GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
if (gtk_widget_get_ancestor (GTK_WIDGET (entry), GTK_TYPE_EMOJI_CHOOSER) != NULL)
return;
if (icon == GTK_ENTRY_ICON_SECONDARY)
gtk_entry_insert_emoji (entry);
g_signal_emit_by_name (priv->text, "insert-emoji");
}
static void

View File

@ -10,6 +10,7 @@
<child>
<object class="GtkSearchEntry" id="search_entry">
<signal name="search-changed" handler="search_changed"/>
<signal name="stop-search" handler="stop_search"/>
</object>
</child>
<child>