[gnome-software] Improve scrolling



commit 5a65843ab0ef6c3ffd30d60bd340d676be7f5201
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 31 22:07:57 2013 -0400

    Improve scrolling
    
    Arrange things so that we scroll to the top only when switching
    pages using the main buttons, not when going back from a category
    or app page.

 src/gs-shell-installed.c |   16 +++++++++-------
 src/gs-shell-installed.h |    3 ++-
 src/gs-shell-overview.c  |   28 +++++++++++++++++-----------
 src/gs-shell-overview.h  |    3 ++-
 src/gs-shell-updates.c   |    9 ++++++++-
 src/gs-shell-updates.h   |    3 ++-
 src/gs-shell.c           |   28 ++++++++++++++--------------
 7 files changed, 54 insertions(+), 36 deletions(-)
---
diff --git a/src/gs-shell-installed.c b/src/gs-shell-installed.c
index 7e86dde..027bdc1 100644
--- a/src/gs-shell-installed.c
+++ b/src/gs-shell-installed.c
@@ -276,12 +276,11 @@ resort_list (GsShellInstalled *shell)
  * gs_shell_installed_refresh:
  **/
 void
-gs_shell_installed_refresh (GsShellInstalled *shell_installed)
+gs_shell_installed_refresh (GsShellInstalled *shell_installed, gboolean scroll_up)
 {
        GsShellInstalledPrivate *priv = shell_installed->priv;
         GtkWidget *widget;
         GtkSpinner *spinner;
-        GtkAdjustment *adj;
 
         if (gs_shell_get_mode (priv->shell) == GS_SHELL_MODE_INSTALLED) {
                 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
@@ -290,12 +289,15 @@ gs_shell_installed_refresh (GsShellInstalled *shell_installed)
 
         resort_list (shell_installed);
 
-        /* scroll to top */
         widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_install"));
-        adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (widget));
-        gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
-
-        gs_grab_focus_when_mapped (widget);
+        if (scroll_up) {
+                GtkAdjustment *adj;
+                adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (widget));
+                gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
+        }
+        if (gs_shell_get_mode (priv->shell) == GS_SHELL_MODE_INSTALLED) {
+                gs_grab_focus_when_mapped (widget);
+        }
 
        /* no need to refresh */
        if (priv->cache_valid)
diff --git a/src/gs-shell-installed.h b/src/gs-shell-installed.h
index 75cb9ac..39fb2cc 100644
--- a/src/gs-shell-installed.h
+++ b/src/gs-shell-installed.h
@@ -53,7 +53,8 @@ GType          gs_shell_installed_get_type    (void);
 
 GsShellInstalled *gs_shell_installed_new       (void);
 void            gs_shell_installed_invalidate  (GsShellInstalled       *shell_installed);
-void            gs_shell_installed_refresh     (GsShellInstalled       *shell_installed);
+void            gs_shell_installed_refresh     (GsShellInstalled       *shell_installed,
+                                                 gboolean                scroll_up);
 void            gs_shell_installed_setup       (GsShellInstalled       *shell_installed,
                                                  GsShell                *shell,
                                                 GsPluginLoader         *plugin_loader,
diff --git a/src/gs-shell-overview.c b/src/gs-shell-overview.c
index 42f9ed9..ee51c88 100644
--- a/src/gs-shell-overview.c
+++ b/src/gs-shell-overview.c
@@ -280,25 +280,31 @@ out:
  * gs_shell_overview_refresh:
  **/
 void
-gs_shell_overview_refresh (GsShellOverview *shell_overview)
+gs_shell_overview_refresh (GsShellOverview *shell_overview, gboolean scroll_up)
 {
        GsShellOverviewPrivate *priv = shell_overview->priv;
        GtkWidget *widget;
        GtkWidget *grid;
         GtkAdjustment *adj;
 
-        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
-        gtk_widget_show (widget);
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
-       gtk_widget_show (widget);
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
-        gtk_entry_set_text (GTK_ENTRY (widget), "");
+        if (gs_shell_get_mode (priv->shell) == GS_SHELL_MODE_OVERVIEW) {
+                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "buttonbox_main"));
+                gtk_widget_show (widget);
+               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "search_bar"));
+               gtk_widget_show (widget);
+               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
+                gtk_entry_set_text (GTK_ENTRY (widget), "");
+        }
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_overview"));
-        adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (widget));
-        gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
-
-        gs_grab_focus_when_mapped (widget);
+        if (scroll_up) {
+                adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (widget));
+                gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
+        }
+
+        if (gs_shell_get_mode (priv->shell) == GS_SHELL_MODE_OVERVIEW) {
+                gs_grab_focus_when_mapped (widget);
+        }
 
        /* no need to refresh */
        if (priv->cache_valid)
diff --git a/src/gs-shell-overview.h b/src/gs-shell-overview.h
index 1c0812a..dbc1926 100644
--- a/src/gs-shell-overview.h
+++ b/src/gs-shell-overview.h
@@ -57,7 +57,8 @@ GType          gs_shell_overview_get_type     (void);
 
 GsShellOverview        *gs_shell_overview_new          (void);
 void            gs_shell_overview_invalidate   (GsShellOverview        *shell_overview);
-void            gs_shell_overview_refresh      (GsShellOverview        *shell_overview);
+void            gs_shell_overview_refresh      (GsShellOverview        *shell_overview,
+                                                 gboolean                scroll_up);
 void            gs_shell_overview_setup        (GsShellOverview        *shell_overview,
                                                  GsShell                *shell,
                                                 GsPluginLoader         *plugin_loader,
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 1745bbe..6746aa4 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -125,7 +125,7 @@ out:
  * gs_shell_updates_refresh:
  **/
 void
-gs_shell_updates_refresh (GsShellUpdates *shell_updates)
+gs_shell_updates_refresh (GsShellUpdates *shell_updates, gboolean scroll_up)
 {
        GsShellUpdatesPrivate *priv = shell_updates->priv;
         GtkWidget *widget;
@@ -137,6 +137,13 @@ gs_shell_updates_refresh (GsShellUpdates *shell_updates)
                 gtk_widget_show (widget);
         }
 
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "scrolledwindow_install"));
+        if (scroll_up) {
+                GtkAdjustment *adj;
+                adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (widget));
+                gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
+        }
+
        /* no need to refresh */
        if (priv->cache_valid) {
                 widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_updates"));
diff --git a/src/gs-shell-updates.h b/src/gs-shell-updates.h
index 1ad7c75..af6c975 100644
--- a/src/gs-shell-updates.h
+++ b/src/gs-shell-updates.h
@@ -54,7 +54,8 @@ GType          gs_shell_updates_get_type      (void);
 
 GsShellUpdates *gs_shell_updates_new           (void);
 void            gs_shell_updates_invalidate    (GsShellUpdates         *shell_updates);
-void            gs_shell_updates_refresh       (GsShellUpdates         *shell_updates);
+void            gs_shell_updates_refresh       (GsShellUpdates         *shell_updates,
+                                                 gboolean                scroll_up);
 void            gs_shell_updates_setup         (GsShellUpdates         *shell_updates,
                                                  GsShell                *shell,
                                                 GsPluginLoader         *plugin_loader,
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 12cebc1..a502fd3 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -72,7 +72,7 @@ gs_shell_activate (GsShell *shell)
 }
 
 static void
-gs_shell_change_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *category)
+gs_shell_change_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *category, gboolean scroll_up)
 {
        GsShellPrivate *priv = shell->priv;
         GtkWidget *widget;
@@ -119,10 +119,10 @@ gs_shell_change_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *
        priv->mode = mode;
        switch (mode) {
        case GS_SHELL_MODE_OVERVIEW:
-               gs_shell_overview_refresh (priv->shell_overview);
+               gs_shell_overview_refresh (priv->shell_overview, scroll_up);
                break;
        case GS_SHELL_MODE_INSTALLED:
-               gs_shell_installed_refresh (priv->shell_installed);
+               gs_shell_installed_refresh (priv->shell_installed, scroll_up);
                break;
        case GS_SHELL_MODE_SEARCH:
                widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "entry_search"));
@@ -130,7 +130,7 @@ gs_shell_change_mode (GsShell *shell, GsShellMode mode, GsApp *app, GsCategory *
                gs_shell_search_refresh (priv->shell_search, text);
                break;
        case GS_SHELL_MODE_UPDATES:
-               gs_shell_updates_refresh (priv->shell_updates);
+               gs_shell_updates_refresh (priv->shell_updates, scroll_up);
                break;
        case GS_SHELL_MODE_DETAILS:
                gs_shell_details_set_app (priv->shell_details, app);
@@ -154,7 +154,7 @@ gs_shell_overview_button_cb (GtkWidget *widget, GsShell *shell)
        GsShellMode mode;
        mode = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
                                                   "gnome-software::overview-mode"));
-       gs_shell_change_mode (shell, mode, NULL, NULL);
+       gs_shell_change_mode (shell, mode, NULL, NULL, TRUE);
 }
 
 static void
@@ -199,7 +199,7 @@ gs_shell_back_button_cb (GtkWidget *widget, GsShell *shell)
         entry = priv->back_entry_stack->data;
         priv->back_entry_stack = g_slist_remove (priv->back_entry_stack, entry);
 
-       gs_shell_change_mode (shell, entry->mode, entry->app, entry->category);
+       gs_shell_change_mode (shell, entry->mode, entry->app, entry->category, FALSE);
 
         free_back_entry (entry);
 }
@@ -211,8 +211,8 @@ initial_overview_load_done (GsShellOverview *shell_overview, gpointer data)
 
         g_signal_handlers_disconnect_by_func (shell_overview, initial_overview_load_done, data);
 
-       gs_shell_updates_refresh (shell->priv->shell_updates);
-       gs_shell_installed_refresh (shell->priv->shell_installed);
+       gs_shell_updates_refresh (shell->priv->shell_updates, TRUE);
+       gs_shell_installed_refresh (shell->priv->shell_installed, TRUE);
 }
 
 static void
@@ -228,7 +228,7 @@ gs_shell_search_activated_cb (GtkEntry *entry, GsShell *shell)
         if (gs_shell_get_mode (shell) == GS_SHELL_MODE_SEARCH) {
                 gs_shell_search_refresh (priv->shell_search, text);
         } else {
-                gs_shell_set_mode (shell, GS_SHELL_MODE_SEARCH);
+                gs_shell_change_mode (shell, GS_SHELL_MODE_SEARCH, NULL, NULL, TRUE);
         }
 }
 
@@ -339,7 +339,7 @@ text_changed_handler (GObject *entry, GParamSpec *pspec, GsShell *shell)
 
         text = gtk_entry_get_text (GTK_ENTRY (entry));
         if (text[0] == '\0')
-                gs_shell_set_mode (shell, GS_SHELL_MODE_OVERVIEW);
+                gs_shell_change_mode (shell, GS_SHELL_MODE_OVERVIEW, NULL, NULL, TRUE);
 }
 
 /**
@@ -439,7 +439,7 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
         /* load content */
         g_signal_connect (priv->shell_overview, "refreshed",
                           G_CALLBACK (initial_overview_load_done), shell);
-        gs_shell_set_mode (shell, GS_SHELL_MODE_OVERVIEW);
+        gs_shell_change_mode (shell, GS_SHELL_MODE_OVERVIEW, NULL, NULL, TRUE);
 
        return GTK_WINDOW (main_window);
 }
@@ -450,7 +450,7 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
 void
 gs_shell_set_mode (GsShell *shell, GsShellMode mode)
 {
-        gs_shell_change_mode (shell, mode, NULL, NULL);
+        gs_shell_change_mode (shell, mode, NULL, NULL, TRUE);
 }
 
 GsShellMode
@@ -465,14 +465,14 @@ void
 gs_shell_show_app (GsShell *shell, GsApp *app)
 {
         save_back_entry (shell);
-        gs_shell_change_mode (shell, GS_SHELL_MODE_DETAILS, app, NULL);
+        gs_shell_change_mode (shell, GS_SHELL_MODE_DETAILS, app, NULL, TRUE);
 }
 
 void
 gs_shell_show_category (GsShell *shell, GsCategory *category)
 {
         save_back_entry (shell);
-        gs_shell_change_mode (shell, GS_SHELL_MODE_CATEGORY, NULL, category);
+        gs_shell_change_mode (shell, GS_SHELL_MODE_CATEGORY, NULL, category, TRUE);
 }
 
 /**


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