Fix a number of odd quirks regarding how grid selection is moved after committing multiple lines, and how audio selection moves after committing. See #794 for full details. Patch by Harukalover.

closes #64, #420, #794

Originally committed to SVN as r2859.
This commit is contained in:
Karl Blomster 2009-04-26 01:02:23 +00:00
parent 76cec3ec29
commit 31aed4c1a7
6 changed files with 93 additions and 41 deletions

View file

@ -1197,6 +1197,9 @@ void AudioDisplay::CommitChanges (bool nextLine) {
if (!loaded) return; if (!loaded) return;
// Check validity // Check validity
bool textNeedsCommit = grid->GetDialogue(line_n)->Text != grid->editBox->TextEdit->GetText();
bool timeNeedsCommit = grid->GetDialogue(line_n)->Start.GetMS() != curStartMS || grid->GetDialogue(line_n)->End.GetMS() != curEndMS;
if (timeNeedsCommit || textNeedsCommit) NeedCommit = true;
bool wasKaraSplitting = false; bool wasKaraSplitting = false;
bool validCommit = true; bool validCommit = true;
if (!karaoke->enabled && !karaoke->splitting) { if (!karaoke->enabled && !karaoke->splitting) {
@ -1220,6 +1223,9 @@ void AudioDisplay::CommitChanges (bool nextLine) {
wxLogDebug(_T("AudioDisplay::CommitChanges: karaSelStart=%d karaSelEnd=%d"), karaSelStart, karaSelEnd); wxLogDebug(_T("AudioDisplay::CommitChanges: karaSelStart=%d karaSelEnd=%d"), karaSelStart, karaSelEnd);
} }
// Get selected rows
wxArrayInt sel = grid->GetSelection();
// Commit ok? // Commit ok?
if (validCommit) { if (validCommit) {
wxLogDebug(_T("AudioDisplay::CommitChanges: valid commit")); wxLogDebug(_T("AudioDisplay::CommitChanges: valid commit"));
@ -1229,25 +1235,21 @@ void AudioDisplay::CommitChanges (bool nextLine) {
// Update dialogues // Update dialogues
blockUpdate = true; blockUpdate = true;
wxArrayInt sel = grid->GetSelection();
int sels = (int)sel.Count();
bool textNeedsCommit = grid->GetDialogue(sel[0])->Text != grid->editBox->TextEdit->GetText();
AssDialogue *curDiag; AssDialogue *curDiag;
for (int i=-1;i<sels;i++) { for (size_t i=0;i<sel.GetCount();i++) {
if (i == -1) curDiag = dialogue; if (grid->IsInSelection(line_n)) curDiag = grid->GetDialogue(sel[i]);
else { else curDiag = grid->GetDialogue(line_n);
curDiag = grid->GetDialogue(sel[i]); if (timeNeedsCommit) {
if (curDiag == dialogue) continue;
}
curDiag->Start.SetMS(curStartMS); curDiag->Start.SetMS(curStartMS);
curDiag->End.SetMS(curEndMS); curDiag->End.SetMS(curEndMS);
}
if (!karaoke->enabled && textNeedsCommit) { if (!karaoke->enabled && textNeedsCommit) {
// If user was editing karaoke stuff, that should take precedence of manual changes in the editbox, // If user was editing karaoke stuff, that should take precedence of manual changes in the editbox,
// so only update from editbox when not in kara mode // so only update from editbox when not in kara mode
curDiag->Text = grid->editBox->TextEdit->GetText(); curDiag->Text = grid->editBox->TextEdit->GetText();
} }
curDiag->UpdateData(); curDiag->UpdateData();
if (!grid->IsInSelection(line_n)) break;
} }
// Update edit box // Update edit box
@ -1278,15 +1280,22 @@ void AudioDisplay::CommitChanges (bool nextLine) {
def->End.SetMS(def->End.GetMS()+Options.AsInt(_T("Timing Default Duration"))); def->End.SetMS(def->End.GetMS()+Options.AsInt(_T("Timing Default Duration")));
def->Style = grid->GetDialogue(line_n)->Style; def->Style = grid->GetDialogue(line_n)->Style;
grid->InsertLine(def,line_n,true); grid->InsertLine(def,line_n,true);
curStartMS = curEndMS;
curEndMS = curStartMS + Options.AsInt(_T("Timing Default Duration"));
}
else if (grid->GetDialogue(line_n+1)->Start.GetMS() == 0 && grid->GetDialogue(line_n+1)->End.GetMS() == 0) {
curStartMS = curEndMS;
curEndMS = curStartMS + Options.AsInt(_T("Timing Default Duration"));
}
else {
curStartMS = grid->GetDialogue(line_n+1)->Start.GetMS();
curEndMS = grid->GetDialogue(line_n+1)->End.GetMS();
} }
// Go to next // Go to next
dontReadTimes = true; dontReadTimes = true;
Next(); ChangeLine(1,sel.GetCount() > 1 ? true : false);
dontReadTimes = false; dontReadTimes = false;
curStartMS = curEndMS;
curEndMS = curStartMS + Options.AsInt(_T("Timing Default Duration"));
NeedCommit = true;
} }
Update(); Update();
@ -2208,12 +2217,15 @@ void AudioDisplay::OnKeyDown(wxKeyEvent &event) {
/////////////// ///////////////
// Change line // Change line
void AudioDisplay::ChangeLine(int delta) { void AudioDisplay::ChangeLine(int delta, bool block) {
wxLogDebug(_T("AudioDisplay::ChangeLine(delta=%d)"), delta); wxLogDebug(_T("AudioDisplay::ChangeLine(delta=%d)"), delta);
if (dialogue) { if (dialogue) {
wxLogDebug(_T("AudioDisplay::ChangeLine: has dialogue")); wxLogDebug(_T("AudioDisplay::ChangeLine: has dialogue"));
// Get next line number and make sure it's within bounds // Get next line number and make sure it's within bounds
int next = line_n+delta; int next;
if (block && grid->IsInSelection(line_n)) next = grid->GetLastSelRow()+delta;
else next = line_n+delta;
if (next == -1) next = 0; if (next == -1) next = 0;
if (next == grid->GetRows()) next = grid->GetRows() - 1; if (next == grid->GetRows()) next = grid->GetRows() - 1;
wxLogDebug(_T("AudioDisplay::ChangeLine: next=%i"), next); wxLogDebug(_T("AudioDisplay::ChangeLine: next=%i"), next);

View file

@ -161,7 +161,7 @@ public:
void UpdateScrollbar(); void UpdateScrollbar();
void SetDialogue(SubtitlesGrid *_grid=NULL,AssDialogue *diag=NULL,int n=-1); void SetDialogue(SubtitlesGrid *_grid=NULL,AssDialogue *diag=NULL,int n=-1);
void MakeDialogueVisible(bool force=false); void MakeDialogueVisible(bool force=false);
void ChangeLine(int delta); void ChangeLine(int delta, bool block=false);
void Next(bool play=true); void Next(bool play=true);
void Prev(bool play=true); void Prev(bool play=true);

View file

@ -140,6 +140,9 @@ void BaseGrid::EndBatch() {
////////////////////// //////////////////////
// Makes cell visible // Makes cell visible
void BaseGrid::MakeCellVisible(int row, int col,bool center) { void BaseGrid::MakeCellVisible(int row, int col,bool center) {
// Update last row selection
lastRow = row;
// Get size // Get size
int w = 0; int w = 0;
int h = 0; int h = 0;
@ -256,6 +259,17 @@ int BaseGrid::GetFirstSelRow() {
} }
/////////////////////////////////////////////////////
// Gets last selected row from first block selection
int BaseGrid::GetLastSelRow() {
int frow = GetFirstSelRow();
while (IsInSelection(frow)) {
frow++;
}
return frow-1;
}
////////////////////////// //////////////////////////
// Gets all selected rows // Gets all selected rows
wxArrayInt BaseGrid::GetSelection(bool *cont) { wxArrayInt BaseGrid::GetSelection(bool *cont) {

View file

@ -103,6 +103,7 @@ public:
bool IsDisplayed(AssDialogue *line); bool IsDisplayed(AssDialogue *line);
int GetNumberSelection(); int GetNumberSelection();
int GetFirstSelRow(); int GetFirstSelRow();
int GetLastSelRow();
void SelectVisible(); void SelectVisible();
wxArrayInt GetSelection(bool *continuous=NULL); wxArrayInt GetSelection(bool *continuous=NULL);

View file

@ -1638,9 +1638,7 @@ void FrameMain::OnEditBoxCommit(wxCommandEvent &event) {
// Is the text edit // Is the text edit
if (focus == EditBox->TextEdit) { if (focus == EditBox->TextEdit) {
EditBox->CommitText(); EditBox->Commit(true);
SubsBox->ass->FlagAsModified(_("editing"));
SubsBox->CommitChanges();
} }
// Other window // Other window

View file

@ -342,8 +342,6 @@ void SubsEditBox::SetToLine(int n,bool weak) {
enabled = true; enabled = true;
if (n != linen) { if (n != linen) {
linen = n; linen = n;
StartTime->Update();
EndTime->Update();
Duration->Update(); Duration->Update();
} }
} }
@ -714,7 +712,8 @@ void SubsEditBox::CommitTimes(bool start,bool end,bool fromStart,bool commit) {
// Update lines // Update lines
for (int i=0;i<n;i++) { for (int i=0;i<n;i++) {
cur = grid->GetDialogue(sel[i]); if (grid->IsInSelection(linen)) cur = grid->GetDialogue(sel[i]);
else cur = grid->GetDialogue(linen);
if (cur) { if (cur) {
// Set times // Set times
if (start) cur->Start = StartTime->time; if (start) cur->Start = StartTime->time;
@ -725,11 +724,15 @@ void SubsEditBox::CommitTimes(bool start,bool end,bool fromStart,bool commit) {
if (fromStart) cur->End = cur->Start; if (fromStart) cur->End = cur->Start;
else cur->Start = cur->End; else cur->Start = cur->End;
} }
if (!grid->IsInSelection(linen)) break;
} }
} }
// Commit // Commit
if (commit) { if (commit) {
StartTime->Update();
EndTime->Update();
Duration->Update();
grid->ass->FlagAsModified(_("modify times")); grid->ass->FlagAsModified(_("modify times"));
grid->CommitChanges(); grid->CommitChanges();
audio->SetDialogue(grid,grid->GetDialogue(sel[0]),sel[0]); audio->SetDialogue(grid,grid->GetDialogue(sel[0]),sel[0]);
@ -884,15 +887,43 @@ void SubsEditBox::DoKeyPress(wxKeyEvent &event) {
////////// //////////
// Commit // Commit
void SubsEditBox::Commit(bool stay) { void SubsEditBox::Commit(bool stay) {
// Record pre-commit data
wxString oldText = grid->GetDialogue(linen)->Text;
int oldStart = grid->GetDialogue(linen)->Start.GetMS();
int oldEnd = grid->GetDialogue(linen)->End.GetMS();
// Update line // Update line
CommitText(); CommitText();
// Next line if control is not held down // Change text/time if needed for all selected lines
bool updated = false; bool updated = false;
if (!stay) { bool textNeedsCommit = grid->GetDialogue(linen)->Text != oldText;
AssDialogue *cur = grid->GetDialogue(linen); bool timeNeedsCommit = grid->GetDialogue(linen)->Start.GetMS() != oldStart || grid->GetDialogue(linen)->End.GetMS() != oldEnd;
int nrows = grid->GetRows(); int nrows = grid->GetRows();
int next = linen+1; wxArrayInt sel = grid->GetSelection();
if (grid->IsInSelection(linen)) {
for (size_t i=0;i<sel.GetCount();i++) {
if (textNeedsCommit) grid->GetDialogue(sel[i])->Text = TextEdit->GetText();
if (timeNeedsCommit) {
grid->GetDialogue(sel[i])->Start.SetMS(StartTime->time.GetMS());
grid->GetDialogue(sel[i])->End.SetMS(EndTime->time.GetMS());
}
}
}
// Update file
if (!updated && textNeedsCommit) {
grid->ass->FlagAsModified(_("editing"));
grid->CommitChanges();
}
else if (!updated && (StartTime->HasBeenModified() || EndTime->HasBeenModified()))
CommitTimes(StartTime->HasBeenModified(),EndTime->HasBeenModified(),StartTime->HasBeenModified(),true);
// Get next line if ctrl was not held down
if (!stay) {
int next;
if (!grid->IsInSelection(linen)) next = linen+1;
else next = grid->GetLastSelRow()+1;
AssDialogue *cur = grid->GetDialogue(next-1);
if (next >= nrows) { if (next >= nrows) {
AssDialogue *newline = new AssDialogue; AssDialogue *newline = new AssDialogue;
newline->Start = cur->End; newline->Start = cur->End;
@ -907,12 +938,6 @@ void SubsEditBox::Commit(bool stay) {
SetToLine(next); SetToLine(next);
if (next >= nrows) return; if (next >= nrows) return;
} }
// Update file
if (!updated) {
grid->ass->FlagAsModified(_("editing"));
grid->CommitChanges();
}
} }
@ -927,12 +952,14 @@ void SubsEditBox::CommitText(bool weak) {
cur->Text = TextEdit->GetText(); cur->Text = TextEdit->GetText();
// Update times // Update times
if (grid->IsInSelection(linen)) {
cur->Start = StartTime->time; cur->Start = StartTime->time;
cur->End = EndTime->time; cur->End = EndTime->time;
if (cur->Start > cur->End) cur->End = cur->Start; if (cur->Start > cur->End) {
StartTime->Update(); cur->End = cur->Start;
EndTime->Update(); EndTime->SetTime(cur->End.GetMS());
Duration->Update(); }
}
// Update audio // Update audio
if (!weak) { if (!weak) {