[gnome-software/gnome-3-20] trivial: Factor out gs_shell_search_set_text



commit d37181e6aa4ab2904382ca1129055a3835ec43c9
Author: Kalev Lember <klember redhat com>
Date:   Tue Feb 23 11:26:23 2016 +0100

    trivial: Factor out gs_shell_search_set_text
    
    ... instead of having an extra parameter in gs_shell_search_switch_to.

 src/gs-shell-search.c |   12 ++++++++----
 src/gs-shell-search.h |    3 ++-
 src/gs-shell.c        |   14 +++++++++-----
 3 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/src/gs-shell-search.c b/src/gs-shell-search.c
index ee8b5e2..7772876 100644
--- a/src/gs-shell-search.c
+++ b/src/gs-shell-search.c
@@ -197,11 +197,18 @@ gs_shell_search_set_appid_to_show (GsShellSearch *self, const gchar *appid)
        self->appid_to_show = g_strdup (appid);
 }
 
+void
+gs_shell_search_set_text (GsShellSearch *self, const gchar *value)
+{
+       g_free (self->value);
+       self->value = g_strdup (value);
+}
+
 /**
  * gs_shell_search_switch_to:
  **/
 void
-gs_shell_search_switch_to (GsShellSearch *self, const gchar *value, gboolean scroll_up)
+gs_shell_search_switch_to (GsShellSearch *self, gboolean scroll_up)
 {
        GtkWidget *widget;
 
@@ -223,9 +230,6 @@ gs_shell_search_switch_to (GsShellSearch *self, const gchar *value, gboolean scr
                gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
        }
 
-       g_free (self->value);
-       self->value = g_strdup (value);
-
        gs_shell_search_load (self);
 }
 
diff --git a/src/gs-shell-search.h b/src/gs-shell-search.h
index 0260a1d..bb64fb8 100644
--- a/src/gs-shell-search.h
+++ b/src/gs-shell-search.h
@@ -38,8 +38,9 @@ G_DECLARE_FINAL_TYPE (GsShellSearch, gs_shell_search, GS, SHELL_SEARCH, GsPage)
 GsShellSearch  *gs_shell_search_new            (void);
 void            gs_shell_search_set_appid_to_show (GsShellSearch       *self,
                                                 const gchar            *appid);
+void            gs_shell_search_set_text       (GsShellSearch          *self,
+                                                const gchar            *value);
 void            gs_shell_search_switch_to      (GsShellSearch          *self,
-                                                const gchar            *text,
                                                 gboolean                scroll_up);
 void            gs_shell_search_reload         (GsShellSearch          *self);
 void            gs_shell_search_setup          (GsShellSearch          *self,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 37bcb14..6103eb6 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -198,7 +198,8 @@ gs_shell_change_mode (GsShell *shell,
        case GS_SHELL_MODE_SEARCH:
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
                text = gtk_entry_get_text (GTK_ENTRY (widget));
-               gs_shell_search_switch_to (priv->shell_search, text, scroll_up);
+               gs_shell_search_set_text (priv->shell_search, text);
+               gs_shell_search_switch_to (priv->shell_search, scroll_up);
                break;
        case GS_SHELL_MODE_UPDATES:
                gs_shell_updates_switch_to (priv->shell_updates, scroll_up);
@@ -319,7 +320,8 @@ gs_shell_search_activated_cb (GtkEntry *entry, GsShell *shell)
                return;
 
        if (gs_shell_get_mode (shell) == GS_SHELL_MODE_SEARCH) {
-               gs_shell_search_switch_to (priv->shell_search, text, TRUE);
+               gs_shell_search_set_text (priv->shell_search, text);
+               gs_shell_search_switch_to (priv->shell_search, TRUE);
        } else {
                gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, NULL, NULL, TRUE);
        }
@@ -443,10 +445,12 @@ search_changed_handler (GObject *entry, GsShell *shell)
        }
 
        if (strlen(text) > 2) {
-               if (gs_shell_get_mode (shell) != GS_SHELL_MODE_SEARCH)
+               if (gs_shell_get_mode (shell) != GS_SHELL_MODE_SEARCH) {
                        gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, NULL, NULL, TRUE);
-               else
-                       gs_shell_search_switch_to (priv->shell_search, text, TRUE);
+               } else {
+                       gs_shell_search_set_text (priv->shell_search, text);
+                       gs_shell_search_switch_to (priv->shell_search, TRUE);
+               }
        }
 }
 


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