Extract some duplicated code for the margin controls
This commit is contained in:
parent
0b46fdff49
commit
fae9a5496a
2 changed files with 19 additions and 32 deletions
|
@ -134,9 +134,9 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
|
||||||
Duration = MakeTimeCtrl(_("Line duration"), TIME_DURATION);
|
Duration = MakeTimeCtrl(_("Line duration"), TIME_DURATION);
|
||||||
MiddleSizer->AddSpacer(5);
|
MiddleSizer->AddSpacer(5);
|
||||||
|
|
||||||
MarginL = MakeMarginCtrl(_("Left Margin (0 = default)"), &SubsEditBox::OnMarginLChange);
|
MarginL = MakeMarginCtrl(_("Left Margin (0 = default)"), 0, _("left margin change"));
|
||||||
MarginR = MakeMarginCtrl(_("Right Margin (0 = default)"), &SubsEditBox::OnMarginRChange);
|
MarginR = MakeMarginCtrl(_("Right Margin (0 = default)"), 1, _("right margin change"));
|
||||||
MarginV = MakeMarginCtrl(_("Vertical Margin (0 = default)"), &SubsEditBox::OnMarginVChange);
|
MarginV = MakeMarginCtrl(_("Vertical Margin (0 = default)"), 2, _("vertical margin change"));
|
||||||
MiddleSizer->AddSpacer(5);
|
MiddleSizer->AddSpacer(5);
|
||||||
|
|
||||||
// Middle-bottom controls
|
// Middle-bottom controls
|
||||||
|
@ -201,12 +201,18 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
|
||||||
SubsEditBox::~SubsEditBox() {
|
SubsEditBox::~SubsEditBox() {
|
||||||
}
|
}
|
||||||
|
|
||||||
wxTextCtrl *SubsEditBox::MakeMarginCtrl(wxString const& tooltip, void (SubsEditBox::*handler)(wxCommandEvent&)) {
|
wxTextCtrl *SubsEditBox::MakeMarginCtrl(wxString const& tooltip, int margin, wxString const& commit_msg) {
|
||||||
wxTextCtrl *ctrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(40,-1), wxTE_CENTRE | wxTE_PROCESS_ENTER, NumValidator());
|
wxTextCtrl *ctrl = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(40,-1), wxTE_CENTRE | wxTE_PROCESS_ENTER, NumValidator());
|
||||||
ctrl->SetMaxLength(4);
|
ctrl->SetMaxLength(4);
|
||||||
ctrl->SetToolTip(tooltip);
|
ctrl->SetToolTip(tooltip);
|
||||||
Bind(wxEVT_COMMAND_TEXT_UPDATED, handler, this, ctrl->GetId());
|
|
||||||
MiddleSizer->Add(ctrl, wxSizerFlags().Center());
|
MiddleSizer->Add(ctrl, wxSizerFlags().Center());
|
||||||
|
|
||||||
|
Bind(wxEVT_COMMAND_TEXT_UPDATED, [=](wxCommandEvent&) {
|
||||||
|
wxString value = ctrl->GetValue();
|
||||||
|
SetSelectedRows([&](AssDialogue *d) { d->SetMarginString(value, margin); }, commit_msg, AssFile::COMMIT_DIAG_META);
|
||||||
|
if (line) change_value(ctrl, line->GetMarginString(margin, false));
|
||||||
|
}, ctrl->GetId());
|
||||||
|
|
||||||
return ctrl;
|
return ctrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,9 +383,9 @@ void SubsEditBox::OnUndoTimer(wxTimerEvent&) {
|
||||||
commitId = -1;
|
commitId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class setter>
|
template<class setter>
|
||||||
void SubsEditBox::SetSelectedRows(setter set, T value, wxString const& desc, int type, bool amend) {
|
void SubsEditBox::SetSelectedRows(setter set, wxString const& desc, int type, bool amend) {
|
||||||
for_each(sel.begin(), sel.end(), bind(set, std::placeholders::_1, value));
|
for_each(sel.begin(), sel.end(), set);
|
||||||
|
|
||||||
file_changed_slot.Block();
|
file_changed_slot.Block();
|
||||||
commitId = c->ass->Commit(desc, type, (amend && desc == lastCommitType) ? commitId : -1, sel.size() == 1 ? *sel.begin() : 0);
|
commitId = c->ass->Commit(desc, type, (amend && desc == lastCommitType) ? commitId : -1, sel.size() == 1 ? *sel.begin() : 0);
|
||||||
|
@ -392,7 +398,7 @@ void SubsEditBox::SetSelectedRows(setter set, T value, wxString const& desc, int
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void SubsEditBox::SetSelectedRows(T AssDialogue::*field, T value, wxString const& desc, int type, bool amend) {
|
void SubsEditBox::SetSelectedRows(T AssDialogue::*field, T value, wxString const& desc, int type, bool amend) {
|
||||||
SetSelectedRows([=](AssDialogue *d, T const& v) { d->*field = v; }, value, desc, type, amend);
|
SetSelectedRows([&](AssDialogue *d) { d->*field = value; }, desc, type, amend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsEditBox::CommitText(wxString const& desc) {
|
void SubsEditBox::CommitText(wxString const& desc) {
|
||||||
|
@ -499,21 +505,6 @@ void SubsEditBox::OnLayerEnter(wxCommandEvent &) {
|
||||||
SetSelectedRows(&AssDialogue::Layer, Layer->GetValue(), _("layer change"), AssFile::COMMIT_DIAG_META);
|
SetSelectedRows(&AssDialogue::Layer, Layer->GetValue(), _("layer change"), AssFile::COMMIT_DIAG_META);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsEditBox::OnMarginLChange(wxCommandEvent &) {
|
|
||||||
SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<0>), MarginL->GetValue(), _("MarginL change"), AssFile::COMMIT_DIAG_META);
|
|
||||||
if (line) change_value(MarginL, line->GetMarginString(0, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsEditBox::OnMarginRChange(wxCommandEvent &) {
|
|
||||||
SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<1>), MarginR->GetValue(), _("MarginR change"), AssFile::COMMIT_DIAG_META);
|
|
||||||
if (line) change_value(MarginR, line->GetMarginString(1, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsEditBox::OnMarginVChange(wxCommandEvent &) {
|
|
||||||
SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<2>), MarginV->GetValue(), _("MarginV change"), AssFile::COMMIT_DIAG_META);
|
|
||||||
if (line) change_value(MarginV, line->GetMarginString(2, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SubsEditBox::OnEffectChange(wxCommandEvent &evt) {
|
void SubsEditBox::OnEffectChange(wxCommandEvent &evt) {
|
||||||
bool amend = evt.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED;
|
bool amend = evt.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED;
|
||||||
SetSelectedRows(&AssDialogue::Effect, Effect->GetValue(), _("effect change"), AssFile::COMMIT_DIAG_META, amend);
|
SetSelectedRows(&AssDialogue::Effect, Effect->GetValue(), _("effect change"), AssFile::COMMIT_DIAG_META, amend);
|
||||||
|
|
|
@ -137,7 +137,7 @@ class SubsEditBox : public wxPanel {
|
||||||
boost::container::map<AssDialogue *, std::pair<AssTime, AssTime> > initialTimes;
|
boost::container::map<AssDialogue *, std::pair<AssTime, AssTime> > initialTimes;
|
||||||
|
|
||||||
// Constructor helpers
|
// Constructor helpers
|
||||||
wxTextCtrl *MakeMarginCtrl(wxString const& tooltip, void (SubsEditBox::*handler)(wxCommandEvent&));
|
wxTextCtrl *MakeMarginCtrl(wxString const& tooltip, int margin, wxString const& commit_msg);
|
||||||
TimeEdit *MakeTimeCtrl(wxString const& tooltip, TimeField field);
|
TimeEdit *MakeTimeCtrl(wxString const& tooltip, TimeField field);
|
||||||
void MakeButton(const char *cmd_name);
|
void MakeButton(const char *cmd_name);
|
||||||
wxComboBox *MakeComboBox(wxString const& initial_text, int style, void (SubsEditBox::*handler)(wxCommandEvent&), wxString const& tooltip);
|
wxComboBox *MakeComboBox(wxString const& initial_text, int style, void (SubsEditBox::*handler)(wxCommandEvent&), wxString const& tooltip);
|
||||||
|
@ -153,9 +153,6 @@ class SubsEditBox : public wxPanel {
|
||||||
void OnStyleChange(wxCommandEvent &event);
|
void OnStyleChange(wxCommandEvent &event);
|
||||||
void OnActorChange(wxCommandEvent &event);
|
void OnActorChange(wxCommandEvent &event);
|
||||||
void OnLayerEnter(wxCommandEvent &event);
|
void OnLayerEnter(wxCommandEvent &event);
|
||||||
void OnMarginLChange(wxCommandEvent &);
|
|
||||||
void OnMarginRChange(wxCommandEvent &);
|
|
||||||
void OnMarginVChange(wxCommandEvent &);
|
|
||||||
void OnCommentChange(wxCommandEvent &);
|
void OnCommentChange(wxCommandEvent &);
|
||||||
void OnEffectChange(wxCommandEvent &);
|
void OnEffectChange(wxCommandEvent &);
|
||||||
void OnSize(wxSizeEvent &event);
|
void OnSize(wxSizeEvent &event);
|
||||||
|
@ -164,13 +161,12 @@ class SubsEditBox : public wxPanel {
|
||||||
void SetPlaceholderCtrl(wxControl *ctrl, wxString const& value);
|
void SetPlaceholderCtrl(wxControl *ctrl, wxString const& value);
|
||||||
|
|
||||||
/// @brief Set a field in each selected line to a specified value
|
/// @brief Set a field in each selected line to a specified value
|
||||||
/// @param set Callable which does the setting
|
/// @param set Callable which updates a passed line
|
||||||
/// @param value Value to pass to set
|
|
||||||
/// @param desc Undo description to use
|
/// @param desc Undo description to use
|
||||||
/// @param type Commit type to use
|
/// @param type Commit type to use
|
||||||
/// @param amend Coalesce sequences of commits of the same type
|
/// @param amend Coalesce sequences of commits of the same type
|
||||||
template<class T, class setter>
|
template<class setter>
|
||||||
void SetSelectedRows(setter set, T value, wxString const& desc, int type, bool amend = false);
|
void SetSelectedRows(setter set, wxString const& desc, int type, bool amend = false);
|
||||||
|
|
||||||
/// @brief Set a field in each selected line to a specified value
|
/// @brief Set a field in each selected line to a specified value
|
||||||
/// @param field Field to set
|
/// @param field Field to set
|
||||||
|
|
Loading…
Reference in a new issue