From ab8721fc04bf2dc583a958ac4a8cf2d49cae8f30 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Thu, 21 Jul 2016 22:00:03 -0300 Subject: [PATCH] keyboard: add search support Based on the latest mockups, the Keyboard panel would benefit from a search functionality. This patch add all the necessary UI and functions to make the search work. Worth noticing that the current implementation still doesn't work with search-as-you-type, which'll be addressed on a future fix. https://bugzilla.gnome.org/show_bug.cgi?id=769063 --- panels/keyboard/cc-keyboard-panel.c | 49 ++++++++++++++- panels/keyboard/gnome-keyboard-panel.ui | 79 ++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 4 deletions(-) diff --git a/panels/keyboard/cc-keyboard-panel.c b/panels/keyboard/cc-keyboard-panel.c index 124aea371..476c63720 100644 --- a/panels/keyboard/cc-keyboard-panel.c +++ b/panels/keyboard/cc-keyboard-panel.c @@ -31,6 +31,8 @@ #include "keyboard-shortcuts.h" +#include "cc-util.h" + typedef struct { CcKeyboardItem *item; gchar *section_title; @@ -41,7 +43,12 @@ struct _CcKeyboardPanel { CcPanel parent; - /* Shortcut models */ + /* Search */ + GtkWidget *empty_search_placeholder; + GtkWidget *search_button; + GtkWidget *search_entry; + + /* Shortcuts */ GtkWidget *listbox; GtkListBoxRow *add_shortcut_row; GtkSizeGroup *accelerator_sizegroup; @@ -365,6 +372,34 @@ header_function (GtkListBoxRow *row, } } +static gboolean +filter_function (GtkListBoxRow *row, + gpointer user_data) +{ + CcKeyboardPanel *self = user_data; + RowData *data; + gboolean retval; + gchar *search, *name; + + if (gtk_entry_get_text_length (GTK_ENTRY (self->search_entry)) == 0) + return TRUE; + + /* When searching, the '+' row is always hidden */ + if (row == self->add_shortcut_row) + return FALSE; + + data = g_object_get_data (G_OBJECT (row), "data"); + name = cc_util_normalize_casefold_and_unaccent (data->item->description); + search = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (self->search_entry))); + + retval = strstr (name, search) != NULL; + + g_free (search); + g_free (name); + + return retval; +} + static void shortcut_row_activated (GtkWidget *button, GtkListBoxRow *row, @@ -436,6 +471,8 @@ cc_keyboard_panel_constructed (GObject *object) /* Setup the dialog's transient parent */ toplevel = GTK_WINDOW (cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (self)))); gtk_window_set_transient_for (GTK_WINDOW (self->shortcut_editor), toplevel); + + cc_shell_embed_widget_in_header (cc_panel_get_shell (CC_PANEL (self)), self->search_button); } static void @@ -456,7 +493,10 @@ cc_keyboard_panel_class_init (CcKeyboardPanelClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/keyboard/gnome-keyboard-panel.ui"); gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, add_shortcut_row); + gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, empty_search_placeholder); gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, listbox); + gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, search_button); + gtk_widget_class_bind_template_child (widget_class, CcKeyboardPanel, search_entry); gtk_widget_class_bind_template_callback (widget_class, shortcut_row_activated); } @@ -514,5 +554,12 @@ cc_keyboard_panel_init (CcKeyboardPanel *self) header_function, self, NULL); + + gtk_list_box_set_filter_func (GTK_LIST_BOX (self->listbox), + filter_function, + self, + NULL); + + gtk_list_box_set_placeholder (GTK_LIST_BOX (self->listbox), self->empty_search_placeholder); } diff --git a/panels/keyboard/gnome-keyboard-panel.ui b/panels/keyboard/gnome-keyboard-panel.ui index cb0bdb130..c062eec51 100644 --- a/panels/keyboard/gnome-keyboard-panel.ui +++ b/panels/keyboard/gnome-keyboard-panel.ui @@ -12,22 +12,37 @@ True False True - 18 + True False vertical - center 12 + + + True + True + + + + True + 30 + + + + + True True + center True True never in + 18 True @@ -63,8 +78,11 @@ True + center False - 6 + 18 + 18 + 18 True @@ -81,4 +99,59 @@ + + True + + + + True + system-search-symbolic + + + + + True + False + center + center + True + True + 18 + vertical + 6 + + + True + False + 72 + edit-find-symbolic + + + + + + True + False + No keyboard shortcut found + + + + + + + + + True + False + Try a different search + + + +