[gnome-music/wip/jfelder/search-selection-reset: 19/24] window: Do not expose headerbar's search button



commit 688ba27261663701581917ea508ee4eb01a13d6f
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Feb 27 08:59:40 2019 +0100

    window: Do not expose headerbar's search button
    
    With the introduction of search-mode-enabled and state properties from
    the previous commits, it is now possible to directly listen to
    search-mode-enabled changes.

 gnomemusic/window.py | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 79dbf70a..b06410db 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -184,10 +184,10 @@ class Window(Gtk.ApplicationWindow):
         self._box.pack_start(selection_toolbar, False, False, 0)
         self.add(self._box)
 
-        self._headerbar._search_button.connect(
-            'toggled', self._on_search_toggled)
         selection_toolbar.connect(
             'add-to-playlist', self._on_add_to_playlist)
+        self._search.connect(
+            "notify::search-mode-enabled", self._on_search_mode_changed)
 
         self._headerbar.props.state = HeaderBar.State.MAIN
         self._headerbar.show()
@@ -456,24 +456,18 @@ class Window(Gtk.ApplicationWindow):
             self._stack.set_visible_child(self.views[view_enum])
 
     @log
-    def _on_search_toggled(self, button, data=None):
-        if (not button.get_active()
-                and (self.curr_view == self.views[View.SEARCH]
-                    or self.curr_view == self.views[View.EMPTY])):
-            child = self.curr_view.get_visible_child()
-            if self._headerbar.props.state == HeaderBar.State.MAIN:
-                # We should get back to the view before the search
-                self._stack.set_visible_child(
-                    self.views[View.SEARCH].previous_view)
-                self._searchbar.clear()
-            elif (self.views[View.SEARCH].previous_view == self.views[View.ALBUM]
-                    and child != self.curr_view._album_widget
-                    and child != self.curr_view._artist_albums_widget):
-                self._stack.set_visible_child(self.views[View.ALBUM])
-                self._searchbar.clear()
-
-            if self.props.selection_mode:
-                self.props.selection_mode = False
+    def _on_search_mode_changed(self, klass, param):
+        if (self._search.props.search_mode_enabled
+                or self._search.props.state == Search.State.NONE):
+            return
+
+        # Get back to the view before the search
+        search_views = [self.views[View.EMPTY], self.views[View.SEARCH]]
+        if self.curr_view in search_views:
+            self._stack.set_visible_child(
+                self.views[View.SEARCH].previous_view)
+
+        self._searchbar.clear()
 
     @log
     def _switch_back_from_childview(self, klass=None):


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