[gnome-software: 11/14] gs-details-page: Highlight the first visible button in the header
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 11/14] gs-details-page: Highlight the first visible button in the header
- Date: Fri, 13 Aug 2021 13:03:33 +0000 (UTC)
commit 5b6970ce450e7e87879e66fda0fb964e35d53d92
Author: Philip Withnall <pwithnall endlessos org>
Date: Fri Aug 13 10:10:25 2021 +0100
gs-details-page: Highlight the first visible button in the header
The code previously attempted to do this, but by hard-coding the checks.
It’s simpler to check each button automatically, and more robust against
unusual sets of buttons being visible for odd app states.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #1351
src/gs-details-page.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index 6ac427c84..e0b9a3ca5 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -794,6 +794,13 @@ static void
gs_details_page_refresh_buttons (GsDetailsPage *self)
{
GsAppState state;
+ GtkWidget *buttons_in_order[] = {
+ self->button_details_launch,
+ self->button_install,
+ self->button_update,
+ self->button_remove,
+ };
+ GtkWidget *highlighted_button = NULL;
state = gs_app_get_state (self->app);
@@ -881,11 +888,6 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
case GS_APP_STATE_UPDATABLE_LIVE:
gtk_widget_set_visible (self->button_remove, TRUE);
gtk_widget_set_sensitive (self->button_remove, TRUE);
- /* Mark the button as destructive only if Launch is not visible */
- if (gtk_widget_get_visible (self->button_details_launch))
- gtk_style_context_remove_class (gtk_widget_get_style_context
(self->button_remove), "destructive-action");
- else
- gtk_style_context_add_class (gtk_widget_get_style_context
(self->button_remove), "destructive-action");
break;
case GS_APP_STATE_AVAILABLE_LOCAL:
case GS_APP_STATE_AVAILABLE:
@@ -911,6 +913,24 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
gtk_widget_set_visible (self->button_details_launch, FALSE);
gtk_widget_set_visible (self->button_remove, FALSE);
}
+
+ /* Update the styles so that the first visible button gets
+ * `suggested-action` or `destructive-action` and the rest are
+ * unstyled. This draws the user’s attention to the most likely
+ * action to perform. */
+ for (gsize i = 0; i < G_N_ELEMENTS (buttons_in_order); i++) {
+ if (highlighted_button != NULL) {
+ gtk_style_context_remove_class (gtk_widget_get_style_context (buttons_in_order[i]),
"suggested-action");
+ gtk_style_context_remove_class (gtk_widget_get_style_context (buttons_in_order[i]),
"destructive-action");
+ } else if (gtk_widget_get_visible (buttons_in_order[i])) {
+ highlighted_button = buttons_in_order[i];
+
+ if (buttons_in_order[i] == self->button_remove)
+ gtk_style_context_add_class (gtk_widget_get_style_context
(buttons_in_order[i]), "destructive-action");
+ else
+ gtk_style_context_add_class (gtk_widget_get_style_context
(buttons_in_order[i]), "suggested-action");
+ }
+ }
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]