Missing content filename stuff in DCP filename format.
[dcpomatic.git] / src / wx / name_format_editor.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "name_format_editor.h"
22 #include "wx_util.h"
23
24 NameFormatEditor::NameFormatEditor (wxWindow* parent, dcp::NameFormat name, dcp::NameFormat::Map titles, dcp::NameFormat::Map examples)
25         : _panel (new wxPanel (parent))
26         , _example (new wxStaticText (_panel, wxID_ANY, ""))
27         , _sizer (new wxBoxSizer (wxVERTICAL))
28         , _specification (new wxTextCtrl (_panel, wxID_ANY, ""))
29         , _name (name)
30         , _examples (examples)
31 {
32         _sizer->Add (_specification, 0, wxEXPAND, DCPOMATIC_SIZER_Y_GAP);
33         _sizer->Add (_example, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
34         _panel->SetSizer (_sizer);
35
36         for (dcp::NameFormat::Map::const_iterator i = titles.begin(); i != titles.end(); ++i) {
37                 wxStaticText* t = new wxStaticText (_panel, wxID_ANY, std_to_wx (String::compose ("%%%1 %2", i->first, i->second)));
38                 _sizer->Add (t);
39                 wxFont font = t->GetFont();
40                 font.SetStyle (wxFONTSTYLE_ITALIC);
41                 font.SetPointSize (font.GetPointSize() - 1);
42                 t->SetFont (font);
43                 t->SetForegroundColour (wxColour (0, 0, 204));
44         }
45
46         _specification->SetValue (std_to_wx (_name.specification ()));
47         _specification->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&NameFormatEditor::changed, this));
48
49         update_example ();
50 }
51
52 void
53 NameFormatEditor::changed ()
54 {
55         update_example ();
56         Changed ();
57 }
58
59 void
60 NameFormatEditor::update_example ()
61 {
62         _name.set_specification (wx_to_std (_specification->GetValue ()));
63
64         wxString example = wxString::Format (_("e.g. %s"), _name.get (_examples));
65         wxString wrapped;
66         for (size_t i = 0; i < example.Length(); ++i) {
67                 if (i > 0 && (i % 40) == 0) {
68                         wrapped += "\n";
69                 }
70                 wrapped += example[i];
71         }
72
73         _example->SetLabel (wrapped);
74 }