2 Copyright (C) 2016 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 #ifndef DCPOMATIC_NAME_FORMAT_EDITOR_H
22 #define DCPOMATIC_NAME_FORMAT_EDITOR_H
24 #include "lib/compose.hpp"
25 #include <dcp/name_format.h>
27 #include <boost/foreach.hpp>
30 class NameFormatEditor
33 NameFormatEditor (wxWindow* parent, T name, dcp::NameFormat::Map titles, dcp::NameFormat::Map examples)
34 : _panel (new wxPanel (parent))
35 , _example (new wxStaticText (_panel, wxID_ANY, ""))
36 , _sizer (new wxBoxSizer (wxVERTICAL))
37 , _specification (new wxTextCtrl (_panel, wxID_ANY, ""))
39 , _examples (examples)
41 _sizer->Add (_specification, 0, wxEXPAND, DCPOMATIC_SIZER_Y_GAP);
42 _sizer->Add (_example, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
43 _panel->SetSizer (_sizer);
45 BOOST_FOREACH (char c, name.components ()) {
46 wxStaticText* t = new wxStaticText (_panel, wxID_ANY, std_to_wx (String::compose ("%%%1 %2", c, titles[c])));
48 wxFont font = t->GetFont();
49 font.SetStyle (wxFONTSTYLE_ITALIC);
50 font.SetPointSize (font.GetPointSize() - 1);
52 t->SetForegroundColour (wxColour (0, 0, 204));
55 _specification->SetValue (std_to_wx (_name.specification ()));
56 _specification->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&NameFormatEditor::changed, this));
61 wxPanel* panel () const {
69 boost::signals2::signal<void ()> Changed;
79 virtual void update_example ()
81 _name.set_specification (wx_to_std (_specification->GetValue ()));
83 wxString example = wxString::Format (_("e.g. %s"), _name.get (_examples));
85 for (size_t i = 0; i < example.Length(); ++i) {
86 if (i > 0 && (i % 40) == 0) {
89 wrapped += example[i];
92 _example->SetLabel (wrapped);
96 wxStaticText* _example;
98 wxTextCtrl* _specification;
101 dcp::NameFormat::Map _examples;