Cleanup: extract sorted_cinemas().
authorCarl Hetherington <cth@carlh.net>
Wed, 23 Nov 2022 20:03:59 +0000 (21:03 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 23 Nov 2022 20:23:25 +0000 (21:23 +0100)
src/wx/screens_panel.cc
src/wx/screens_panel.h

index 272b983d90c8bf5e72c81e00c3b38ef3e9791163..b7defe0e9be39e482d6163fe1f4f1972edb21330 100644 (file)
@@ -32,6 +32,7 @@
 
 
 using std::cout;
+using std::list;
 using std::make_pair;
 using std::make_shared;
 using std::map;
@@ -235,10 +236,7 @@ ScreensPanel::add_cinema_clicked ()
        if (dialog->ShowModal() == wxID_OK) {
                auto cinema = make_shared<Cinema>(dialog->name(), dialog->emails(), dialog->notes(), dialog->utc_offset_hour(), dialog->utc_offset_minute());
 
-               auto cinemas = Config::instance()->cinemas();
-               cinemas.sort(
-                       [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return _collator.compare(a->name, b->name) < 0; }
-                       );
+               auto cinemas = sorted_cinemas();
 
                try {
                        _ignore_cinemas_changed = true;
@@ -495,15 +493,23 @@ ScreensPanel::selection_changed ()
 }
 
 
-void
-ScreensPanel::add_cinemas ()
+list<shared_ptr<Cinema>>
+ScreensPanel::sorted_cinemas() const
 {
        auto cinemas = Config::instance()->cinemas();
+
        cinemas.sort(
                [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return _collator.compare(a->name, b->name) < 0; }
                );
 
-       for (auto cinema: cinemas) {
+       return cinemas;
+}
+
+
+void
+ScreensPanel::add_cinemas ()
+{
+       for (auto cinema: sorted_cinemas()) {
                add_cinema (cinema, wxTLI_LAST);
        }
 }
index 73da029d0e4a6f83fa745045b2ddbf7b08a6b332..b469c19e307dc49d32758588c33489cc32127f80 100644 (file)
@@ -76,6 +76,7 @@ private:
        void config_changed(Config::Property);
        void convert_to_lower(std::string& s);
        bool matches_search(std::shared_ptr<const Cinema> cinema, std::string lower_case_search);
+       std::list<std::shared_ptr<Cinema>> sorted_cinemas() const;
 
        std::shared_ptr<Cinema> item_to_cinema (wxTreeListItem item) const;
        std::shared_ptr<dcpomatic::Screen> item_to_screen (wxTreeListItem item) const;