2 Copyright (C) 2016-2017 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/>.
21 #include "name_format_editor.h"
27 NameFormatEditor::NameFormatEditor (wxWindow* parent, dcp::NameFormat name, dcp::NameFormat::Map titles, dcp::NameFormat::Map examples, string suffix)
28 : _panel (new wxPanel (parent))
29 , _example (new wxStaticText (_panel, wxID_ANY, ""))
30 , _sizer (new wxBoxSizer (wxVERTICAL))
31 , _specification (new wxTextCtrl (_panel, wxID_ANY, ""))
33 , _examples (examples)
36 _sizer->Add (_specification, 0, wxEXPAND, DCPOMATIC_SIZER_Y_GAP);
37 if (!_examples.empty ()) {
38 _sizer->Add (_example, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
40 _panel->SetSizer (_sizer);
42 for (dcp::NameFormat::Map::const_iterator i = titles.begin(); i != titles.end(); ++i) {
43 wxStaticText* t = new wxStaticText (_panel, wxID_ANY, std_to_wx (String::compose ("%%%1 %2", i->first, i->second)));
45 wxFont font = t->GetFont();
46 font.SetStyle (wxFONTSTYLE_ITALIC);
47 font.SetPointSize (font.GetPointSize() - 1);
49 t->SetForegroundColour (wxColour (0, 0, 204));
52 _specification->SetValue (std_to_wx (_name.specification ()));
53 _specification->Bind (wxEVT_TEXT, boost::bind (&NameFormatEditor::changed, this));
59 NameFormatEditor::changed ()
66 NameFormatEditor::update_example ()
68 if (_examples.empty ()) {
72 _name.set_specification (careful_string_filter (wx_to_std (_specification->GetValue ())));
74 wxString example = wxString::Format (_("e.g. %s"), std_to_wx (_name.get (_examples, _suffix)));
76 for (size_t i = 0; i < example.Length(); ++i) {
77 if (i > 0 && (i % 40) == 0) {
80 wrapped += example[i];
83 _example->SetLabel (wrapped);