Use collator to search for screens (#2426).
[dcpomatic.git] / src / wx / screens_panel.cc
index 34bdadd8ea35b91014c5efcf739ec6d4a5ebc966..6c5b28b8d0fdd048449ce2c0e3a0bdfc8994d3a3 100644 (file)
 #include "wx_util.h"
 #include "lib/cinema.h"
 #include "lib/config.h"
+#include "lib/scope_guard.h"
 #include "lib/screen.h"
-#include <unicode/putil.h>
-#include <unicode/ucol.h>
-#include <unicode/uiter.h>
-#include <unicode/utypes.h>
-#include <unicode/ustring.h>
+#include "lib/timer.h"
 
 
 using std::cout;
+using std::list;
 using std::make_pair;
 using std::make_shared;
 using std::map;
@@ -43,6 +41,9 @@ using std::shared_ptr;
 using std::string;
 using std::vector;
 using boost::optional;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
 using namespace dcpomatic;
 
 
@@ -61,13 +62,13 @@ ScreensPanel::ScreensPanel (wxWindow* parent)
        auto targets = new wxBoxSizer (wxHORIZONTAL);
        _targets = new wxTreeListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTL_MULTIPLE | wxTL_3STATE | wxTL_NO_HEADER);
        _targets->AppendColumn (wxT("foo"));
-       _targets->SetSortColumn (0);
-       _targets->SetItemComparator (&_comparator);
 
        targets->Add (_targets, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
 
        add_cinemas ();
 
+       auto side_buttons = new wxBoxSizer (wxVERTICAL);
+
        auto target_buttons = new wxBoxSizer (wxVERTICAL);
 
        _add_cinema = new Button (this, _("Add Cinema..."));
@@ -83,13 +84,25 @@ ScreensPanel::ScreensPanel (wxWindow* parent)
        _remove_screen = new Button (this, _("Remove Screen"));
        target_buttons->Add (_remove_screen, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
 
-       targets->Add (target_buttons, 0, 0);
+       side_buttons->Add (target_buttons, 0, 0);
+
+       auto check_buttons = new wxBoxSizer (wxVERTICAL);
+
+       _check_all = new Button (this, _("Check all"));
+       check_buttons->Add (_check_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
+       _uncheck_all = new Button (this, _("Uncheck all"));
+       check_buttons->Add (_uncheck_all, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
+
+       side_buttons->Add (check_buttons, 1, wxEXPAND | wxTOP, DCPOMATIC_BUTTON_STACK_GAP * 8);
+
+       targets->Add (side_buttons, 0, 0);
 
        sizer->Add (targets, 1, wxEXPAND);
 
        _search->Bind        (wxEVT_TEXT, boost::bind (&ScreensPanel::search_changed, this));
        _targets->Bind       (wxEVT_TREELIST_SELECTION_CHANGED, &ScreensPanel::selection_changed_shim, this);
        _targets->Bind       (wxEVT_TREELIST_ITEM_CHECKED, &ScreensPanel::checkbox_changed, this);
+       _targets->Bind       (wxEVT_TREELIST_ITEM_ACTIVATED, &ScreensPanel::item_activated, this);
 
        _add_cinema->Bind    (wxEVT_BUTTON, boost::bind (&ScreensPanel::add_cinema_clicked, this));
        _edit_cinema->Bind   (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_cinema_clicked, this));
@@ -99,7 +112,12 @@ ScreensPanel::ScreensPanel (wxWindow* parent)
        _edit_screen->Bind   (wxEVT_BUTTON, boost::bind (&ScreensPanel::edit_screen_clicked, this));
        _remove_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_screen_clicked, this));
 
+       _check_all->Bind     (wxEVT_BUTTON, boost::bind(&ScreensPanel::check_all, this));
+       _uncheck_all->Bind   (wxEVT_BUTTON, boost::bind(&ScreensPanel::uncheck_all, this));
+
        SetSizer (sizer);
+
+       _config_connection = Config::instance()->Changed.connect(boost::bind(&ScreensPanel::config_changed, this, _1));
 }
 
 
@@ -110,6 +128,32 @@ ScreensPanel::~ScreensPanel ()
 }
 
 
+void
+ScreensPanel::check_all ()
+{
+       for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk();  cinema = _targets->GetNextSibling(cinema)) {
+               _targets->CheckItem(cinema, wxCHK_CHECKED);
+               for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
+                       _targets->CheckItem(screen, wxCHK_CHECKED);
+                       set_screen_checked(screen, true);
+               }
+       }
+}
+
+
+void
+ScreensPanel::uncheck_all ()
+{
+       for (auto cinema = _targets->GetFirstChild(_targets->GetRootItem()); cinema.IsOk();  cinema = _targets->GetNextSibling(cinema)) {
+               _targets->CheckItem(cinema, wxCHK_UNCHECKED);
+               for (auto screen = _targets->GetFirstChild(cinema); screen.IsOk(); screen = _targets->GetNextSibling(screen)) {
+                       _targets->CheckItem(screen, wxCHK_UNCHECKED);
+                       set_screen_checked(screen, false);
+               }
+       }
+}
+
+
 void
 ScreensPanel::setup_sensitivity ()
 {
@@ -125,23 +169,34 @@ ScreensPanel::setup_sensitivity ()
 }
 
 
-optional<wxTreeListItem>
-ScreensPanel::add_cinema (shared_ptr<Cinema> cinema)
+void
+ScreensPanel::convert_to_lower(string& s)
+{
+       transform(s.begin(), s.end(), s.begin(), ::tolower);
+}
+
+
+bool
+ScreensPanel::matches_search(shared_ptr<const Cinema> cinema, string search)
 {
-       auto search = wx_to_std (_search->GetValue ());
-       transform (search.begin(), search.end(), search.begin(), ::tolower);
+       if (search.empty()) {
+               return true;
+       }
 
-       if (!search.empty ()) {
-               auto name = cinema->name;
-               transform (name.begin(), name.end(), name.begin(), ::tolower);
-               if (name.find (search) == string::npos) {
-                       return {};
-               }
+       return _collator.find(search, cinema->name);
+}
+
+
+optional<wxTreeListItem>
+ScreensPanel::add_cinema (shared_ptr<Cinema> cinema, wxTreeListItem previous)
+{
+       auto const search = wx_to_std(_search->GetValue());
+       if (!matches_search(cinema, search)) {
+               return {};
        }
 
-       auto id = _targets->AppendItem(_targets->GetRootItem(), std_to_wx(cinema->name));
+       auto id = _targets->InsertItem(_targets->GetRootItem(), previous, std_to_wx(cinema->name));
 
-       _cinemas.push_back(make_pair(id, cinema));
        _item_to_cinema[id] = cinema;
        _cinema_to_item[cinema] = id;
 
@@ -163,7 +218,6 @@ ScreensPanel::add_screen (shared_ptr<Cinema> cinema, shared_ptr<Screen> screen)
 
        auto id = _targets->AppendItem(*item, std_to_wx(screen->name));
 
-       _screens.push_back(make_pair(id, screen));
        _item_to_screen[id] = screen;
        _screen_to_item[screen] = id;
 
@@ -174,28 +228,58 @@ ScreensPanel::add_screen (shared_ptr<Cinema> cinema, shared_ptr<Screen> screen)
 void
 ScreensPanel::add_cinema_clicked ()
 {
-       auto d = new CinemaDialog (GetParent(), _("Add Cinema"));
-       if (d->ShowModal () == wxID_OK) {
-               auto cinema = make_shared<Cinema>(d->name(), d->emails(), d->notes(), d->utc_offset_hour(), d->utc_offset_minute());
-               Config::instance()->add_cinema (cinema);
-               auto id = add_cinema (cinema);
-               if (id) {
+       CinemaDialog dialog(GetParent(), _("Add Cinema"));
+
+       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 = sorted_cinemas();
+
+               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;
+               auto const search = wx_to_std(_search->GetValue());
+               for (auto existing_cinema: cinemas) {
+                       if (!matches_search(existing_cinema, search)) {
+                               continue;
+                       }
+                       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 (*id);
+                       _targets->Select (*item);
                }
        }
 
-       d->Destroy ();
+       selection_changed ();
 }
 
 
-optional<pair<wxTreeListItem, shared_ptr<Cinema>>>
+shared_ptr<Cinema>
 ScreensPanel::cinema_for_operation () const
 {
        if (_selected_cinemas.size() == 1) {
-               return make_pair(_selected_cinemas.begin()->first, _selected_cinemas.begin()->second);
+               return _selected_cinemas[0];
        } else if (_selected_screens.size() == 1) {
-               return make_pair(_targets->GetItemParent(_selected_screens.begin()->first), _selected_screens.begin()->second->cinema);
+               return _selected_screens[0]->cinema;
        }
 
        return {};
@@ -206,25 +290,30 @@ void
 ScreensPanel::edit_cinema_clicked ()
 {
        auto cinema = cinema_for_operation ();
-       if (!cinema) {
-               return;
+       if (cinema) {
+               edit_cinema(cinema);
        }
+}
 
-       auto d = new CinemaDialog (
-               GetParent(), _("Edit cinema"), cinema->second->name, cinema->second->emails, cinema->second->notes, cinema->second->utc_offset_hour(), cinema->second->utc_offset_minute()
+
+void
+ScreensPanel::edit_cinema(shared_ptr<Cinema> cinema)
+{
+       CinemaDialog dialog(
+               GetParent(), _("Edit cinema"), cinema->name, cinema->emails, cinema->notes, cinema->utc_offset_hour(), cinema->utc_offset_minute()
                );
 
-       if (d->ShowModal() == wxID_OK) {
-               cinema->second->name = d->name ();
-               cinema->second->emails = d->emails ();
-               cinema->second->notes = d->notes ();
-               cinema->second->set_utc_offset_hour (d->utc_offset_hour ());
-               cinema->second->set_utc_offset_minute (d->utc_offset_minute ());
-               _targets->SetItemText (cinema->first, std_to_wx(d->name()));
-               Config::instance()->changed (Config::CINEMAS);
+       if (dialog.ShowModal() == wxID_OK) {
+               cinema->name = dialog.name();
+               cinema->emails = dialog.emails();
+               cinema->notes = dialog.notes();
+               cinema->set_utc_offset_hour(dialog.utc_offset_hour());
+               cinema->set_utc_offset_minute(dialog.utc_offset_minute());
+               notify_cinemas_changed();
+               auto item = cinema_to_item(cinema);
+               DCPOMATIC_ASSERT(item);
+               _targets->SetItemText (*item, std_to_wx(dialog.name()));
        }
-
-       d->Destroy ();
 }
 
 
@@ -232,7 +321,7 @@ void
 ScreensPanel::remove_cinema_clicked ()
 {
        if (_selected_cinemas.size() == 1) {
-               if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the cinema '%s'?"), std_to_wx(_selected_cinemas.begin()->second->name)))) {
+               if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the cinema '%s'?"), std_to_wx(_selected_cinemas[0]->name)))) {
                        return;
                }
        } else {
@@ -241,9 +330,13 @@ ScreensPanel::remove_cinema_clicked ()
                }
        }
 
-       for (auto const& i: _selected_cinemas) {
-               Config::instance()->remove_cinema (i.second);
-               _targets->DeleteItem (i.first);
+       for (auto const& cinema: _selected_cinemas) {
+               _ignore_cinemas_changed = true;
+               ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
+               Config::instance()->remove_cinema(cinema);
+               auto item = cinema_to_item(cinema);
+               DCPOMATIC_ASSERT(item);
+               _targets->DeleteItem(*item);
        }
 
        selection_changed ();
@@ -258,84 +351,85 @@ ScreensPanel::add_screen_clicked ()
                return;
        }
 
-       auto d = new ScreenDialog (GetParent(), _("Add Screen"));
-       if (d->ShowModal () != wxID_OK) {
-               d->Destroy ();
+       ScreenDialog dialog(GetParent(), _("Add Screen"));
+
+       if (dialog.ShowModal () != wxID_OK) {
                return;
        }
 
-       for (auto screen: cinema->second->screens()) {
-               if (screen->name == d->name()) {
+       for (auto screen: cinema->screens()) {
+               if (screen->name == dialog.name()) {
                        error_dialog (
                                GetParent(),
                                wxString::Format (
                                        _("You cannot add a screen called '%s' as the cinema already has a screen with this name."),
-                                       std_to_wx(d->name()).data()
+                                       std_to_wx(dialog.name()).data()
                                        )
                                );
                        return;
                }
        }
 
-       auto screen = std::make_shared<Screen>(d->name(), d->notes(), d->recipient(), d->recipient_file(), d->trusted_devices());
-       cinema->second->add_screen (screen);
-       auto id = add_screen (cinema->second, screen);
+       auto screen = std::make_shared<Screen>(dialog.name(), dialog.notes(), dialog.recipient(), dialog.recipient_file(), dialog.trusted_devices());
+       cinema->add_screen (screen);
+       notify_cinemas_changed();
+
+       auto id = add_screen (cinema, screen);
        if (id) {
                _targets->Expand (id.get ());
        }
-
-       Config::instance()->changed (Config::CINEMAS);
-
-       d->Destroy ();
 }
 
 
 void
 ScreensPanel::edit_screen_clicked ()
 {
-       if (_selected_screens.size() != 1) {
-               return;
+       if (_selected_screens.size() == 1) {
+               edit_screen(_selected_screens[0]);
        }
+}
 
-       auto edit_screen = *_selected_screens.begin();
 
-       auto d = new ScreenDialog (
+void
+ScreensPanel::edit_screen(shared_ptr<Screen> edit_screen)
+{
+       ScreenDialog dialog(
                GetParent(), _("Edit screen"),
-               edit_screen.second->name,
-               edit_screen.second->notes,
-               edit_screen.second->recipient,
-               edit_screen.second->recipient_file,
-               edit_screen.second->trusted_devices
+               edit_screen->name,
+               edit_screen->notes,
+               edit_screen->recipient,
+               edit_screen->recipient_file,
+               edit_screen->trusted_devices
                );
 
-       if (d->ShowModal() != wxID_OK) {
-               d->Destroy ();
+       if (dialog.ShowModal() != wxID_OK) {
                return;
        }
 
-       auto cinema = edit_screen.second->cinema;
+       auto cinema = edit_screen->cinema;
        for (auto screen: cinema->screens()) {
-               if (screen != edit_screen.second && screen->name == d->name()) {
+               if (screen != edit_screen && screen->name == dialog.name()) {
                        error_dialog (
                                GetParent(),
                                wxString::Format (
                                        _("You cannot change this screen's name to '%s' as the cinema already has a screen with this name."),
-                                       std_to_wx(d->name()).data()
+                                       std_to_wx(dialog.name()).data()
                                        )
                                );
                        return;
                }
        }
 
-       edit_screen.second->name = d->name ();
-       edit_screen.second->notes = d->notes ();
-       edit_screen.second->recipient = d->recipient ();
-       edit_screen.second->recipient_file = d->recipient_file ();
-       edit_screen.second->trusted_devices = d->trusted_devices ();
-       _targets->SetItemText (edit_screen.first, std_to_wx(d->name()));
-       Config::instance()->changed (Config::CINEMAS);
+       edit_screen->name = dialog.name();
+       edit_screen->notes = dialog.notes();
+       edit_screen->recipient = dialog.recipient();
+       edit_screen->recipient_file = dialog.recipient_file();
+       edit_screen->trusted_devices = dialog.trusted_devices();
+       notify_cinemas_changed();
 
-       d->Destroy ();
+       auto item = screen_to_item(edit_screen);
+       DCPOMATIC_ASSERT (item);
+       _targets->SetItemText(*item, std_to_wx(dialog.name()));
 }
 
 
@@ -343,7 +437,7 @@ void
 ScreensPanel::remove_screen_clicked ()
 {
        if (_selected_screens.size() == 1) {
-               if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the screen '%s'?"), std_to_wx(_selected_screens.begin()->second->name)))) {
+               if (!confirm_dialog(this, wxString::Format(_("Are you sure you want to remove the screen '%s'?"), std_to_wx(_selected_screens[0]->name)))) {
                        return;
                }
        } else {
@@ -352,26 +446,18 @@ ScreensPanel::remove_screen_clicked ()
                }
        }
 
-       for (auto const& i: _selected_screens) {
-               auto j = _cinemas.begin ();
-               while (j != _cinemas.end ()) {
-                       auto sc = j->second->screens ();
-                       if (find (sc.begin(), sc.end(), i.second) != sc.end ()) {
-                               break;
-                       }
-
-                       ++j;
-               }
-
-               if (j == _cinemas.end()) {
-                       continue;
-               }
-
-               j->second->remove_screen (i.second);
-               _targets->DeleteItem (i.first);
+       for (auto const& screen: _selected_screens) {
+               screen->cinema->remove_screen(screen);
+               auto item = screen_to_item(screen);
+               DCPOMATIC_ASSERT(item);
+               _targets->DeleteItem(*item);
        }
 
-       Config::instance()->changed (Config::CINEMAS);
+       /* This is called by the signal on Linux, but not it seems on Windows, so we call it ourselves
+        * as well.
+        */
+       selection_changed();
+       notify_cinemas_changed();
 }
 
 
@@ -379,15 +465,7 @@ vector<shared_ptr<Screen>>
 ScreensPanel::screens () const
 {
        vector<shared_ptr<Screen>> output;
-
-       for (auto item = _targets->GetFirstItem(); item.IsOk(); item = _targets->GetNextItem(item)) {
-               if (_targets->GetCheckedState(item) == wxCHK_CHECKED) {
-                       if (auto screen = item_to_screen(item)) {
-                               output.push_back (screen);
-                       }
-               }
-       }
-
+       std::copy (_checked_screens.begin(), _checked_screens.end(), std::back_inserter(output));
        return output;
 }
 
@@ -414,10 +492,10 @@ ScreensPanel::selection_changed ()
 
        for (size_t i = 0; i < selection.size(); ++i) {
                if (auto cinema = item_to_cinema(selection[i])) {
-                       _selected_cinemas.push_back(make_pair(selection[i], cinema));
+                       _selected_cinemas.push_back(cinema);
                }
                if (auto screen = item_to_screen(selection[i])) {
-                       _selected_screens.push_back(make_pair(selection[i], screen));
+                       _selected_screens.push_back(screen);
                }
        }
 
@@ -425,21 +503,32 @@ ScreensPanel::selection_changed ()
 }
 
 
+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; }
+               );
+
+       return cinemas;
+}
+
+
 void
 ScreensPanel::add_cinemas ()
 {
-       for (auto cinema: Config::instance()->cinemas()) {
-               add_cinema (cinema);
+       for (auto cinema: sorted_cinemas()) {
+               add_cinema (cinema, wxTLI_LAST);
        }
 }
 
 
 void
-ScreensPanel::search_changed ()
+ScreensPanel::clear_and_re_add()
 {
        _targets->DeleteAllItems ();
-       _cinemas.clear ();
-       _screens.clear ();
 
        _item_to_cinema.clear ();
        _cinema_to_item.clear ();
@@ -447,19 +536,24 @@ ScreensPanel::search_changed ()
        _screen_to_item.clear ();
 
        add_cinemas ();
+}
+
+
+void
+ScreensPanel::search_changed ()
+{
+       clear_and_re_add();
 
        _ignore_selection_change = true;
 
        for (auto const& selection: _selected_cinemas) {
-               /* The wxTreeListItems will now be different, so we must search by cinema */
-               if (auto item = cinema_to_item(selection.second)) {
+               if (auto item = cinema_to_item(selection)) {
                        _targets->Select (*item);
                }
        }
 
        for (auto const& selection: _selected_screens) {
-               /* Likewise by screen */
-               if (auto item = screen_to_item(selection.second)) {
+               if (auto item = screen_to_item(selection)) {
                        _targets->Select (*item);
                }
        }
@@ -469,7 +563,7 @@ ScreensPanel::search_changed ()
        _ignore_check_change = true;
 
        for (auto const& checked: _checked_screens) {
-               if (auto item = screen_to_item(checked.second)) {
+               if (auto item = screen_to_item(checked)) {
                        _targets->CheckItem(*item, wxCHK_CHECKED);
                        setup_cinema_checked_state(*item);
                }
@@ -482,15 +576,12 @@ ScreensPanel::search_changed ()
 void
 ScreensPanel::set_screen_checked (wxTreeListItem item, bool checked)
 {
-       auto current = std::find_if(
-               _checked_screens.begin(), _checked_screens.end(),
-               [item](pair<wxTreeListItem, shared_ptr<Screen>> const& screen) { return screen.first == item; }
-               );
-
-       if (current == _checked_screens.end() && checked) {
-               _checked_screens.push_back({item, item_to_screen(item)});
-       } else if (current != _checked_screens.end() && !checked) {
-               _checked_screens.erase(current);
+       auto screen = item_to_screen(item);
+       DCPOMATIC_ASSERT(screen);
+       if (checked) {
+               _checked_screens.insert(screen);
+       } else {
+               _checked_screens.erase(screen);
        }
 }
 
@@ -590,37 +681,44 @@ ScreensPanel::screen_to_item (shared_ptr<Screen> screen) const
 }
 
 
-ScreensPanel::Comparator::Comparator ()
+bool
+ScreensPanel::notify_cinemas_changed()
 {
-       UErrorCode status = U_ZERO_ERROR;
-       _collator = ucol_open(nullptr, &status);
-       if (_collator) {
-               ucol_setAttribute(_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
-               ucol_setAttribute(_collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
-               ucol_setAttribute(_collator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
+       _ignore_cinemas_changed = true;
+       ScopeGuard sg = [this]() { _ignore_cinemas_changed = false; };
+
+       try {
+               Config::instance()->changed(Config::CINEMAS);
+       } 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 false;
        }
+
+       return true;
 }
 
-ScreensPanel::Comparator::~Comparator ()
+
+void
+ScreensPanel::config_changed(Config::Property property)
 {
-       if (_collator) {
-               ucol_close (_collator);
+       if (property == Config::Property::CINEMAS && !_ignore_cinemas_changed) {
+               clear_and_re_add();
        }
 }
 
-int
-ScreensPanel::Comparator::Compare (wxTreeListCtrl* tree_list, unsigned, wxTreeListItem a, wxTreeListItem b)
+
+void
+ScreensPanel::item_activated(wxTreeListEvent& ev)
 {
-       auto utf8_a = wx_to_std(tree_list->GetItemText(a));
-       auto utf8_b = wx_to_std(tree_list->GetItemText(b));
-       if (_collator) {
-               UErrorCode error = U_ZERO_ERROR;
-               boost::scoped_array<uint16_t> utf16_a(new uint16_t[utf8_a.size() + 1]);
-               u_strFromUTF8(reinterpret_cast<UChar*>(utf16_a.get()), utf8_a.size() + 1, nullptr, utf8_a.c_str(), -1, &error);
-               boost::scoped_array<uint16_t> utf16_b(new uint16_t[utf8_b.size() + 1]);
-               u_strFromUTF8(reinterpret_cast<UChar*>(utf16_b.get()), utf8_b.size() + 1, nullptr, utf8_b.c_str(), -1, &error);
-               return ucol_strcoll(_collator, reinterpret_cast<UChar*>(utf16_a.get()), -1, reinterpret_cast<UChar*>(utf16_b.get()), -1);
+       auto iter = _item_to_cinema.find(ev.GetItem());
+       if (iter != _item_to_cinema.end()) {
+               edit_cinema(iter->second);
        } else {
-               return strcoll(utf8_a.c_str(), utf8_b.c_str());
+               auto iter = _item_to_screen.find(ev.GetItem());
+               if (iter != _item_to_screen.end()) {
+                       edit_screen(iter->second);
+               }
        }
 }
+
+