From 09287979ce90e809880cd17fb20deb23669f68e4 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 31 Aug 2022 00:33:12 +0200 Subject: [PATCH] Fix incorrect ordering when adding cinemas. --- src/wx/screens_panel.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/wx/screens_panel.cc b/src/wx/screens_panel.cc index 10adad7e5..562ea8f38 100644 --- a/src/wx/screens_panel.cc +++ b/src/wx/screens_panel.cc @@ -251,18 +251,20 @@ ScreensPanel::add_cinema_clicked () return; } - optional 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 (); -- 2.30.2