[gnome-music] window: Track current and previous views



commit 79612986e4a2c52351bd19d801707ca942c6eb1c
Author: Arnel Borja <arnelborja src gnome org>
Date:   Mon May 5 00:14:44 2014 +0800

    window: Track current and previous views
    
    This will allow us to go back to the other views after closing the
    search view. Connect to the notify signal before creating the views to
    properly get the current view on startup.

 gnomemusic/window.py |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index f22e0fa..dc23e87 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -73,6 +73,9 @@ class Window(Gtk.ApplicationWindow):
         self.set_size_request(200, 100)
         self.set_icon_name('gnome-music')
 
+        self.prev_view = None
+        self.curr_view = None
+
         size_setting = self.settings.get_value('window-size')
         if isinstance(size_setting[0], int) and isinstance(size_setting[1], int):
             self.resize(size_setting[0], size_setting[1])
@@ -225,6 +228,10 @@ class Window(Gtk.ApplicationWindow):
 
     @log
     def _switch_to_player_view(self):
+        self._on_notify_model_id = self._stack.connect('notify::visible-child', self._on_notify_mode)
+        self.connect('destroy', self._notify_mode_disconnect)
+        self._key_press_event_id = self.connect('key_press_event', self._on_key_press)
+
         self.views.append(Views.Albums(self, self.player))
         self.views.append(Views.Artists(self, self.player))
         self.views.append(Views.Songs(self, self.player))
@@ -241,10 +248,6 @@ class Window(Gtk.ApplicationWindow):
         self.toolbar.searchbar.show()
         self.toolbar.dropdown.show()
 
-        self._on_notify_model_id = self._stack.connect('notify::visible-child', self._on_notify_mode)
-        self.connect('destroy', self._notify_mode_disconnect)
-        self._key_press_event_id = self.connect('key_press_event', self._on_key_press)
-
         self.views[0].populate()
 
     @log
@@ -322,12 +325,15 @@ class Window(Gtk.ApplicationWindow):
 
     @log
     def _on_notify_mode(self, stack, param):
-        # Slide out artist list on switching to artists view
-        if stack.get_visible_child() == self.views[1] or \
-           stack.get_visible_child() == self.views[3]:
-            stack.get_visible_child().stack.set_visible_child_name('dummy')
-            stack.get_visible_child().stack.set_visible_child_name('sidebar')
-        if stack.get_visible_child() != self.views[4]:
+        self.prev_view = self.curr_view
+        self.curr_view = stack.get_visible_child()
+
+        # Slide out sidebar on switching to Artists or Playlists view
+        if self.curr_view == self.views[1] or \
+           self.curr_view == self.views[3]:
+            self.curr_view.stack.set_visible_child_name('dummy')
+            self.curr_view.stack.set_visible_child_name('sidebar')
+        if self.curr_view != self.views[4]:
             self.toolbar.searchbar.show_bar(False)
 
     @log


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