2 Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "dcpomatic_button.h"
23 #include "rename_template_dialog.h"
24 #include "templates_dialog.h"
26 #include "lib/config.h"
27 #include <dcp/warnings.h>
28 LIBDCP_DISABLE_WARNINGS
30 LIBDCP_ENABLE_WARNINGS
35 #if BOOST_VERSION >= 106100
36 using namespace boost::placeholders;
40 TemplatesDialog::TemplatesDialog (wxWindow* parent)
41 : wxDialog (parent, wxID_ANY, _("Templates"))
43 _sizer = new wxBoxSizer (wxVERTICAL);
46 auto hs = new wxBoxSizer (wxHORIZONTAL);
47 _list = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(400, 300), wxLC_REPORT | wxLC_SINGLE_SEL);
51 ip.SetText (_("Template"));
53 _list->InsertColumn (0, ip);
55 hs->Add (_list, 1, wxEXPAND, DCPOMATIC_SIZER_GAP);
58 auto s = new wxBoxSizer (wxVERTICAL);
59 _rename = new Button (this, _("Rename..."));
60 s->Add(_rename, 0, wxTOP | wxBOTTOM | wxEXPAND, 2);
61 _remove = new Button (this, _("Remove"));
62 s->Add(_remove, 0, wxTOP | wxBOTTOM | wxEXPAND, 2);
63 hs->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
66 _sizer->Add (hs, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
68 auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
70 _sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
73 _rename->Bind (wxEVT_BUTTON, bind(&TemplatesDialog::rename_clicked, this));
74 _remove->Bind (wxEVT_BUTTON, bind(&TemplatesDialog::remove_clicked, this));
76 _list->Bind (wxEVT_LIST_ITEM_SELECTED, bind(&TemplatesDialog::selection_changed, this));
77 _list->Bind (wxEVT_LIST_ITEM_DESELECTED, bind(&TemplatesDialog::selection_changed, this));
78 _list->Bind (wxEVT_SIZE, bind(&TemplatesDialog::resized, this, _1));
79 _config_connection = Config::instance()->Changed.connect (bind(&TemplatesDialog::refresh, this));
89 TemplatesDialog::refresh ()
91 _list->DeleteAllItems ();
93 for (auto i: Config::instance()->templates()) {
95 int const n = _list->GetItemCount ();
97 _list->InsertItem (list_item);
98 _list->SetItem (n, 0, std_to_wx (i));
104 TemplatesDialog::layout ()
111 TemplatesDialog::selection_changed ()
113 int const i = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
114 _rename->Enable (i >= 0);
115 _remove->Enable (i >= 0);
120 TemplatesDialog::rename_clicked ()
122 int item = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
130 li.m_mask = wxLIST_MASK_TEXT;
133 RenameTemplateDialog dialog(this);
134 dialog.set(li.m_text);
135 if (dialog.ShowModal() != wxID_OK) {
139 if (!dialog.get().IsEmpty()) {
140 Config::instance()->rename_template(wx_to_std(li.m_text), wx_to_std(dialog.get()));
141 _list->SetItem(item, 0, dialog.get());
143 error_dialog (this, _("Template names must not be empty."));
149 TemplatesDialog::remove_clicked ()
151 int i = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
159 li.m_mask = wxLIST_MASK_TEXT;
162 Config::instance()->delete_template (wx_to_std(li.m_text));
163 _list->DeleteItem (i);
165 selection_changed ();
170 TemplatesDialog::resized (wxSizeEvent& ev)
172 _list->SetColumnWidth (0, GetSize().GetWidth());