[gnome-control-center/gbsneto/search-applications: 2/4] applications: Add search entry to the sidebar
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gbsneto/search-applications: 2/4] applications: Add search entry to the sidebar
- Date: Mon, 1 Apr 2019 21:32:08 +0000 (UTC)
commit 3d4ef26173a3f4410964899a5c8f9bc1e92c9a79
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Mar 29 19:51:06 2019 -0300
applications: Add search entry to the sidebar
This matches the current mockups [1] for the panel, and
allows easily finding applications.
[1] https://gitlab.gnome.org/Teams/Design/settings-mockups/raw/master/applications/applications-wires.png
panels/applications/cc-applications-panel.c | 68 +++++++++++++++++++++++++++-
panels/applications/cc-applications-panel.ui | 26 +++++++++--
2 files changed, 90 insertions(+), 4 deletions(-)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index 21a34bb4d..57a6d49ad 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -31,6 +31,7 @@
#include "cc-info-row.h"
#include "cc-action-row.h"
#include "cc-applications-resources.h"
+#include "cc-util.h"
#include "globs.h"
#include "list-box-helper.h"
#include "search.h"
@@ -44,7 +45,9 @@ struct _CcApplicationsPanel
{
CcPanel parent;
+ GtkWidget *sidebar_box;
GtkListBox *sidebar_listbox;
+ GtkEntry *sidebar_search_entry;
GtkWidget *header_button;
GtkWidget *title_label;
GAppInfoMonitor *monitor;
@@ -1433,6 +1436,26 @@ compare_rows (GtkListBoxRow *row1,
return strcmp (key1, key2);
}
+static gboolean
+filter_sidebar_rows (GtkListBoxRow *row,
+ gpointer data)
+{
+ CcApplicationsPanel *self = CC_APPLICATIONS_PANEL (data);
+ g_autofree gchar *app_name = NULL;
+ g_autofree gchar *search_text = NULL;
+ GAppInfo *info;
+
+ /* Only filter after the second character */
+ if (gtk_entry_get_text_length (self->sidebar_search_entry) < 2)
+ return TRUE;
+
+ info = cc_applications_row_get_info (CC_APPLICATIONS_ROW (row));
+ app_name = cc_util_normalize_casefold_and_unaccent (g_app_info_get_name (info));
+ search_text = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (self->sidebar_search_entry));
+
+ return g_strstr_len (app_name, -1, search_text) != NULL;
+}
+
static void
apps_changed (GAppInfoMonitor *monitor,
CcApplicationsPanel *self)
@@ -1492,6 +1515,40 @@ select_app (CcApplicationsPanel *self,
}
}
+static void
+on_sidebar_search_entry_activated_cb (GtkSearchEntry *search_entry,
+ CcApplicationsPanel *self)
+{
+ GtkListBoxRow *row;
+
+ row = gtk_list_box_get_row_at_y (self->sidebar_listbox, 0);
+
+ if (!row)
+ return;
+
+ /* Show the app */
+ gtk_list_box_select_row (self->sidebar_listbox, row);
+ g_signal_emit_by_name (row, "activate");
+
+ /* Cleanup the entry */
+ gtk_entry_set_text (self->sidebar_search_entry, "");
+ gtk_widget_grab_focus (GTK_WIDGET (self->sidebar_search_entry));
+}
+
+static void
+on_sidebar_search_entry_search_changed_cb (GtkSearchEntry *search_entry,
+ CcApplicationsPanel *self)
+{
+ gtk_list_box_invalidate_filter (self->sidebar_listbox);
+}
+
+static void
+on_sidebar_search_entry_search_stopped_cb (GtkSearchEntry *search_entry,
+ CcApplicationsPanel *self)
+{
+ gtk_entry_set_text (self->sidebar_search_entry, "");
+}
+
static void
cc_applications_panel_dispose (GObject *object)
{
@@ -1577,7 +1634,7 @@ static GtkWidget*
cc_applications_panel_get_sidebar_widget (CcPanel *panel)
{
CcApplicationsPanel *self = CC_APPLICATIONS_PANEL (panel);
- return GTK_WIDGET (self->sidebar_listbox);
+ return self->sidebar_box;
}
static GtkWidget *
@@ -1631,7 +1688,9 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, notification);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, permission_section);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, permission_list);
+ gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_box);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_listbox);
+ gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sidebar_search_entry);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, search);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, sound);
gtk_widget_class_bind_template_child (widget_class, CcApplicationsPanel, stack);
@@ -1656,6 +1715,9 @@ cc_applications_panel_class_init (CcApplicationsPanelClass *klass)
gtk_widget_class_bind_template_callback (widget_class, storage_row_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, open_software_cb);
gtk_widget_class_bind_template_callback (widget_class, handler_reset_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_sidebar_search_entry_activated_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_sidebar_search_entry_search_changed_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_sidebar_search_entry_search_stopped_cb);
}
static void
@@ -1711,6 +1773,10 @@ cc_applications_panel_init (CcApplicationsPanel *self)
compare_rows,
NULL, NULL);
+ gtk_list_box_set_filter_func (self->sidebar_listbox,
+ filter_sidebar_rows,
+ self, NULL);
+
self->location_settings = g_settings_new ("org.gnome.system.location");
self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
self->search_settings = g_settings_new ("org.gnome.desktop.search-providers");
diff --git a/panels/applications/cc-applications-panel.ui b/panels/applications/cc-applications-panel.ui
index b4fbbfc79..ea0bca9de 100644
--- a/panels/applications/cc-applications-panel.ui
+++ b/panels/applications/cc-applications-panel.ui
@@ -412,9 +412,29 @@
<property name="visible">1</property>
<property name="label" translatable="yes">Open in Software</property>
</object>
- <object class="GtkListBox" id="sidebar_listbox">
- <property name="visible">1</property>
- <property name="selection-mode">browse</property>
+
+ <!-- Sidebar -->
+ <object class="GtkBox" id="sidebar_box">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkSearchEntry" id="sidebar_search_entry">
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="has-focus">True</property>
+ <property name="margin">12</property>
+ <property name="margin-bottom">6</property>
+ <signal name="activate" handler="on_sidebar_search_entry_activated_cb" object="CcApplicationsPanel"
swapped="no" />
+ <signal name="search-changed" handler="on_sidebar_search_entry_search_changed_cb"
object="CcApplicationsPanel" swapped="no" />
+ <signal name="stop-search" handler="on_sidebar_search_entry_search_stopped_cb"
object="CcApplicationsPanel" swapped="no" />
+ </object>
+ </child>
+ <child>
+ <object class="GtkListBox" id="sidebar_listbox">
+ <property name="visible">True</property>
+ <property name="selection-mode">browse</property>
+ </object>
+ </child>
</object>
<!-- Built-in Permissions dialog -->
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]