Fix incorrect ordering when adding cinemas.
authorCarl Hetherington <cth@carlh.net>
Tue, 30 Aug 2022 22:33:12 +0000 (00:33 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 30 Aug 2022 22:33:12 +0000 (00:33 +0200)
src/wx/screens_panel.cc

index 10adad7e53b78cc44839704beac00104529fbc35..562ea8f3895d0d67423ee135ae8b76bf4ef35900 100644 (file)
@@ -251,18 +251,20 @@ ScreensPanel::add_cinema_clicked ()
                        return;
                }
 
-               optional<wxTreeListItem> item;
+               wxTreeListItem previous = wxTLI_FIRST;
+               bool found = false;
                for (auto existing_cinema: cinemas) {
-                       if (!item && compare(dialog->name(), existing_cinema->name) < 0) {
-                               if (auto existing_item = cinema_to_item(existing_cinema)) {
-                                       item = add_cinema (cinema, *existing_item);
-                               }
+                       if (compare(dialog->name(), existing_cinema->name) < 0) {
+                               /* existing_cinema should be after the one we're inserting */
+                               found = true;
+                               break;
                        }
+                       auto item = cinema_to_item(existing_cinema);
+                       DCPOMATIC_ASSERT(item);
+                       previous = *item;
                }
 
-               if (!item) {
-                       item = add_cinema (cinema, wxTLI_LAST);
-               }
+               auto item = add_cinema(cinema, found ? previous : wxTLI_LAST);
 
                if (item) {
                        _targets->UnselectAll ();