X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ftemplates_dialog.cc;h=145e4f2b97119d3557c7805705d3e4ce39265d99;hb=7aab34abcab28ca38a5354dec075b56d430e82db;hp=e8f9b8a2b22516160f3400222b762fe601f6d62f;hpb=a5d004b0773f633401528392fc28e66d70e13ac8;p=dcpomatic.git diff --git a/src/wx/templates_dialog.cc b/src/wx/templates_dialog.cc index e8f9b8a2b..145e4f2b9 100644 --- a/src/wx/templates_dialog.cc +++ b/src/wx/templates_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,12 +18,17 @@ */ + +#include "dcpomatic_button.h" +#include "rename_template_dialog.h" #include "templates_dialog.h" #include "wx_util.h" -#include "rename_template_dialog.h" -#include "dcpomatic_button.h" #include "lib/config.h" +#include +LIBDCP_DISABLE_WARNINGS #include +LIBDCP_ENABLE_WARNINGS + using std::string; using boost::bind; @@ -31,14 +36,15 @@ using boost::bind; using namespace boost::placeholders; #endif + TemplatesDialog::TemplatesDialog (wxWindow* parent) : wxDialog (parent, wxID_ANY, _("Templates")) { _sizer = new wxBoxSizer (wxVERTICAL); SetSizer (_sizer); - wxSizer* hs = new wxBoxSizer (wxHORIZONTAL); - _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (200, 100), wxLC_REPORT | wxLC_SINGLE_SEL); + auto hs = new wxBoxSizer (wxHORIZONTAL); + _list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(400, 300), wxLC_REPORT | wxLC_SINGLE_SEL); wxListItem ip; ip.SetId (0); @@ -49,33 +55,36 @@ TemplatesDialog::TemplatesDialog (wxWindow* parent) hs->Add (_list, 1, wxEXPAND, DCPOMATIC_SIZER_GAP); { - wxSizer* s = new wxBoxSizer (wxVERTICAL); + auto s = new wxBoxSizer (wxVERTICAL); _rename = new Button (this, _("Rename...")); - s->Add (_rename, 0, wxTOP | wxBOTTOM, 2); + s->Add(_rename, 0, wxTOP | wxBOTTOM | wxEXPAND, 2); _remove = new Button (this, _("Remove")); - s->Add (_remove, 0, wxTOP | wxBOTTOM, 2); + s->Add(_remove, 0, wxTOP | wxBOTTOM | wxEXPAND, 2); hs->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP); } _sizer->Add (hs, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER); - wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE); + auto buttons = CreateSeparatedButtonSizer (wxCLOSE); if (buttons) { _sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } - _rename->Bind (wxEVT_BUTTON, bind (&TemplatesDialog::rename_clicked, this)); - _remove->Bind (wxEVT_BUTTON, bind (&TemplatesDialog::remove_clicked, this)); + _rename->Bind (wxEVT_BUTTON, bind(&TemplatesDialog::rename_clicked, this)); + _remove->Bind (wxEVT_BUTTON, bind(&TemplatesDialog::remove_clicked, this)); - _list->Bind (wxEVT_LIST_ITEM_SELECTED, bind (&TemplatesDialog::selection_changed, this)); - _list->Bind (wxEVT_LIST_ITEM_DESELECTED, bind (&TemplatesDialog::selection_changed, this)); - _list->Bind (wxEVT_SIZE, bind (&TemplatesDialog::resized, this, _1)); - _config_connection = Config::instance()->Changed.connect (bind (&TemplatesDialog::refresh, this)); + _list->Bind (wxEVT_LIST_ITEM_SELECTED, bind(&TemplatesDialog::selection_changed, this)); + _list->Bind (wxEVT_LIST_ITEM_DESELECTED, bind(&TemplatesDialog::selection_changed, this)); + _list->Bind (wxEVT_SIZE, bind(&TemplatesDialog::resized, this, _1)); + _config_connection = Config::instance()->Changed.connect (bind(&TemplatesDialog::refresh, this)); + + Fit(); refresh (); selection_changed (); } + void TemplatesDialog::refresh () { @@ -90,12 +99,14 @@ TemplatesDialog::refresh () } } + void TemplatesDialog::layout () { _sizer->Layout (); } + void TemplatesDialog::selection_changed () { @@ -104,6 +115,7 @@ TemplatesDialog::selection_changed () _remove->Enable (i >= 0); } + void TemplatesDialog::rename_clicked () { @@ -118,19 +130,21 @@ TemplatesDialog::rename_clicked () li.m_mask = wxLIST_MASK_TEXT; _list->GetItem (li); - RenameTemplateDialog* d = new RenameTemplateDialog (this); - d->set (li.m_text); - if (d->ShowModal() == wxID_OK) { - if (!d->get().IsEmpty()) { - Config::instance()->rename_template (wx_to_std (li.m_text), wx_to_std (d->get ())); - _list->SetItem (item, 0, d->get()); - } else { - error_dialog (this, _("Template names must not be empty.")); - } + RenameTemplateDialog dialog(this); + dialog.set(li.m_text); + if (dialog.ShowModal() != wxID_OK) { + return; + } + + if (!dialog.get().IsEmpty()) { + Config::instance()->rename_template(wx_to_std(li.m_text), wx_to_std(dialog.get())); + _list->SetItem(item, 0, dialog.get()); + } else { + error_dialog (this, _("Template names must not be empty.")); } - d->Destroy (); } + void TemplatesDialog::remove_clicked () { @@ -145,12 +159,13 @@ TemplatesDialog::remove_clicked () li.m_mask = wxLIST_MASK_TEXT; _list->GetItem (li); - Config::instance()->delete_template (wx_to_std (li.m_text)); + Config::instance()->delete_template (wx_to_std(li.m_text)); _list->DeleteItem (i); selection_changed (); } + void TemplatesDialog::resized (wxSizeEvent& ev) {