[gnome-software: 3/29] src: Remove scroll_up argument from gs_page_switch_to()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 3/29] src: Remove scroll_up argument from gs_page_switch_to()
- Date: Wed, 31 Mar 2021 16:03:45 +0000 (UTC)
commit 81f69246492b163bf0f367e3cdd5f68c70536bb3
Author: Philip Withnall <pwithnall endlessos org>
Date: Wed Jan 20 22:48:54 2021 +0000
src: Remove scroll_up argument from gs_page_switch_to()
This moves the code a step closer to being property-based, as now
changing modes doesn’t necessarily involve context-dependent choice of
whether to scroll up in the new page.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
src/gs-category-page.c | 2 +-
src/gs-details-page.c | 11 +++++++----
src/gs-extras-page.c | 9 +--------
src/gs-installed-page.c | 7 +------
src/gs-loading-page.c | 2 +-
src/gs-moderate-page.c | 2 +-
src/gs-overview-page.c | 8 +-------
src/gs-page.c | 27 ++++++++++++++++++++++++---
src/gs-page.h | 7 +++----
src/gs-search-page.c | 8 +-------
src/gs-shell.c | 7 +++++--
src/gs-updates-page.c | 12 +++---------
12 files changed, 49 insertions(+), 53 deletions(-)
---
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 77b0c3ab0..e57aab1f6 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -58,7 +58,7 @@ struct _GsCategoryPage
G_DEFINE_TYPE (GsCategoryPage, gs_category_page, GS_TYPE_PAGE)
static void
-gs_category_page_switch_to (GsPage *page, gboolean scroll_up)
+gs_category_page_switch_to (GsPage *page)
{
GsCategoryPage *self = GS_CATEGORY_PAGE (page);
GtkWidget *widget;
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 8f72f2304..8355930e4 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -279,7 +279,7 @@ gs_details_page_set_header_label (GsDetailsPage *self,
}
static void
-gs_details_page_switch_to (GsPage *page, gboolean scroll_up)
+gs_details_page_switch_to (GsPage *page)
{
GsDetailsPage *self = GS_DETAILS_PAGE (page);
GtkAdjustment *adj;
@@ -500,8 +500,10 @@ gs_details_page_switch_to_idle (gpointer user_data)
{
GsDetailsPage *self = GS_DETAILS_PAGE (user_data);
- if (gs_shell_get_mode (self->shell) == GS_SHELL_MODE_DETAILS)
- gs_page_switch_to (GS_PAGE (self), TRUE);
+ if (gs_shell_get_mode (self->shell) == GS_SHELL_MODE_DETAILS) {
+ gs_page_switch_to (GS_PAGE (self));
+ gs_page_scroll_up (GS_PAGE (self));
+ }
/* update widgets */
gs_details_page_refresh_all (self);
@@ -2158,7 +2160,8 @@ gs_details_page_load_stage1 (GsDetailsPage *self)
g_autoptr(GsPluginJob) plugin_job = NULL;
/* update UI */
- gs_page_switch_to (GS_PAGE (self), TRUE);
+ gs_page_switch_to (GS_PAGE (self));
+ gs_page_scroll_up (GS_PAGE (self));
gs_details_page_set_state (self, GS_DETAILS_PAGE_STATE_LOADING);
/* get extra details about the app */
diff --git a/src/gs-extras-page.c b/src/gs-extras-page.c
index e0b1d827c..c78a89491 100644
--- a/src/gs-extras-page.c
+++ b/src/gs-extras-page.c
@@ -1086,8 +1086,7 @@ gs_extras_page_search (GsExtrasPage *self,
}
static void
-gs_extras_page_switch_to (GsPage *page,
- gboolean scroll_up)
+gs_extras_page_switch_to (GsPage *page)
{
GsExtrasPage *self = GS_EXTRAS_PAGE (page);
GtkWidget *widget;
@@ -1101,12 +1100,6 @@ gs_extras_page_switch_to (GsPage *page,
widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "application_details_header"));
gtk_widget_show (widget);
- if (scroll_up) {
- GtkAdjustment *adj;
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolledwindow));
- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
- }
-
gs_extras_page_update_ui_state (self);
}
diff --git a/src/gs-installed-page.c b/src/gs-installed-page.c
index 103da87a4..5ff4fc8d4 100644
--- a/src/gs-installed-page.c
+++ b/src/gs-installed-page.c
@@ -277,7 +277,7 @@ gs_installed_page_reload (GsPage *page)
}
static void
-gs_installed_page_switch_to (GsPage *page, gboolean scroll_up)
+gs_installed_page_switch_to (GsPage *page)
{
GsInstalledPage *self = GS_INSTALLED_PAGE (page);
GtkWidget *widget;
@@ -293,11 +293,6 @@ gs_installed_page_switch_to (GsPage *page, gboolean scroll_up)
widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "menu_button"));
gtk_widget_show (widget);
- if (scroll_up) {
- GtkAdjustment *adj;
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
(self->scrolledwindow_install));
- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
- }
if (gs_shell_get_mode (self->shell) == GS_SHELL_MODE_INSTALLED) {
gs_grab_focus_when_mapped (self->scrolledwindow_install);
}
diff --git a/src/gs-loading-page.c b/src/gs-loading-page.c
index 67a20fb5a..a31d77344 100644
--- a/src/gs-loading-page.c
+++ b/src/gs-loading-page.c
@@ -146,7 +146,7 @@ gs_loading_page_load (GsLoadingPage *self)
}
static void
-gs_loading_page_switch_to (GsPage *page, gboolean scroll_up)
+gs_loading_page_switch_to (GsPage *page)
{
GsLoadingPage *self = GS_LOADING_PAGE (page);
GsLoadingPagePrivate *priv = gs_loading_page_get_instance_private (self);
diff --git a/src/gs-moderate-page.c b/src/gs-moderate-page.c
index edd77aad6..a63ebaa93 100644
--- a/src/gs-moderate-page.c
+++ b/src/gs-moderate-page.c
@@ -231,7 +231,7 @@ gs_moderate_page_reload (GsPage *page)
}
static void
-gs_moderate_page_switch_to (GsPage *page, gboolean scroll_up)
+gs_moderate_page_switch_to (GsPage *page)
{
GsModeratePage *self = GS_MODERATE_PAGE (page);
diff --git a/src/gs-overview-page.c b/src/gs-overview-page.c
index 64d11ad42..d1ddc71b9 100644
--- a/src/gs-overview-page.c
+++ b/src/gs-overview-page.c
@@ -753,11 +753,10 @@ gs_overview_page_reload (GsPage *page)
}
static void
-gs_overview_page_switch_to (GsPage *page, gboolean scroll_up)
+gs_overview_page_switch_to (GsPage *page)
{
GsOverviewPage *self = GS_OVERVIEW_PAGE (page);
GtkWidget *widget;
- GtkAdjustment *adj;
if (gs_shell_get_mode (self->shell) != GS_SHELL_MODE_OVERVIEW) {
g_warning ("Called switch_to(overview) when in mode %s",
@@ -774,11 +773,6 @@ gs_overview_page_switch_to (GsPage *page, gboolean scroll_up)
widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "menu_button"));
gtk_widget_show (widget);
- if (scroll_up) {
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
(self->scrolledwindow_overview));
- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
- }
-
gs_grab_focus_when_mapped (self->scrolledwindow_overview);
if (self->cache_valid || self->action_cnt > 0)
diff --git a/src/gs-page.c b/src/gs-page.c
index 87effb97f..f1647f098 100644
--- a/src/gs-page.c
+++ b/src/gs-page.c
@@ -602,14 +602,13 @@ gs_page_is_active (GsPage *page)
* widgets.
*/
void
-gs_page_switch_to (GsPage *page,
- gboolean scroll_up)
+gs_page_switch_to (GsPage *page)
{
GsPageClass *klass = GS_PAGE_GET_CLASS (page);
GsPagePrivate *priv = gs_page_get_instance_private (page);
priv->is_active = TRUE;
if (klass->switch_to != NULL)
- klass->switch_to (page, scroll_up);
+ klass->switch_to (page);
}
/**
@@ -628,6 +627,28 @@ gs_page_switch_from (GsPage *page)
klass->switch_from (page);
}
+/**
+ * gs_page_scroll_up:
+ * @page: a #GsPage
+ *
+ * Scroll the page to the top of its content, if it supports scrolling.
+ *
+ * If it doesn’t support scrolling, this is a no-op.
+ *
+ * Since: 40
+ */
+void
+gs_page_scroll_up (GsPage *page)
+{
+ g_return_if_fail (GS_IS_PAGE (page));
+
+ if (GTK_IS_SCROLLABLE (page)) {
+ GtkAdjustment *adj;
+ adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (page));
+ gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
+ }
+}
+
void
gs_page_reload (GsPage *page)
{
diff --git a/src/gs-page.h b/src/gs-page.h
index 9fc5ad8de..6594e3aae 100644
--- a/src/gs-page.h
+++ b/src/gs-page.h
@@ -25,8 +25,7 @@ struct _GsPageClass
GsApp *app);
void (*app_removed) (GsPage *page,
GsApp *app);
- void (*switch_to) (GsPage *page,
- gboolean scroll_up);
+ void (*switch_to) (GsPage *page);
void (*switch_from) (GsPage *page);
void (*reload) (GsPage *page);
gboolean (*setup) (GsPage *page,
@@ -64,9 +63,9 @@ void gs_page_shortcut_add (GsPage *page,
void gs_page_shortcut_remove (GsPage *page,
GsApp *app,
GCancellable *cancellable);
-void gs_page_switch_to (GsPage *page,
- gboolean scroll_up);
+void gs_page_switch_to (GsPage *page);
void gs_page_switch_from (GsPage *page);
+void gs_page_scroll_up (GsPage *page);
void gs_page_reload (GsPage *page);
gboolean gs_page_setup (GsPage *page,
GsShell *shell,
diff --git a/src/gs-search-page.c b/src/gs-search-page.c
index c60f3121e..ae0130c19 100644
--- a/src/gs-search-page.c
+++ b/src/gs-search-page.c
@@ -347,7 +347,7 @@ gs_search_page_set_text (GsSearchPage *self, const gchar *value)
}
static void
-gs_search_page_switch_to (GsPage *page, gboolean scroll_up)
+gs_search_page_switch_to (GsPage *page)
{
GsSearchPage *self = GS_SEARCH_PAGE (page);
GtkWidget *widget;
@@ -370,12 +370,6 @@ gs_search_page_switch_to (GsPage *page, gboolean scroll_up)
widget = GTK_WIDGET (gtk_builder_get_object (self->builder, "search_button"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
- if (scroll_up) {
- GtkAdjustment *adj;
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolledwindow_search));
- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
- }
-
if (self->value && self->changed)
gs_search_page_load (self);
}
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 4a4e0a2da..083630b18 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -543,7 +543,9 @@ gs_shell_change_mode (GsShell *shell,
if (priv->page != NULL)
gs_page_switch_from (priv->page);
g_set_object (&priv->page, page);
- gs_page_switch_to (page, scroll_up);
+ gs_page_switch_to (page);
+ if (scroll_up)
+ gs_page_scroll_up (page);
priv->in_mode_change = FALSE;
/* update header bar widgets */
@@ -871,7 +873,8 @@ search_changed_handler (GObject *entry, GsShell *shell)
} else {
GsPage *page = GS_PAGE (g_hash_table_lookup (priv->pages, "search"));
gs_search_page_set_text (GS_SEARCH_PAGE (page), text);
- gs_page_switch_to (page, TRUE);
+ gs_page_switch_to (page);
+ gs_page_scroll_up (page);
}
}
}
diff --git a/src/gs-updates-page.c b/src/gs-updates-page.c
index 6a16852c2..89992d498 100644
--- a/src/gs-updates-page.c
+++ b/src/gs-updates-page.c
@@ -638,8 +638,7 @@ gs_updates_page_reload (GsPage *page)
}
static void
-gs_updates_page_switch_to (GsPage *page,
- gboolean scroll_up)
+gs_updates_page_switch_to (GsPage *page)
{
GsUpdatesPage *self = GS_UPDATES_PAGE (page);
GtkWidget *widget;
@@ -657,12 +656,6 @@ gs_updates_page_switch_to (GsPage *page,
gtk_widget_set_visible (self->button_refresh, TRUE);
- if (scroll_up) {
- GtkAdjustment *adj;
- adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
(self->scrolledwindow_updates));
- gtk_adjustment_set_value (adj, gtk_adjustment_get_lower (adj));
- }
-
/* no need to refresh */
if (self->cache_valid) {
gs_updates_page_update_ui_state (self);
@@ -709,7 +702,8 @@ gs_updates_page_refresh_cb (GsPluginLoader *plugin_loader,
/* get the new list */
gs_updates_page_invalidate (self);
- gs_page_switch_to (GS_PAGE (self), TRUE);
+ gs_page_switch_to (GS_PAGE (self));
+ gs_page_scroll_up (GS_PAGE (self));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]