[gnome-software: 1/6] shell: Centralize mode retrieval in gs_shell_get_mode()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/6] shell: Centralize mode retrieval in gs_shell_get_mode()
- Date: Fri, 11 Jun 2021 14:44:56 +0000 (UTC)
commit f9d122aa7492500d003d2f9e4a28c308a5d914d0
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Apr 23 07:36:57 2021 +0200
shell: Centralize mode retrieval in gs_shell_get_mode()
This will help untangling the mode and the stack and give us more
freedom on how to implement the UI.
src/gs-shell.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 64bc01161..74a01303b 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -458,14 +458,7 @@ stack_notify_visible_child_cb (GObject *object,
GsShellMode mode;
gsize i;
- /* Work out the mode for this child. */
- for (i = 0; i < G_N_ELEMENTS (page_name); i++) {
- if (g_strcmp0 (page_name[i], gtk_stack_get_visible_child_name (shell->stack_main)) == 0) {
- mode = i;
- break;
- }
- }
- g_assert (i < G_N_ELEMENTS (page_name));
+ mode = gs_shell_get_mode (shell);
update_header_widgets (shell);
@@ -2158,10 +2151,13 @@ gs_shell_set_mode (GsShell *shell, GsShellMode mode)
GsShellMode
gs_shell_get_mode (GsShell *shell)
{
- for (gsize i = 0; i < G_N_ELEMENTS (page_name); i++) {
- if (g_strcmp0 (gtk_stack_get_visible_child_name (shell->stack_main), page_name[i]) == 0)
- return (GsShellMode) i;
- }
+ const gchar *name;
+
+ name = gtk_stack_get_visible_child_name (shell->stack_main);
+
+ for (gsize i = 0; i < G_N_ELEMENTS (page_name); i++)
+ if (g_strcmp0 (page_name[i], name) == 0)
+ return i;
g_assert_not_reached ();
}
@@ -2169,7 +2165,8 @@ gs_shell_get_mode (GsShell *shell)
const gchar *
gs_shell_get_mode_string (GsShell *shell)
{
- return gtk_stack_get_visible_child_name (shell->stack_main);
+ GsShellMode mode = gs_shell_get_mode (shell);
+ return page_name[mode];
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]