Allow using , as the separator in time edit controls

This commit is contained in:
Thomas Goyne 2013-10-08 07:19:56 -07:00
parent 7a6fd4bb1e
commit 6694baf3f0
2 changed files with 7 additions and 19 deletions

View file

@ -40,12 +40,12 @@ AssTime::AssTime(std::string const& text)
{ {
int after_decimal = -1; int after_decimal = -1;
int current = 0; int current = 0;
for (char c : text | boost::adaptors::filtered(boost::is_any_of(":0123456789."))) { for (char c : text | boost::adaptors::filtered(boost::is_any_of(",.0123456789:"))) {
if (c == ':') { if (c == ':') {
time = time * 60 + current; time = time * 60 + current;
current = 0; current = 0;
} }
else if (c == '.') { else if (c == '.' || c == ',') {
time = (time * 60 + current) * 1000; time = (time * 60 + current) * 1000;
current = 0; current = 0;
after_decimal = 100; after_decimal = 100;

View file

@ -67,20 +67,8 @@ TimeEdit::TimeEdit(wxWindow* parent, wxWindowID id, agi::Context *c, const std::
{ {
// Set validator // Set validator
wxTextValidator val(wxFILTER_INCLUDE_CHAR_LIST); wxTextValidator val(wxFILTER_INCLUDE_CHAR_LIST);
wxArrayString includes; wxString includes[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ".", ":", ","};
includes.Add("0"); val.SetIncludes(wxArrayString(countof(includes), includes));
includes.Add("1");
includes.Add("2");
includes.Add("3");
includes.Add("4");
includes.Add("5");
includes.Add("6");
includes.Add("7");
includes.Add("8");
includes.Add("9");
includes.Add(".");
includes.Add(":");
val.SetIncludes(includes);
SetValidator(val); SetValidator(val);
// Other stuff // Other stuff
@ -162,7 +150,7 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) {
event.Skip(); event.Skip();
if (byFrame) return; if (byFrame) return;
if (insert) return; if (insert) return;
if ((key < '0' || key > '9') && key != WXK_BACK && key != WXK_DELETE && key != ';' && key != '.') return; if ((key < '0' || key > '9') && key != WXK_BACK && key != WXK_DELETE && key != ';' && key != '.' && key != ',') return;
event.Skip(false); event.Skip(false);
@ -182,11 +170,11 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) {
if (start >= (long)text.size()) return; if (start >= (long)text.size()) return;
// If the cursor is at punctuation, move it forward to the next digit // If the cursor is at punctuation, move it forward to the next digit
if (text[start] == ':' || text[start] == '.') if (text[start] == ':' || text[start] == '.' || text[start] == ',')
++start; ++start;
// : and . hop over punctuation but never insert anything // : and . hop over punctuation but never insert anything
if (key == ';' || key == '.') { if (key == ';' || key == '.' || key == ',') {
SetInsertionPoint(start); SetInsertionPoint(start);
return; return;
} }