#include "lib/cinema.h"
#include "lib/config.h"
#include "lib/screen.h"
+#include "lib/timer.h"
#include <unicode/putil.h>
#include <unicode/ucol.h>
#include <unicode/uiter.h>
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);
_remove_screen->Bind (wxEVT_BUTTON, boost::bind (&ScreensPanel::remove_screen_clicked, this));
SetSizer (sizer);
+
+ 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);
+ }
}
{
_targets->Unbind (wxEVT_TREELIST_SELECTION_CHANGED, &ScreensPanel::selection_changed_shim, this);
_targets->Unbind (wxEVT_TREELIST_ITEM_CHECKED, &ScreensPanel::checkbox_changed, this);
+
+ if (_collator) {
+ ucol_close (_collator);
+ }
}
optional<wxTreeListItem>
-ScreensPanel::add_cinema (shared_ptr<Cinema> cinema)
+ScreensPanel::add_cinema (shared_ptr<Cinema> cinema, wxTreeListItem previous)
{
auto search = wx_to_std (_search->GetValue ());
transform (search.begin(), search.end(), search.begin(), ::tolower);
}
}
- 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;
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) {
+
+ auto cinemas = Config::instance()->cinemas();
+ cinemas.sort(
+ [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return compare(a->name, b->name) < 0; }
+ );
+
+ optional<wxTreeListItem> item;
+ for (auto existing_cinema: cinemas) {
+ if (!item && compare(d->name(), existing_cinema->name) < 0) {
+ if (auto existing_item = cinema_to_item(existing_cinema)) {
+ item = add_cinema (cinema, *existing_item);
+ }
+ }
+ }
+
+ if (!item) {
+ item = add_cinema (cinema, wxTLI_LAST);
+ }
+
+ if (item) {
_targets->UnselectAll ();
- _targets->Select (*id);
+ _targets->Select (*item);
}
+
+ Config::instance()->add_cinema (cinema);
}
d->Destroy ();
void
ScreensPanel::add_cinemas ()
{
- for (auto cinema: Config::instance()->cinemas()) {
- add_cinema (cinema);
+ auto cinemas = Config::instance()->cinemas();
+ cinemas.sort(
+ [this](shared_ptr<Cinema> a, shared_ptr<Cinema> b) { return compare(a->name, b->name) < 0; }
+ );
+
+ for (auto cinema: cinemas) {
+ add_cinema (cinema, wxTLI_LAST);
}
}
}
-ScreensPanel::Comparator::Comparator ()
-{
- 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);
- }
-}
-
-ScreensPanel::Comparator::~Comparator ()
-{
- if (_collator) {
- ucol_close (_collator);
- }
-}
-
int
-ScreensPanel::Comparator::Compare (wxTreeListCtrl* tree_list, unsigned, wxTreeListItem a, wxTreeListItem b)
+ScreensPanel::compare (string const& utf8_a, string const& utf8_b)
{
- 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]);
private:
void add_cinemas ();
- boost::optional<wxTreeListItem> add_cinema (std::shared_ptr<Cinema>);
+ boost::optional<wxTreeListItem> add_cinema (std::shared_ptr<Cinema>, wxTreeListItem previous);
boost::optional<wxTreeListItem> add_screen (std::shared_ptr<Cinema>, std::shared_ptr<dcpomatic::Screen>);
void add_cinema_clicked ();
void edit_cinema_clicked ();
boost::optional<std::pair<wxTreeListItem, std::shared_ptr<Cinema>>> cinema_for_operation () const;
void set_screen_checked (wxTreeListItem item, bool checked);
void setup_cinema_checked_state (wxTreeListItem screen);
+ int compare (std::string const& utf8_a, std::string const& utf8_b);
typedef std::vector<std::pair<wxTreeListItem, std::shared_ptr<Cinema>>> Cinemas;
typedef std::vector<std::pair<wxTreeListItem, std::shared_ptr<dcpomatic::Screen>>> Screens;
bool _ignore_selection_change = false;
bool _ignore_check_change = false;
- class Comparator : public wxTreeListItemComparator
- {
- public:
- Comparator ();
- ~Comparator ();
-
- int Compare (wxTreeListCtrl* tree_list, unsigned, wxTreeListItem a, wxTreeListItem b) override;
-
- private:
- UCollator* _collator;
- };
-
- Comparator _comparator;
+ UCollator* _collator = nullptr;
};