Change the Effect box to a combobox like the Actor box. Closes #1461.

This commit is contained in:
Thomas Goyne 2012-10-20 07:34:55 -07:00
parent bd3df29a1c
commit 6b3cfcebfd
2 changed files with 31 additions and 24 deletions

View file

@ -127,8 +127,9 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &SubsEditBox::OnActorChange, this, ActorBox->GetId()); Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &SubsEditBox::OnActorChange, this, ActorBox->GetId());
TopSizer->Add(ActorBox, wxSizerFlags(2).Center().Border(wxRIGHT)); TopSizer->Add(ActorBox, wxSizerFlags(2).Center().Border(wxRIGHT));
Effect = new Placeholder<wxTextCtrl>(this, _("Effect"), wxSize(80,-1), wxTE_PROCESS_ENTER, _("Effect for this line. This can be used to store extra information for karaoke scripts, or for the effects supported by the renderer.")); Effect = new Placeholder<wxComboBox>(this, _("Effect"), wxSize(80,-1), wxCB_DROPDOWN | wxTE_PROCESS_ENTER, _("Effect for this line. This can be used to store extra information for karaoke scripts, or for the effects supported by the renderer."));
Bind(wxEVT_COMMAND_TEXT_UPDATED, &SubsEditBox::OnEffectChange, this, Effect->GetId()); Bind(wxEVT_COMMAND_TEXT_UPDATED, &SubsEditBox::OnEffectChange, this, Effect->GetId());
Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &SubsEditBox::OnEffectChange, this, Effect->GetId());
TopSizer->Add(Effect, 3, wxALIGN_CENTER, 5); TopSizer->Add(Effect, 3, wxALIGN_CENTER, 5);
// Middle controls // Middle controls
@ -270,7 +271,8 @@ void SubsEditBox::OnCommit(int type) {
if (type == AssFile::COMMIT_NEW) { if (type == AssFile::COMMIT_NEW) {
/// @todo maybe preserve selection over undo? /// @todo maybe preserve selection over undo?
PopulateActorList(); PopulateList(Effect, &AssDialogue::Effect);
PopulateList(ActorBox, &AssDialogue::Actor);
TextEdit->SetSelection(0,0); TextEdit->SetSelection(0,0);
return; return;
@ -298,38 +300,41 @@ void SubsEditBox::OnCommit(int type) {
change_value(MarginL, line->GetMarginString(0,false)); change_value(MarginL, line->GetMarginString(0,false));
change_value(MarginR, line->GetMarginString(1,false)); change_value(MarginR, line->GetMarginString(1,false));
change_value(MarginV, line->GetMarginString(2,false)); change_value(MarginV, line->GetMarginString(2,false));
Effect->ChangeValue(line->Effect);
CommentBox->SetValue(line->Comment); CommentBox->SetValue(line->Comment);
StyleBox->Select(StyleBox->FindString(line->Style)); StyleBox->Select(StyleBox->FindString(line->Style));
PopulateActorList(); PopulateList(Effect, &AssDialogue::Effect);
Effect->ChangeValue(line->Effect);
Effect->SetStringSelection(line->Effect);
PopulateList(ActorBox, &AssDialogue::Actor);
ActorBox->ChangeValue(line->Actor); ActorBox->ChangeValue(line->Actor);
ActorBox->SetStringSelection(line->Actor); ActorBox->SetStringSelection(line->Actor);
} }
} }
void SubsEditBox::PopulateActorList() { void SubsEditBox::PopulateList(wxComboBox *combo, wxString AssDialogue::*field) {
wxEventBlocker blocker(this); wxEventBlocker blocker(this);
std::set<wxString> actors; std::set<wxString> values;
for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) { for (entryIter it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) {
if (AssDialogue *diag = dynamic_cast<AssDialogue*>(*it)) if (AssDialogue *diag = dynamic_cast<AssDialogue*>(*it))
actors.insert(diag->Actor); values.insert(diag->*field);
} }
actors.erase(""); values.erase("");
wxArrayString arrstr; wxArrayString arrstr;
arrstr.reserve(actors.size()); arrstr.reserve(values.size());
copy(actors.begin(), actors.end(), std::back_inserter(arrstr)); copy(values.begin(), values.end(), std::back_inserter(arrstr));
ActorBox->Freeze(); combo->Freeze();
long pos = ActorBox->GetInsertionPoint(); long pos = combo->GetInsertionPoint();
wxString value = ActorBox->GetValue(); wxString value = combo->GetValue();
ActorBox->Set(arrstr); combo->Set(arrstr);
ActorBox->ChangeValue(value); combo->ChangeValue(value);
ActorBox->SetStringSelection(value); combo->SetStringSelection(value);
ActorBox->SetInsertionPoint(pos); combo->SetInsertionPoint(pos);
ActorBox->Thaw(); combo->Thaw();
} }
void SubsEditBox::OnActiveLineChanged(AssDialogue *new_line) { void SubsEditBox::OnActiveLineChanged(AssDialogue *new_line) {
@ -503,7 +508,7 @@ void SubsEditBox::OnStyleChange(wxCommandEvent &) {
void SubsEditBox::OnActorChange(wxCommandEvent &evt) { void SubsEditBox::OnActorChange(wxCommandEvent &evt) {
bool amend = evt.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED; bool amend = evt.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED;
SetSelectedRows(&AssDialogue::Actor, ActorBox->GetValue(), _("actor change"), AssFile::COMMIT_DIAG_META, amend); SetSelectedRows(&AssDialogue::Actor, ActorBox->GetValue(), _("actor change"), AssFile::COMMIT_DIAG_META, amend);
PopulateActorList(); PopulateList(ActorBox, &AssDialogue::Actor);
} }
void SubsEditBox::OnLayerEnter(wxCommandEvent &) { void SubsEditBox::OnLayerEnter(wxCommandEvent &) {
@ -537,8 +542,10 @@ void SubsEditBox::OnMarginVChange(wxCommandEvent &) {
if (line) change_value(MarginV, line->GetMarginString(2, false)); if (line) change_value(MarginV, line->GetMarginString(2, false));
} }
void SubsEditBox::OnEffectChange(wxCommandEvent &) { void SubsEditBox::OnEffectChange(wxCommandEvent &evt) {
SetSelectedRows(&AssDialogue::Effect, Effect->GetValue(), _("effect change"), AssFile::COMMIT_DIAG_META, true); bool amend = evt.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED;
SetSelectedRows(&AssDialogue::Effect, Effect->GetValue(), _("effect change"), AssFile::COMMIT_DIAG_META, amend);
PopulateList(Effect, &AssDialogue::Effect);
} }
void SubsEditBox::OnCommentChange(wxCommandEvent &) { void SubsEditBox::OnCommentChange(wxCommandEvent &) {

View file

@ -106,7 +106,7 @@ class SubsEditBox : public wxPanel {
wxTextCtrl *MarginL; wxTextCtrl *MarginL;
wxTextCtrl *MarginR; wxTextCtrl *MarginR;
wxTextCtrl *MarginV; wxTextCtrl *MarginV;
Placeholder<wxTextCtrl> *Effect; Placeholder<wxComboBox> *Effect;
wxRadioButton *ByTime; wxRadioButton *ByTime;
wxRadioButton *ByFrame; wxRadioButton *ByFrame;
@ -192,8 +192,8 @@ class SubsEditBox : public wxPanel {
/// @param type AssFile::CommitType /// @param type AssFile::CommitType
void OnCommit(int type); void OnCommit(int type);
/// Regenerate the contents of the actor dropdown list /// Regenerate a dropdown list with the unique values of a dialogue field
void PopulateActorList(); void PopulateList(wxComboBox *combo, wxString AssDialogue::*field);
/// @brief Enable or disable frame timing mode /// @brief Enable or disable frame timing mode
void UpdateFrameTiming(agi::vfr::Framerate const& fps); void UpdateFrameTiming(agi::vfr::Framerate const& fps);