From db99267c14964b2d32a34b7e7978dbad8f449832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 14 Jul 2025 12:38:05 -0700 Subject: [PATCH 1/3] =?UTF-8?q?MainWindow:=20ListBox=20=E2=86=92=20ListVie?= =?UTF-8?q?w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MainWindow.vala | 65 +++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 75207e4..09c996a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -36,7 +36,6 @@ public class Maps.MainWindow : Adw.ApplicationWindow { private Gtk.Button current_location; private Gtk.Spinner spinner; private Gtk.SearchEntry search_entry; - private Gtk.ListBox search_res_list; private Gtk.Popover search_res_popover; private MapWidget map_widget; @@ -73,25 +72,34 @@ public class Maps.MainWindow : Adw.ApplicationWindow { margin_end = 12 }; - search_res_list = new Gtk.ListBox () { - selection_mode = Gtk.SelectionMode.BROWSE + var list_factory = new Gtk.SignalListItemFactory (); + list_factory.setup.connect (setup_factory); + list_factory.bind.connect (bind_factory); + + var selection_model = new Gtk.NoSelection (location_store); + + var search_listview = new Gtk.ListView (selection_model, list_factory) { + single_click_activate = true }; - search_res_list.add_css_class (Granite.STYLE_CLASS_RICH_LIST); - search_res_list.bind_model (location_store, construct_search_res); - search_res_list.set_placeholder (search_placeholder); + search_listview.add_css_class (Granite.STYLE_CLASS_RICH_LIST); var search_res_list_scrolled = new Gtk.ScrolledWindow () { - child = search_res_list, + child = search_listview, hscrollbar_policy = Gtk.PolicyType.NEVER, max_content_height = 500, propagate_natural_height = true }; + var search_stack = new Gtk.Stack () { + vhomogeneous = false + }; + search_stack.add_child (search_res_list_scrolled); + search_stack.add_child (search_placeholder); + search_res_popover = new Gtk.Popover () { width_request = 400, has_arrow = false, - child = search_res_list_scrolled, - default_widget = search_res_list + child = search_stack }; search_res_popover.set_parent (search_entry); @@ -156,6 +164,14 @@ public class Maps.MainWindow : Adw.ApplicationWindow { map_widget.go_to_current (); }); + selection_model.items_changed.connect (() => { + if (selection_model.get_n_items () == 0) { + search_stack.visible_child = search_placeholder; + } else { + search_stack.visible_child = search_res_list_scrolled; + } + }); + search_entry.search_changed.connect (() => { if (search_entry.text == "") { return; @@ -172,13 +188,9 @@ public class Maps.MainWindow : Adw.ApplicationWindow { }); }); - search_res_list.row_activated.connect ((row) => { - unowned var place_row = row as PlaceListBoxRow; - if (place_row == null) { - return; - } - - map_widget.go_to_place (place_row.place); + search_listview.activate.connect ((pos) => { + var place = (Geocode.Place) selection_model.get_item (pos); + map_widget.go_to_place (place); }); var search_entry_gesture = new Gtk.EventControllerKey (); @@ -271,6 +283,8 @@ public class Maps.MainWindow : Adw.ApplicationWindow { answer_count = 10 }; + loc_store.remove_all (); + var places = new List (); try { places = yield forward.search_async (search_cancellable); @@ -279,23 +293,22 @@ public class Maps.MainWindow : Adw.ApplicationWindow { return; } - loc_store.remove_all (); foreach (unowned var place in places) { loc_store.append (place); } } - private Gtk.Widget construct_search_res (Object item) { - unowned var place = item as Geocode.Place; + private void setup_factory (Object object) { + var search_result_item = new SearchResultItem (); - var result_item = new Maps.SearchResultItem () { - place = place - }; + var list_item = (Gtk.ListItem) object; + list_item.child = search_result_item; + } - var row = new PlaceListBoxRow (place) { - child = result_item - }; + private void bind_factory (Object object) { + var list_item = (Gtk.ListItem) object; - return row; + var search_result_item = (SearchResultItem) list_item.child; + search_result_item.place = (Geocode.Place) list_item.get_item (); } } From b0eb400998cb1ba3940ff250097a4761a3861e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 15 Jul 2025 10:56:08 -0700 Subject: [PATCH 2/3] Remove unused PlacesListBoxRow --- src/MainWindow.vala | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ccf3f19..df45403 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -5,14 +5,6 @@ */ public class Maps.MainWindow : Adw.ApplicationWindow { - private class PlaceListBoxRow : Gtk.ListBoxRow { - public Geocode.Place place { get; construct; } - - public PlaceListBoxRow (Geocode.Place place) { - Object (place: place); - } - } - [Flags] private enum BusyReason { /** Busy with locating */ From 45b433f55c0cc0413a213ced203434acd2772fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 15 Jul 2025 10:59:03 -0700 Subject: [PATCH 3/3] =?UTF-8?q?get=5Fitem=20()=20=E2=86=92=20item?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index df45403..de9b268 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -283,6 +283,6 @@ public class Maps.MainWindow : Adw.ApplicationWindow { var list_item = (Gtk.ListItem) object; var search_result_item = (SearchResultItem) list_item.child; - search_result_item.place = (Geocode.Place) list_item.get_item (); + search_result_item.place = (Geocode.Place) list_item.item; } }