[gnome-initial-setup/wip/pwithnall/misc-fixes: 29/70] language-chooser: make it more clear for the users
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/wip/pwithnall/misc-fixes: 29/70] language-chooser: make it more clear for the users
- Date: Fri, 11 Sep 2020 13:29:13 +0000 (UTC)
commit 52429d89b8a047792deb9b381033a8b26b822f10
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Feb 6 15:36:56 2017 -0200
language-chooser: make it more clear for the users
What this patch implements:
- vertically centralize the selected language to ensure
that the initially selected language is shown.
- show all languages by default because it is not clear that
the three-vertical-dots row means "show the other languages".
Instead of simply setting a field, go through the method that would
be used when clicking on the dots. This will make sure the internal
state stays consistent, including the visibility of the vertical
scrollbar.
- show the searchbar by default because all languages are shown
by default.
(Modified during the 3.36 rebase by Matthew Leeds to drop "<property
name="valign">fill</property>" on the box id "box" in
gis-language-page.ui. See upstream commit bdca72d6c)
(Rebase 3.38: This could potentially be dropped in future if we update
cc-language-chooser.c from gnome-control-center; it’s copy/paste code.)
https://phabricator.endlessm.com/T15310
https://phabricator.endlessm.com/T17323
.../pages/language/cc-language-chooser.c | 68 +++++++++++++++++++++-
.../pages/language/gis-language-page.ui | 1 -
.../pages/language/language-chooser.ui | 2 +-
3 files changed, 67 insertions(+), 4 deletions(-)
---
diff --git a/gnome-initial-setup/pages/language/cc-language-chooser.c
b/gnome-initial-setup/pages/language/cc-language-chooser.c
index fa8531cc..2e15331c 100644
--- a/gnome-initial-setup/pages/language/cc-language-chooser.c
+++ b/gnome-initial-setup/pages/language/cc-language-chooser.c
@@ -42,6 +42,9 @@ struct _CcLanguageChooserPrivate
GtkWidget *filter_entry;
GtkWidget *language_list;
+ GtkWidget *to_be_scrolled_row;
+ gboolean initial_scroll;
+
GtkWidget *scrolled_window;
GtkWidget *no_results;
GtkWidget *more_item;
@@ -188,10 +191,65 @@ language_widget_new (const char *locale_id,
return widget->box;
}
+static inline gint
+get_selected_language_row_y (GtkWidget *row)
+{
+ GtkAllocation alloc;
+
+ gtk_widget_get_allocation (row, &alloc);
+
+ return alloc.y + alloc.height / 2.0;
+}
+
+static void
+update_scroll_position (CcLanguageChooser *chooser)
+{
+ CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
+ GtkAdjustment *vadjustment;
+ GtkWidget *row;
+ gdouble page_increment;
+ gdouble real_value;
+
+ row = priv->to_be_scrolled_row;
+
+ vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scrolled_window));
+ page_increment = gtk_adjustment_get_page_increment (vadjustment);
+ real_value = get_selected_language_row_y (row) - page_increment / 2.0;
+
+ /*
+ * Since GtkScrolledWindow tries to follow the focused row of a listbox,
+ * make sure that the current row is focused.
+ */
+ gtk_widget_grab_focus (row);
+
+ gtk_adjustment_set_value (vadjustment, real_value);
+
+ priv->initial_scroll = TRUE;
+}
+
+static void
+schedule_scroll (CcLanguageChooser *chooser,
+ GtkWidget *row)
+{
+ CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
+ priv->to_be_scrolled_row = row;
+
+ if (gtk_widget_get_realized (priv->scrolled_window)) {
+ update_scroll_position (chooser);
+ return;
+ }
+
+ g_signal_connect_swapped (priv->scrolled_window,
+ "realize",
+ G_CALLBACK (update_scroll_position),
+ chooser);
+}
+
static void
sync_checkmark (GtkWidget *row,
gpointer user_data)
{
+ CcLanguageChooser *chooser;
GtkWidget *child;
LanguageWidget *widget;
gchar *locale_id;
@@ -203,9 +261,14 @@ sync_checkmark (GtkWidget *row,
if (widget == NULL)
return;
- locale_id = user_data;
+ chooser = user_data;
+ CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
+ locale_id = priv->language;
should_be_visible = g_str_equal (widget->locale_id, locale_id);
gtk_widget_set_opacity (widget->checkmark, should_be_visible ? 1.0 : 0.0);
+
+ if (should_be_visible && !priv->initial_scroll)
+ schedule_scroll (chooser, row);
}
static void
@@ -214,7 +277,7 @@ sync_all_checkmarks (CcLanguageChooser *chooser)
CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
gtk_container_foreach (GTK_CONTAINER (priv->language_list),
- sync_checkmark, priv->language);
+ sync_checkmark, chooser);
}
static GtkWidget *
@@ -504,6 +567,7 @@ cc_language_chooser_constructed (GObject *object)
priv->language = cc_common_language_get_current_language ();
sync_all_checkmarks (chooser);
+ show_more (chooser);
}
static void
diff --git a/gnome-initial-setup/pages/language/gis-language-page.ui
b/gnome-initial-setup/pages/language/gis-language-page.ui
index 8f2a08cf..1ebbf9b4 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.ui
+++ b/gnome-initial-setup/pages/language/gis-language-page.ui
@@ -37,7 +37,6 @@
<property name="margin_bottom">18</property>
<property name="width_request">400</property>
<property name="visible">True</property>
- <property name="valign">start</property>
</object>
</child>
</object>
diff --git a/gnome-initial-setup/pages/language/language-chooser.ui
b/gnome-initial-setup/pages/language/language-chooser.ui
index fc61d597..986dcfe2 100644
--- a/gnome-initial-setup/pages/language/language-chooser.ui
+++ b/gnome-initial-setup/pages/language/language-chooser.ui
@@ -24,7 +24,7 @@
</child>
<child>
<object class="GtkSearchEntry" id="filter_entry">
- <property name="visible">False</property>
+ <property name="visible">True</property>
<property name="hexpand">True</property>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]