summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-08-24 16:45:34 +0100
committerCarl Hetherington <cth@carlh.net>2016-08-24 16:45:34 +0100
commit73407f943ba25e2a0df2c98b3a9a938132876e9f (patch)
tree3f50da759546b4e15bbb076bfafd8afe4509421b /src/wx
parent8e7bdee30563e9e334bc99387315124557ad0227 (diff)
Add a basic management dialogue for templates.
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/new_film_dialog.cc2
-rw-r--r--src/wx/rename_template_dialog.cc41
-rw-r--r--src/wx/rename_template_dialog.h33
-rw-r--r--src/wx/save_template_dialog.cc21
-rw-r--r--src/wx/save_template_dialog.h2
-rw-r--r--src/wx/templates_dialog.cc156
-rw-r--r--src/wx/templates_dialog.h45
-rw-r--r--src/wx/wscript2
8 files changed, 301 insertions, 1 deletions
diff --git a/src/wx/new_film_dialog.cc b/src/wx/new_film_dialog.cc
index 907b289b5..5d4581d3c 100644
--- a/src/wx/new_film_dialog.cc
+++ b/src/wx/new_film_dialog.cc
@@ -62,7 +62,7 @@ NewFilmDialog::NewFilmDialog (wxWindow* parent)
_name->SetFocus ();
_template_name->Enable (false);
- BOOST_FOREACH (string i, Config::instance()->template_names ()) {
+ BOOST_FOREACH (string i, Config::instance()->templates ()) {
_template_name->Append (std_to_wx (i));
}
diff --git a/src/wx/rename_template_dialog.cc b/src/wx/rename_template_dialog.cc
new file mode 100644
index 000000000..6651d0923
--- /dev/null
+++ b/src/wx/rename_template_dialog.cc
@@ -0,0 +1,41 @@
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "rename_template_dialog.h"
+
+RenameTemplateDialog::RenameTemplateDialog (wxWindow* parent)
+ : TableDialog (parent, _("Rename template"), 2, 1, true)
+{
+ add (_("New name"), true);
+ _name = add (new wxTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (300, -1)));
+ layout ();
+}
+
+wxString
+RenameTemplateDialog::get () const
+{
+ return _name->GetValue ();
+}
+
+void
+RenameTemplateDialog::set (wxString s)
+{
+ _name->SetValue (s);
+}
diff --git a/src/wx/rename_template_dialog.h b/src/wx/rename_template_dialog.h
new file mode 100644
index 000000000..bef9f542b
--- /dev/null
+++ b/src/wx/rename_template_dialog.h
@@ -0,0 +1,33 @@
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "table_dialog.h"
+
+class RenameTemplateDialog : public TableDialog
+{
+public:
+ RenameTemplateDialog (wxWindow* parent);
+
+ void set (wxString n);
+ wxString get () const;
+
+private:
+ wxTextCtrl* _name;
+};
diff --git a/src/wx/save_template_dialog.cc b/src/wx/save_template_dialog.cc
index eff61a256..23dc0a85a 100644
--- a/src/wx/save_template_dialog.cc
+++ b/src/wx/save_template_dialog.cc
@@ -20,6 +20,7 @@
#include "save_template_dialog.h"
#include "wx_util.h"
+#include "lib/config.h"
#include <boost/foreach.hpp>
using std::string;
@@ -31,6 +32,9 @@ SaveTemplateDialog::SaveTemplateDialog (wxWindow* parent)
_name = add (new wxTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (300, -1)));
_name->SetFocus ();
layout ();
+
+ wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
+ ok->Bind (wxEVT_COMMAND_BUTTON_CLICKED, bind (&SaveTemplateDialog::check, this, _1));
}
string
@@ -38,3 +42,20 @@ SaveTemplateDialog::name () const
{
return wx_to_std (_name->GetValue ());
}
+
+void
+SaveTemplateDialog::check (wxCommandEvent& ev)
+{
+ bool ok = true;
+
+ if (_name->GetValue().IsEmpty()) {
+ error_dialog (this, _("Template names must not be empty."));
+ ok = false;
+ } else if (Config::instance()->existing_template (wx_to_std (_name->GetValue ()))) {
+ ok = confirm_dialog (this, _("There is already a template with this name. Do you want to overwrite it?"));
+ }
+
+ if (ok) {
+ ev.Skip ();
+ }
+}
diff --git a/src/wx/save_template_dialog.h b/src/wx/save_template_dialog.h
index 8069fa2f0..5fc4300f8 100644
--- a/src/wx/save_template_dialog.h
+++ b/src/wx/save_template_dialog.h
@@ -28,5 +28,7 @@ public:
std::string name () const;
private:
+ void check (wxCommandEvent& ev);
+
wxTextCtrl* _name;
};
diff --git a/src/wx/templates_dialog.cc b/src/wx/templates_dialog.cc
new file mode 100644
index 000000000..eb0d491e0
--- /dev/null
+++ b/src/wx/templates_dialog.cc
@@ -0,0 +1,156 @@
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "templates_dialog.h"
+#include "wx_util.h"
+#include "rename_template_dialog.h"
+#include "lib/config.h"
+#include <wx/wx.h>
+#include <boost/foreach.hpp>
+
+using std::string;
+using boost::bind;
+
+TemplatesDialog::TemplatesDialog (wxWindow* parent)
+ : wxDialog (parent, wxID_ANY, _("Templates"))
+{
+ _sizer = new wxBoxSizer (wxVERTICAL);
+ SetSizer (_sizer);
+
+ wxSizer* hs = new wxBoxSizer (wxHORIZONTAL);
+ _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (200, 100), wxLC_REPORT | wxLC_SINGLE_SEL);
+
+ wxListItem ip;
+ ip.SetId (0);
+ ip.SetText (_("Template"));
+ ip.SetWidth (200);
+ _list->InsertColumn (0, ip);
+
+ hs->Add (_list, 1, wxEXPAND, DCPOMATIC_SIZER_GAP);
+
+ {
+ wxSizer* s = new wxBoxSizer (wxVERTICAL);
+ _rename = new wxButton (this, wxID_ANY, _("Rename..."));
+ s->Add (_rename, 0, wxTOP | wxBOTTOM, 2);
+ _remove = new wxButton (this, wxID_ANY, _("Remove"));
+ s->Add (_remove, 0, wxTOP | wxBOTTOM, 2);
+ hs->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
+ }
+
+ _sizer->Add (hs, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
+
+ wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
+ if (buttons) {
+ _sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
+ }
+
+ _rename->Bind (wxEVT_COMMAND_BUTTON_CLICKED, bind (&TemplatesDialog::rename_clicked, this));
+ _remove->Bind (wxEVT_COMMAND_BUTTON_CLICKED, bind (&TemplatesDialog::remove_clicked, this));
+
+ _list->Bind (wxEVT_COMMAND_LIST_ITEM_SELECTED, bind (&TemplatesDialog::selection_changed, this));
+ _list->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, bind (&TemplatesDialog::selection_changed, this));
+ _list->Bind (wxEVT_SIZE, bind (&TemplatesDialog::resized, this, _1));
+ _config_connection = Config::instance()->Changed.connect (bind (&TemplatesDialog::refresh, this));
+
+ refresh ();
+ selection_changed ();
+}
+
+void
+TemplatesDialog::refresh ()
+{
+ _list->DeleteAllItems ();
+
+ BOOST_FOREACH (string i, Config::instance()->templates()) {
+ wxListItem list_item;
+ int const n = _list->GetItemCount ();
+ list_item.SetId (n);
+ _list->InsertItem (list_item);
+ _list->SetItem (n, 0, std_to_wx (i));
+ }
+}
+
+void
+TemplatesDialog::layout ()
+{
+ _sizer->Layout ();
+}
+
+void
+TemplatesDialog::selection_changed ()
+{
+ int const i = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ _rename->Enable (i >= 0);
+ _remove->Enable (i >= 0);
+}
+
+void
+TemplatesDialog::rename_clicked ()
+{
+ int item = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (item == -1) {
+ return;
+ }
+
+ wxListItem li;
+ li.m_itemId = item;
+ li.m_col = 0;
+ li.m_mask = wxLIST_MASK_TEXT;
+ _list->GetItem (li);
+
+ RenameTemplateDialog* d = new RenameTemplateDialog (this);
+ d->set (li.m_text);
+ if (d->ShowModal() == wxID_OK) {
+ if (!d->get().IsEmpty()) {
+ Config::instance()->rename_template (wx_to_std (li.m_text), wx_to_std (d->get ()));
+ _list->SetItem (item, 0, d->get());
+ } else {
+ error_dialog (this, _("Template names must not be empty."));
+ }
+ }
+ d->Destroy ();
+}
+
+void
+TemplatesDialog::remove_clicked ()
+{
+ int i = _list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ if (i == -1) {
+ return;
+ }
+
+ wxListItem li;
+ li.m_itemId = i;
+ li.m_col = 0;
+ li.m_mask = wxLIST_MASK_TEXT;
+ _list->GetItem (li);
+
+ Config::instance()->delete_template (wx_to_std (li.m_text));
+ _list->DeleteItem (i);
+
+ selection_changed ();
+}
+
+void
+TemplatesDialog::resized (wxSizeEvent& ev)
+{
+ _list->SetColumnWidth (0, GetSize().GetWidth());
+ ev.Skip ();
+}
diff --git a/src/wx/templates_dialog.h b/src/wx/templates_dialog.h
new file mode 100644
index 000000000..039573932
--- /dev/null
+++ b/src/wx/templates_dialog.h
@@ -0,0 +1,45 @@
+/*
+ Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <wx/wx.h>
+#include <wx/listctrl.h>
+#include <boost/signals2.hpp>
+
+class TemplatesDialog : public wxDialog
+{
+public:
+ TemplatesDialog (wxWindow* parent);
+
+ void refresh ();
+ void layout ();
+
+private:
+ void selection_changed ();
+ void rename_clicked ();
+ void remove_clicked ();
+ void resized (wxSizeEvent& ev);
+
+ wxButton* _rename;
+ wxButton* _remove;
+ wxListCtrl* _list;
+ wxBoxSizer* _sizer;
+
+ boost::signals2::scoped_connection _config_connection;
+};
diff --git a/src/wx/wscript b/src/wx/wscript
index 1f9aed6b3..f89b60c40 100644
--- a/src/wx/wscript
+++ b/src/wx/wscript
@@ -74,6 +74,7 @@ sources = """
playhead_to_frame_dialog.cc
repeat_dialog.cc
report_problem_dialog.cc
+ rename_template_dialog.cc
rgba_colour_picker.cc
save_template_dialog.cc
screen_dialog.cc
@@ -85,6 +86,7 @@ sources = """
subtitle_view.cc
system_font_dialog.cc
table_dialog.cc
+ templates_dialog.cc
text_subtitle_appearance_dialog.cc
time_picker.cc
timecode.cc