[gnome-music] searchbar: Set error style when no match is found
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music] searchbar: Set error style when no match is found
- Date: Tue, 6 Nov 2018 21:10:01 +0000 (UTC)
commit 920878a97b105c5d1f8f125910f69dbb414fd939
Author: ymdatta <ymdatta protonmail com>
Date: Tue Nov 6 12:31:01 2018 +0530
searchbar: Set error style when no match is found
When there are no search results, set the error style on the Gtk.Entry.
Closes: #228
gnomemusic/views/searchview.py | 13 +++++--------
gnomemusic/widgets/searchbar.py | 20 +++++++++++++++++++-
2 files changed, 24 insertions(+), 9 deletions(-)
---
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index f2e72e89..8c275ecc 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -264,20 +264,17 @@ class SearchView(BaseView):
+ self.model.iter_n_children(self._head_iters[3])
)
- if (category == 'song'):
- if remaining != 0:
- self.props.search_state = Search.State.RESULT
- else:
- if self._items_found == 0:
- if grilo.search_source:
- self.props.search_state = Search.State.NO_RESULT
-
# We need to remember the view before the search view
emptysearchview = self._window.views[View.EMPTY]
if (self._window.curr_view != emptysearchview
and self._window.prev_view != emptysearchview):
self.previous_view = self._window.prev_view
+ if self._items_found == 0:
+ self.props.search_state = Search.State.NO_RESULT
+ else:
+ self.props.search_state = Search.State.RESULT
+
if remaining == 0:
self._window.notifications_popup.pop_loading()
self._view.show()
diff --git a/gnomemusic/widgets/searchbar.py b/gnomemusic/widgets/searchbar.py
index b8313e7e..c106fde9 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -373,6 +373,8 @@ class Searchbar(Gtk.SearchBar):
self.props.stack.set_visible_child_name('search')
view = self.props.stack.get_visible_child()
view.set_search_text(search_term, fields_filter)
+ else:
+ self._set_error_style(False)
self._drop_down_button.set_active(False)
self._dropdown.set_reveal_child(False)
@@ -403,7 +405,23 @@ class Searchbar(Gtk.SearchBar):
if search_state == Search.State.NONE:
self.reveal(False)
elif search_state == Search.State.NO_RESULT:
- self.props.stack.set_visible_child_name('emptyview')
+ self._set_error_style(True)
+ self.props.stack.props.visible_child_name = 'emptyview'
+ else:
+ self._set_error_style(False)
+ self.props.stack.props.visible_child_name = 'search'
+
+ @log
+ def _set_error_style(self, error):
+ """Adds error state to searchbar.
+
+ :param bool error: Whether to add error state
+ """
+ style_context = self._search_entry.get_style_context()
+ if error:
+ style_context.add_class('error')
+ else:
+ style_context.remove_class('error')
@log
def toggle(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]