From 38f3c19d64e255e82a4b93ce6f667d162ba7c4df Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Wed, 22 Feb 2006 06:08:35 +0000 Subject: [PATCH] More code cleaning up and fixing! Originally committed to SVN as r109. --- core/base_grid.cpp | 21 ++++++++++ core/base_grid.h | 2 +- core/dialog_spellcheck.cpp | 2 +- core/fextracker_main_events.cpp | 2 +- core/subs_grid.cpp | 68 +++++++++++++++++++-------------- core/subs_grid.h | 2 +- 6 files changed, 65 insertions(+), 32 deletions(-) diff --git a/core/base_grid.cpp b/core/base_grid.cpp index 9a2db8b32..aa582ee27 100644 --- a/core/base_grid.cpp +++ b/core/base_grid.cpp @@ -704,6 +704,9 @@ void BaseGrid::AdjustScrollbar() { bool barToEnable = drawPerScreen < rows+2; bool barEnabled = scrollBar->IsEnabled(); + // Set yPos + yPos = MID(0,yPos,rows - drawPerScreen); + // Set size scrollBar->Freeze(); scrollBar->GetSize(&sw,&sh); @@ -1014,3 +1017,21 @@ void BaseGrid::SetByFrame (bool state) { Refresh(false); } + +/////////////////////////////////////////////// +// Generates an array covering inclusive range +wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) { + // Swap if in wrong order + if (n2 < n1) { + int aux = n1; + n1 = n2; + n2 = aux; + } + + // Generate array + wxArrayInt target; + for (int i=n1;i<=n2;i++) { + target.Add(i); + } + return target; +} diff --git a/core/base_grid.h b/core/base_grid.h index 291825c20..c210a2ccd 100644 --- a/core/base_grid.h +++ b/core/base_grid.h @@ -110,7 +110,7 @@ public: void UpdateMaps(); int GetRows() const; - int GetNumberRows() const { return GetRows(); } + wxArrayInt GetRangeArray(int n1,int n2); void MakeCellVisible(int row, int col,bool center=true); AssDialogue *GetDialogue(int n); diff --git a/core/dialog_spellcheck.cpp b/core/dialog_spellcheck.cpp index 1f0c5a67e..b0eb41d39 100644 --- a/core/dialog_spellcheck.cpp +++ b/core/dialog_spellcheck.cpp @@ -218,7 +218,7 @@ void DialogSpellCheck::LineSetUp(){ if ((lnList.GetCount() == 0) || (alt == true)) { start = 0; - end = grid->GetNumberRows() - 1; + end = grid->GetRows() - 1; curLineNumber = 0; current_line = grid->GetDialogue(curLineNumber); return; diff --git a/core/fextracker_main_events.cpp b/core/fextracker_main_events.cpp index 13e47dba8..37849301d 100644 --- a/core/fextracker_main_events.cpp +++ b/core/fextracker_main_events.cpp @@ -206,7 +206,7 @@ void FrameMain::OnVideoTrackSplitLine(wxCommandEvent &event) { curline->Movement = 0; // Remove this line - SubsBox->DeleteLines( EditBox->linen, EditBox->linen, false ); + SubsBox->DeleteLines(SubsBox->GetRangeArray(EditBox->linen, EditBox->linen)); videoBox->videoDisplay->RefreshVideo(); } diff --git a/core/subs_grid.cpp b/core/subs_grid.cpp index 516d208d2..3eaa10554 100644 --- a/core/subs_grid.cpp +++ b/core/subs_grid.cpp @@ -239,7 +239,7 @@ void SubtitlesGrid::OnKeyDown(wxKeyEvent &event) { // Delete if (Hotkeys.IsPressed(_T("Grid delete rows"))) { - DeleteLines(-1,-1,true); + DeleteLines(GetSelection()); return; } @@ -587,7 +587,7 @@ void SubtitlesGrid::OnPasteLines (wxCommandEvent &WXUNUSED(&event)) { /////////////////////////////// // Copy selection to clipboard void SubtitlesGrid::OnDeleteLines (wxCommandEvent &WXUNUSED(&event)) { - DeleteLines(-1,-1,true); + DeleteLines(GetSelection()); } @@ -639,7 +639,7 @@ void SubtitlesGrid::On1122Recombine(wxCommandEvent &event) { n3->UpdateData(); // Delete middle - DeleteLines(n+1,n+1,false); + DeleteLines(GetRangeArray(n+1,n+1)); } @@ -818,7 +818,9 @@ void SubtitlesGrid::SwapLines(int n1,int n2) { // Update mapping diagMap[n1] = src1; + diagPtrMap[n1] = (AssDialogue*) *src1; diagMap[n2] = src2; + diagPtrMap[n2] = (AssDialogue*) *src2; ass->FlagAsModified(); CommitChanges(); } @@ -840,6 +842,7 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) { //InsertRows(n); //SetRowToLine(n,line); diagMap.insert(diagMap.begin() + n,newIter); + diagPtrMap.insert(diagPtrMap.begin() + n,(AssDialogue*)(*newIter)); selMap.insert(selMap.begin() + n,false); // Update @@ -879,7 +882,7 @@ void SubtitlesGrid::CopyLines() { // Cut to clipboard void SubtitlesGrid::CutLines() { CopyLines(); - DeleteLines(-1,-1,true); + DeleteLines(GetSelection()); } @@ -918,6 +921,7 @@ void SubtitlesGrid::PasteLines(int n) { if (inserted > 0) { // Commit + UpdateMaps(); ass->FlagAsModified(); CommitChanges(); @@ -934,33 +938,41 @@ void SubtitlesGrid::PasteLines(int n) { ///////////////////////// // Delete selected lines -void SubtitlesGrid::DeleteLines(int n1,int n2,bool sel) { +void SubtitlesGrid::DeleteLines(wxArrayInt target) { // Check if it's wiping file int deleted = 0; - // Range - if (!sel) { - // Deallocate lines - for (int i=n1;i<=n2;i++) { - delete GetDialogue(i); - } + //// Range + //if (!sel) { + // // Deallocate lines + // for (int i=n1;i<=n2;i++) { + // delete GetDialogue(i); + // } - // Remove from AssFile - if (n1 != n2) ass->Line.erase(diagMap.at(n1),++diagMap.at(n2)); - else ass->Line.erase(diagMap.at(n1)); - deleted = n2-n1+1; - } + // // Remove from AssFile + // if (n1 != n2) ass->Line.erase(diagMap.at(n1),++diagMap.at(n2)); + // else ass->Line.erase(diagMap.at(n1)); + // deleted = n2-n1+1; + //} - // Selection - else { - int nlines = GetRows(); - for (int i=0;iLine.erase(diagMap.at(i)); - deleted++; - } - } + //// Selection + //else { + // int nlines = GetRows(); + // for (int i=0;iLine.erase(diagMap.at(i)); + // deleted++; + // } + // } + //} + + // Delete lines + int size = target.Count(); + for (int i=0;iLine.erase(diagMap.at(target[i])); + deleted++; } // Add default line if file was wiped @@ -1010,7 +1022,7 @@ void SubtitlesGrid::JoinLines(int n1,int n2,bool concat) { cur->UpdateData(); // Delete remaining lines (this will auto commit) - DeleteLines(n1+1,n2,false); + DeleteLines(GetRangeArray(n1+1,n2)); // Select new line editBox->SetToLine(n1); @@ -1094,7 +1106,7 @@ void SubtitlesGrid::JoinAsKaraoke(int n1,int n2) { cur->UpdateData(); // Delete remaining lines (this will auto commit) - DeleteLines(n1+1,n2,false); + DeleteLines(GetRangeArray(n1+1,n2)); // Select new line editBox->SetToLine(n1); diff --git a/core/subs_grid.h b/core/subs_grid.h index fbdf18354..00e7c3338 100644 --- a/core/subs_grid.h +++ b/core/subs_grid.h @@ -114,7 +114,7 @@ public: void SwapLines(int n1,int n2); void DuplicateLines(int n1,int n2,bool nextFrame=false); - void DeleteLines(int n1,int n2,bool sel); + void DeleteLines(wxArrayInt lines); void JoinLines(int n1,int n2,bool concat=true); void JoinAsKaraoke(int n1,int n2); void AdjoinLines(int n1,int n2,bool setStart);