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)
34 : _panel (new wxPanel (parent))
35 , _example (new wxStaticText (_panel, wxID_ANY, ""))
36 , _sizer (new wxBoxSizer (wxVERTICAL))
37 , _specification (new wxTextCtrl (_panel, wxID_ANY, ""))
40 _sizer->Add (_specification, 0, wxEXPAND, DCPOMATIC_SIZER_Y_GAP);
41 _sizer->Add (_example, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
42 _panel->SetSizer (_sizer);
44 BOOST_FOREACH (dcp::NameFormat::Component c, name.components ()) {
45 wxStaticText* t = new wxStaticText (_panel, wxID_ANY, std_to_wx (String::compose ("%%%1 %2", c.placeholder, c.title)));
47 wxFont font = t->GetFont();
48 font.SetStyle (wxFONTSTYLE_ITALIC);
49 font.SetPointSize (font.GetPointSize() - 1);
51 t->SetForegroundColour (wxColour (0, 0, 204));
54 _specification->SetValue (std_to_wx (_name.specification ()));
55 _specification->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&NameFormatEditor::changed, this));
60 wxPanel* panel () const
65 void set_example (dcp::NameFormat::Map v) {
74 boost::signals2::signal<void ()> Changed;
84 virtual void update_example ()
86 _name.set_specification (wx_to_std (_specification->GetValue ()));
88 wxString example = wxString::Format (_("e.g. %s"), _name.get (_example_values));
90 for (size_t i = 0; i < example.Length(); ++i) {
91 if (i > 0 && (i % 30) == 0) {
94 wrapped += example[i];
97 _example->SetLabel (wrapped);
101 wxStaticText* _example;
103 wxTextCtrl* _specification;
106 dcp::NameFormat::Map _example_values;