- CinemaDialog* d = new CinemaDialog (GetParent(), _("Add Cinema"));
- if (d->ShowModal () == wxID_OK) {
- shared_ptr<Cinema> c (new Cinema (d->name(), d->emails(), d->notes(), d->utc_offset_hour(), d->utc_offset_minute()));
- Config::instance()->add_cinema (c);
- add_cinema (c);
+ auto dialog = new CinemaDialog (GetParent(), _("Add Cinema"));
+ ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+
+ 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; }
+ );
+
+ try {
+ _ignore_cinemas_changed = true;
+ ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
+ Config::instance()->add_cinema(cinema);
+ } catch (FileError& e) {
+ error_dialog(GetParent(), _("Could not write cinema details to the cinemas.xml file. Check that the location of cinemas.xml is valid in DCP-o-matic's preferences."), std_to_wx(e.what()));
+ return;
+ }
+
+ wxTreeListItem previous = wxTLI_FIRST;
+ bool found = false;
+ for (auto existing_cinema: cinemas) {
+ if (_collator.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;
+ }
+
+ auto item = add_cinema(cinema, found ? previous : wxTLI_LAST);
+
+ if (item) {
+ _targets->UnselectAll ();
+ _targets->Select (*item);
+ }
+ }
+
+ selection_changed ();
+}
+
+
+shared_ptr<Cinema>
+ScreensPanel::cinema_for_operation () const
+{
+ if (_selected_cinemas.size() == 1) {
+ return _selected_cinemas[0];
+ } else if (_selected_screens.size() == 1) {
+ return _selected_screens[0]->cinema;