More code cleaning up and fixing!

Originally committed to SVN as r109.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-22 06:08:35 +00:00
parent 0b862d1727
commit 38f3c19d64
6 changed files with 65 additions and 32 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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();
}

View File

@ -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;i<nlines;i++) {
if (IsInSelection(i,0)) {
delete (AssDialogue*)(*diagMap.at(i));
ass->Line.erase(diagMap.at(i));
deleted++;
}
}
//// Selection
//else {
// int nlines = GetRows();
// for (int i=0;i<nlines;i++) {
// if (IsInSelection(i,0)) {
// delete (AssDialogue*)(*diagMap.at(i));
// ass->Line.erase(diagMap.at(i));
// deleted++;
// }
// }
//}
// Delete lines
int size = target.Count();
for (int i=0;i<size;i++) {
delete (*diagMap.at(target[i]));
ass->Line.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);

View File

@ -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);