[gnome-music/wip/jfelder/gtk-stack-switcher-selection-fix] window: Fix album view selection by the stack switcher on launch




commit 0e4cd4e599cf1fc9d453f3b4f5dc0aa80ff8f57a
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Mar 24 13:18:33 2021 +0100

    window: Fix album view selection by the stack switcher on launch
    
    The first view added to the stack is the EmptyView which is not
    visible on launch. Then, AlbumsView is added and becomes the
    visible_child by default because it is visible. However, it is not
    selected by the the stack switcher because the
    "notify::visible-changed" signal is received before the child is added
    to the stack switcher.
    
    This issue is fixed by adding a "visible-child" notification. This
    way, the stack switcher selected the AlbumView on launch.

 gnomemusic/window.py | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 3b5d13998..b2e637564 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -262,7 +262,16 @@ class Window(Gtk.ApplicationWindow):
             else:
                 self._stack.add_named(i, i.props.name)
 
+        # The first view added to the stack is the EmptyView which is
+        # not visible on launch. Then, AlbumsView is added and becomes
+        # the visible_child by default because it is visible. However,
+        # it is not selected by the the stack switcher because the
+        # "notify::visible-changed" signal is received before the child
+        # is added to the stack switcher.
+        # The "visible-child" notification ensures that the AlbumView
+        # appears as selected by the stack switcher on launch.
         self._stack.props.visible_child = self.views[View.ALBUM]
+        self._stack.notify("visible-child")
 
         self.views[View.SEARCH].bind_property(
             "search-state", self._search, "state",


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