Move the logic for Enter in a time edit to SubsEditBox

It doesn't make any sense for the time edits used elsewhere, and it made
Enter in a time edit not close dialogs.

Originally committed to SVN as r6790.
This commit is contained in:
Thomas Goyne 2012-05-15 13:40:00 +00:00
parent fc7164422c
commit d31b795e60
3 changed files with 11 additions and 11 deletions

View File

@ -134,6 +134,16 @@ void change_value(wxTextCtrl *ctrl, wxString const& value) {
ctrl->ChangeValue(value); ctrl->ChangeValue(value);
} }
void time_edit_char_hook(wxKeyEvent &event) {
// Force a modified event on Enter
if (event.GetKeyCode() == WXK_RETURN) {
TimeEdit *edit = static_cast<TimeEdit*>(event.GetEventObject());
edit->SetValue(edit->GetValue());
}
else
event.Skip();
}
} }
SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context) SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
@ -255,6 +265,7 @@ TimeEdit *SubsEditBox::MakeTimeCtrl(bool end, wxString const& tooltip, void (Sub
TimeEdit *ctrl = new TimeEdit(this, -1, c, "", wxSize(75,-1), end); TimeEdit *ctrl = new TimeEdit(this, -1, c, "", wxSize(75,-1), end);
ctrl->SetToolTip(tooltip); ctrl->SetToolTip(tooltip);
Bind(wxEVT_COMMAND_TEXT_UPDATED, handler, this, ctrl->GetId()); Bind(wxEVT_COMMAND_TEXT_UPDATED, handler, this, ctrl->GetId());
ctrl->Bind(wxEVT_CHAR_HOOK, time_edit_char_hook);
MiddleSizer->Add(ctrl, wxSizerFlags().Center()); MiddleSizer->Add(ctrl, wxSizerFlags().Center());
return ctrl; return ctrl;
} }

View File

@ -89,7 +89,6 @@ TimeEdit::TimeEdit(wxWindow* parent, wxWindowID id, agi::Context *c, const wxStr
// Other stuff // Other stuff
if (!value) SetValue(time.GetASSFormated()); if (!value) SetValue(time.GetASSFormated());
Bind(wxEVT_CHAR_HOOK, &TimeEdit::OnCharHook, this);
Bind(wxEVT_COMMAND_MENU_SELECTED, std::tr1::bind(&TimeEdit::CopyTime, this), Time_Edit_Copy); Bind(wxEVT_COMMAND_MENU_SELECTED, std::tr1::bind(&TimeEdit::CopyTime, this), Time_Edit_Copy);
Bind(wxEVT_COMMAND_MENU_SELECTED, std::tr1::bind(&TimeEdit::PasteTime, this), Time_Edit_Paste); Bind(wxEVT_COMMAND_MENU_SELECTED, std::tr1::bind(&TimeEdit::PasteTime, this), Time_Edit_Paste);
Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this); Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this);
@ -140,15 +139,6 @@ void TimeEdit::UpdateText() {
ChangeValue(time.GetASSFormated()); ChangeValue(time.GetASSFormated());
} }
void TimeEdit::OnCharHook(wxKeyEvent &event) {
// Force a modified event on Enter
// Can't be done in OnKeyDown as the SubsEditBox hotkey would grab it first
if (event.GetKeyCode() == WXK_RETURN)
SetValue(GetValue());
else
event.Skip();
}
void TimeEdit::OnKeyDown(wxKeyEvent &event) { void TimeEdit::OnKeyDown(wxKeyEvent &event) {
int key = event.GetKeyCode(); int key = event.GetKeyCode();
if (event.CmdDown()) { if (event.CmdDown()) {

View File

@ -69,7 +69,6 @@ class TimeEdit : public wxTextCtrl {
void OnContextMenu(wxContextMenuEvent &event); void OnContextMenu(wxContextMenuEvent &event);
void OnFocusLost(wxFocusEvent &evt); void OnFocusLost(wxFocusEvent &evt);
void OnInsertChanged(agi::OptionValue const& opt); void OnInsertChanged(agi::OptionValue const& opt);
void OnCharHook(wxKeyEvent &event);
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void OnModified(wxCommandEvent &event); void OnModified(wxCommandEvent &event);