#define DCPOMATIC_EDITABLE_LIST_H
#include "wx_util.h"
+#include "dcpomatic_button.h"
#include <wx/wx.h>
#include <wx/listctrl.h>
#include <boost/function.hpp>
#include <vector>
-bool always_valid ();
-
/** @param T type of things being edited.
* @param S dialog to edit a thing.
*/
std::vector<std::string> columns,
boost::function<std::vector<T> ()> get,
boost::function<void (std::vector<T>)> set,
- boost::function<bool (T)> valid,
boost::function<std::string (T, int)> column,
bool can_edit = true,
- bool title = true
+ bool title = true,
+ int column_width = 200
)
: wxPanel (parent)
, _get (get)
, _set (set)
- , _valid (valid)
, _columns (columns.size ())
, _column (column)
, _edit (0)
if (title) {
style |= wxLC_NO_HEADER;
}
- _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (columns.size() * 200, 100), style);
+ _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (columns.size() * column_width, 100), style);
for (size_t i = 0; i < columns.size(); ++i) {
wxListItem ip;
ip.SetId (i);
ip.SetText (std_to_wx (columns[i]));
- ip.SetWidth (200);
+ ip.SetWidth (column_width);
_list->InsertColumn (i, ip);
}
{
wxSizer* s = new wxBoxSizer (wxVERTICAL);
- _add = new wxButton (this, wxID_ANY, _("Add..."));
+ _add = new Button (this, _("Add..."));
s->Add (_add, 0, wxTOP | wxBOTTOM, 2);
if (can_edit) {
- _edit = new wxButton (this, wxID_ANY, _("Edit..."));
+ _edit = new Button (this, _("Edit..."));
s->Add (_edit, 0, wxTOP | wxBOTTOM, 2);
}
- _remove = new wxButton (this, wxID_ANY, _("Remove"));
+ _remove = new Button (this, _("Remove"));
s->Add (_remove, 0, wxTOP | wxBOTTOM, 2);
_sizer->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
}
S* dialog = new S (this);
if (dialog->ShowModal() == wxID_OK) {
- T const v = dialog->get ();
- if (_valid (v)) {
- add_to_control (v);
+ boost::optional<T> const v = dialog->get ();
+ if (v) {
+ add_to_control (v.get ());
std::vector<T> all = _get ();
- all.push_back (v);
+ all.push_back (v.get ());
_set (all);
}
}
S* dialog = new S (this);
dialog->set (all[item]);
if (dialog->ShowModal() == wxID_OK) {
- T const v = dialog->get ();
- if (!_valid (v)) {
+ boost::optional<T> const v = dialog->get ();
+ if (!v) {
return;
}
- all[item] = v;
+ all[item] = v.get ();
}
dialog->Destroy ();
boost::function <std::vector<T> ()> _get;
boost::function <void (std::vector<T>)> _set;
- boost::function <bool (T)> _valid;
int _columns;
boost::function<std::string (T, int)> _column;