@@ -8,12 +8,13 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
88 private const string ACTION_OPEN = " action-open" ;
99
1010 private Granite . Placeholder queue_placeholder;
11+ private Granite . Placeholder search_placeholder;
1112 private Gtk . Button repeat_button;
1213 private Gtk . Button shuffle_button;
14+ private SearchBar search_bar;
1315 private Gtk . ListView queue_listview;
1416 private Gtk . Revealer search_revealer;
1517 private Gtk . ScrolledWindow scrolled;
16- private Gtk . SearchEntry search_entry;
1718 private Gtk . SingleSelection selection_model;
1819 private Gtk . Stack queue_stack;
1920 private Settings settings;
@@ -30,12 +31,10 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
3031
3132 repeat_button = new Gtk .Button ();
3233
33- search_entry = new Gtk .SearchEntry () {
34- placeholder_text = _ ("Search titles in playlist ")
35- };
34+ search_bar = new SearchBar (playback_manager. queue_liststore);
3635
3736 search_revealer = new Gtk .Revealer () {
38- child = search_entry
37+ child = search_bar
3938 };
4039
4140 playback_manager.bind_property (
@@ -55,7 +54,12 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
5554 icon = new ThemedIcon ("playlist -queue ")
5655 };
5756
58- selection_model = new Gtk .SingleSelection (playback_manager. queue_liststore);
57+ search_placeholder = new Granite .Placeholder (" " ) {
58+ description = _ ("Try changing search terms "),
59+ icon = new ThemedIcon ("edit -find -symbolic ")
60+ };
61+
62+ selection_model = new Gtk .SingleSelection (search_bar. filter_model);
5963
6064 var factory = new Gtk .SignalListItemFactory ();
6165
@@ -71,6 +75,7 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
7175
7276 queue_stack = new Gtk .Stack ();
7377 queue_stack.add_child (queue_placeholder );
78+ queue_stack.add_child (search_placeholder );
7479 queue_stack.add_child (scrolled );
7580
7681 var drop_target = new Gtk .DropTarget (typeof (Gdk . FileList ), Gdk . DragAction . COPY );
@@ -201,6 +206,13 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
201206 return false ;
202207 });
203208
209+ playback_manager.queue_liststore.items_changed.connect (() => {
210+ if (playback_manager. n_items == 0 ) {
211+ queue_stack. visible_child = queue_placeholder;
212+ search_bar. search_entry. text = " " ;
213+ }
214+ });
215+
204216 playback_manager.invalids_found.connect ((count ) => {
205217 error_toast. title = ngettext (
206218 " %d invalid file was not added to the queue" ,
@@ -234,25 +246,24 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
234246
235247 selection_model.items_changed.connect (on_items_changed );
236248
237- search_entry.search_changed.connect (() => {
238- int pos = playback_manager. find_title (search_entry. text);
239- if (pos >= 0 ) {
240- queue_listview. scroll_to (pos, SELECT , null );
241- }
242- });
243-
244- search_entry.activate.connect (() => {
249+ search_bar.activated.connect (() => {
245250 var selected = selection_model. get_selected ();
246251 if (selected != - 1 ) {
247252 var selected_audio = (AudioObject ) selection_model. get_item (selected);
248253 playback_manager. current_audio = selected_audio;
249254 }
250255 });
256+
257+ search_bar.search_entry.search_changed.connect (() => {
258+ if (selection_model. n_items <= 0 && search_bar. search_entry. text != " " ) {
259+ search_placeholder. title = _(" No Results for “%s ”" ). printf (search_bar. search_entry. text);
260+ }
261+ });
251262 }
252263
253264 public void start_search () {
254265 if (search_revealer. child_revealed) {
255- search_entry . grab_focus ();
266+ search_bar . start_search ();
256267 }
257268 }
258269
@@ -330,6 +341,11 @@ public class Music.MainWindow : Gtk.ApplicationWindow {
330341 private void on_items_changed () {
331342 if (selection_model. n_items > 0 ) {
332343 queue_stack. visible_child = scrolled;
344+ return ;
345+ }
346+
347+ if (search_bar. search_entry. text != " " ) {
348+ queue_stack. visible_child = search_placeholder;
333349 } else {
334350 queue_stack. visible_child = queue_placeholder;
335351 }
0 commit comments