[gnome-software] Show the search button in the search shell
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Show the search button in the search shell
- Date: Thu, 2 Jun 2016 13:20:31 +0000 (UTC)
commit 21a3e787b6be71fee72ead7763e46d076bed68fb
Author: Richard Hughes <richard hughsie com>
Date: Thu Jun 2 14:00:51 2016 +0100
Show the search button in the search shell
This is actually a different button entirely, and clicking it takes you back
to the overview shell.
src/gs-common.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
src/gs-common.h | 1 +
src/gs-shell-overview.c | 28 ++++------------------------
src/gs-shell-search.c | 18 ++++++++++++++++++
4 files changed, 70 insertions(+), 24 deletions(-)
---
diff --git a/src/gs-common.c b/src/gs-common.c
index c64aa68..3c2c22d 100644
--- a/src/gs-common.c
+++ b/src/gs-common.c
@@ -866,4 +866,51 @@ gs_utils_show_error_dialog (GtkWindow *parent,
gtk_widget_show (dialog);
}
+static void
+gs_search_button_cb (GtkToggleButton *toggle_button, GtkSearchBar *search_bar)
+{
+ gtk_search_bar_set_search_mode (search_bar,
+ gtk_toggle_button_get_active (toggle_button));
+}
+
+static void
+gs_search_mode_enabled_cb (GtkSearchBar *search_bar,
+ GParamSpec *pspec,
+ GtkToggleButton *toggle_button)
+{
+ gtk_toggle_button_set_active (toggle_button,
+ gtk_search_bar_get_search_mode (search_bar));
+}
+
+/**
+ * gs_search_button_new:
+ *
+ * Creates a new search toggle button.
+ */
+GtkWidget *
+gs_search_button_new (GtkSearchBar *search_bar)
+{
+ GtkWidget *widget;
+ GtkWidget *im;
+
+ widget = gtk_toggle_button_new ();
+ im = gtk_image_new_from_icon_name ("edit-find-symbolic", GTK_ICON_SIZE_BUTTON);
+ gtk_widget_set_visible (im, TRUE);
+ gtk_container_add (GTK_CONTAINER (widget), im);
+ gtk_widget_set_visible (widget, TRUE);
+
+ if (search_bar != NULL) {
+ /* show the search bar when clicked */
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (gs_search_button_cb),
+ search_bar);
+ /* set the button enabled when search appears */
+ g_signal_connect (search_bar, "notify::search-mode-enabled",
+ G_CALLBACK (gs_search_mode_enabled_cb),
+ widget);
+ }
+
+ return widget;
+}
+
/* vim: set noexpandtab: */
diff --git a/src/gs-common.h b/src/gs-common.h
index 43dff11..770b2d8 100644
--- a/src/gs-common.h
+++ b/src/gs-common.h
@@ -67,6 +67,7 @@ void gs_utils_show_error_dialog (GtkWindow *parent,
const gchar *title,
const gchar *msg,
const gchar *details);
+GtkWidget *gs_search_button_new (GtkSearchBar *search_bar);
G_END_DECLS
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 43f5716..67cc027 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -49,7 +49,6 @@ typedef struct
gboolean loading_categories;
gboolean empty;
gchar *category_of_day;
-
GtkWidget *search_button;
GtkWidget *bin_featured;
@@ -517,20 +516,6 @@ gs_shell_overview_switch_to (GsPage *page, gboolean scroll_up)
}
static void
-gs_shell_overview_search_button_cb (GtkButton *button, GsShellOverview *self)
-{
- GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self);
- GtkSearchBar *search_bar;
- GtkToggleButton *search_button;
-
- search_button = GTK_TOGGLE_BUTTON (priv->search_button);
- search_bar = GTK_SEARCH_BAR (gtk_builder_get_object (priv->builder,
- "search_bar"));
- gtk_search_bar_set_search_mode (search_bar,
- gtk_toggle_button_get_active (search_button));
-}
-
-static void
gs_shell_overview_categories_expander_cb (GtkButton *button, GsShellOverview *self)
{
GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self);
@@ -548,9 +533,9 @@ gs_shell_overview_setup (GsShellOverview *self,
GCancellable *cancellable)
{
GsShellOverviewPrivate *priv = gs_shell_overview_get_instance_private (self);
+ GtkSearchBar *search_bar;
GtkAdjustment *adj;
GtkWidget *tile;
- GtkWidget *im;
gint i;
g_return_if_fail (GS_IS_SHELL_OVERVIEW (self));
@@ -581,15 +566,10 @@ gs_shell_overview_setup (GsShellOverview *self,
G_CALLBACK (gs_shell_overview_categories_expander_cb), self);
/* search button */
- priv->search_button = gtk_toggle_button_new ();
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->search_button), FALSE);
- im = gtk_image_new_from_icon_name ("edit-find-symbolic", GTK_ICON_SIZE_BUTTON);
- gtk_widget_set_visible (im, TRUE);
- gtk_container_add (GTK_CONTAINER (priv->search_button), im);
- gtk_widget_set_visible (priv->search_button, TRUE);
+ search_bar = GTK_SEARCH_BAR (gtk_builder_get_object (priv->builder,
+ "search_bar"));
+ priv->search_button = gs_search_button_new (search_bar);
gs_page_set_header_end_widget (GS_PAGE (self), priv->search_button);
- g_signal_connect (priv->search_button, "clicked",
- G_CALLBACK (gs_shell_overview_search_button_cb), self);
/* chain up */
gs_page_setup (GS_PAGE (self),
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index 7e71c99..349959d 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -44,6 +44,7 @@ struct _GsShellSearch
gchar *appid_to_show;
gchar *value;
guint waiting_id;
+ GtkWidget *search_button;
GtkWidget *list_box_search;
GtkWidget *scrolledwindow_search;
@@ -252,6 +253,9 @@ gs_shell_search_switch_to (GsPage *page, gboolean scroll_up)
widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "search_bar"));
gtk_widget_show (widget);
+ /* hardcode */
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->search_button), TRUE);
+
if (scroll_up) {
GtkAdjustment *adj;
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolledwindow_search));
@@ -386,6 +390,14 @@ gs_shell_search_app_removed (GsPage *page, GsApp *app)
gs_shell_search_reload (GS_SHELL_SEARCH (page));
}
+static void
+gs_shell_search_search_button_cb (GtkButton *button, GsShellSearch *self)
+{
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+ return;
+ gs_shell_change_mode (self->shell, GS_SHELL_MODE_OVERVIEW, NULL, NULL, TRUE);
+}
+
/**
* gs_shell_search_setup:
*/
@@ -418,6 +430,12 @@ gs_shell_search_setup (GsShellSearch *self,
gs_shell_search_sort_func,
self, NULL);
+ /* search button */
+ self->search_button = gs_search_button_new (NULL);
+ gs_page_set_header_end_widget (GS_PAGE (self), self->search_button);
+ g_signal_connect (self->search_button, "clicked",
+ G_CALLBACK (gs_shell_search_search_button_cb), self);
+
/* chain up */
gs_page_setup (GS_PAGE (self),
shell,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]