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 barToEnable = drawPerScreen < rows+2;
bool barEnabled = scrollBar->IsEnabled(); bool barEnabled = scrollBar->IsEnabled();
// Set yPos
yPos = MID(0,yPos,rows - drawPerScreen);
// Set size // Set size
scrollBar->Freeze(); scrollBar->Freeze();
scrollBar->GetSize(&sw,&sh); scrollBar->GetSize(&sw,&sh);
@ -1014,3 +1017,21 @@ void BaseGrid::SetByFrame (bool state) {
Refresh(false); 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(); void UpdateMaps();
int GetRows() const; int GetRows() const;
int GetNumberRows() const { return GetRows(); } wxArrayInt GetRangeArray(int n1,int n2);
void MakeCellVisible(int row, int col,bool center=true); void MakeCellVisible(int row, int col,bool center=true);
AssDialogue *GetDialogue(int n); AssDialogue *GetDialogue(int n);

View file

@ -218,7 +218,7 @@ void DialogSpellCheck::LineSetUp(){
if ((lnList.GetCount() == 0) || (alt == true)) { if ((lnList.GetCount() == 0) || (alt == true)) {
start = 0; start = 0;
end = grid->GetNumberRows() - 1; end = grid->GetRows() - 1;
curLineNumber = 0; curLineNumber = 0;
current_line = grid->GetDialogue(curLineNumber); current_line = grid->GetDialogue(curLineNumber);
return; return;

View file

@ -206,7 +206,7 @@ void FrameMain::OnVideoTrackSplitLine(wxCommandEvent &event) {
curline->Movement = 0; curline->Movement = 0;
// Remove this line // Remove this line
SubsBox->DeleteLines( EditBox->linen, EditBox->linen, false ); SubsBox->DeleteLines(SubsBox->GetRangeArray(EditBox->linen, EditBox->linen));
videoBox->videoDisplay->RefreshVideo(); videoBox->videoDisplay->RefreshVideo();
} }

View file

@ -239,7 +239,7 @@ void SubtitlesGrid::OnKeyDown(wxKeyEvent &event) {
// Delete // Delete
if (Hotkeys.IsPressed(_T("Grid delete rows"))) { if (Hotkeys.IsPressed(_T("Grid delete rows"))) {
DeleteLines(-1,-1,true); DeleteLines(GetSelection());
return; return;
} }
@ -587,7 +587,7 @@ void SubtitlesGrid::OnPasteLines (wxCommandEvent &WXUNUSED(&event)) {
/////////////////////////////// ///////////////////////////////
// Copy selection to clipboard // Copy selection to clipboard
void SubtitlesGrid::OnDeleteLines (wxCommandEvent &WXUNUSED(&event)) { void SubtitlesGrid::OnDeleteLines (wxCommandEvent &WXUNUSED(&event)) {
DeleteLines(-1,-1,true); DeleteLines(GetSelection());
} }
@ -639,7 +639,7 @@ void SubtitlesGrid::On1122Recombine(wxCommandEvent &event) {
n3->UpdateData(); n3->UpdateData();
// Delete middle // 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 // Update mapping
diagMap[n1] = src1; diagMap[n1] = src1;
diagPtrMap[n1] = (AssDialogue*) *src1;
diagMap[n2] = src2; diagMap[n2] = src2;
diagPtrMap[n2] = (AssDialogue*) *src2;
ass->FlagAsModified(); ass->FlagAsModified();
CommitChanges(); CommitChanges();
} }
@ -840,6 +842,7 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
//InsertRows(n); //InsertRows(n);
//SetRowToLine(n,line); //SetRowToLine(n,line);
diagMap.insert(diagMap.begin() + n,newIter); diagMap.insert(diagMap.begin() + n,newIter);
diagPtrMap.insert(diagPtrMap.begin() + n,(AssDialogue*)(*newIter));
selMap.insert(selMap.begin() + n,false); selMap.insert(selMap.begin() + n,false);
// Update // Update
@ -879,7 +882,7 @@ void SubtitlesGrid::CopyLines() {
// Cut to clipboard // Cut to clipboard
void SubtitlesGrid::CutLines() { void SubtitlesGrid::CutLines() {
CopyLines(); CopyLines();
DeleteLines(-1,-1,true); DeleteLines(GetSelection());
} }
@ -918,6 +921,7 @@ void SubtitlesGrid::PasteLines(int n) {
if (inserted > 0) { if (inserted > 0) {
// Commit // Commit
UpdateMaps();
ass->FlagAsModified(); ass->FlagAsModified();
CommitChanges(); CommitChanges();
@ -934,33 +938,41 @@ void SubtitlesGrid::PasteLines(int n) {
///////////////////////// /////////////////////////
// Delete selected lines // Delete selected lines
void SubtitlesGrid::DeleteLines(int n1,int n2,bool sel) { void SubtitlesGrid::DeleteLines(wxArrayInt target) {
// Check if it's wiping file // Check if it's wiping file
int deleted = 0; int deleted = 0;
// Range //// Range
if (!sel) { //if (!sel) {
// Deallocate lines // // Deallocate lines
for (int i=n1;i<=n2;i++) { // for (int i=n1;i<=n2;i++) {
delete GetDialogue(i); // delete GetDialogue(i);
} // }
// Remove from AssFile // // Remove from AssFile
if (n1 != n2) ass->Line.erase(diagMap.at(n1),++diagMap.at(n2)); // if (n1 != n2) ass->Line.erase(diagMap.at(n1),++diagMap.at(n2));
else ass->Line.erase(diagMap.at(n1)); // else ass->Line.erase(diagMap.at(n1));
deleted = n2-n1+1; // deleted = n2-n1+1;
} //}
// Selection //// Selection
else { //else {
int nlines = GetRows(); // int nlines = GetRows();
for (int i=0;i<nlines;i++) { // for (int i=0;i<nlines;i++) {
if (IsInSelection(i,0)) { // if (IsInSelection(i,0)) {
delete (AssDialogue*)(*diagMap.at(i)); // delete (AssDialogue*)(*diagMap.at(i));
ass->Line.erase(diagMap.at(i)); // ass->Line.erase(diagMap.at(i));
deleted++; // 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 // Add default line if file was wiped
@ -1010,7 +1022,7 @@ void SubtitlesGrid::JoinLines(int n1,int n2,bool concat) {
cur->UpdateData(); cur->UpdateData();
// Delete remaining lines (this will auto commit) // Delete remaining lines (this will auto commit)
DeleteLines(n1+1,n2,false); DeleteLines(GetRangeArray(n1+1,n2));
// Select new line // Select new line
editBox->SetToLine(n1); editBox->SetToLine(n1);
@ -1094,7 +1106,7 @@ void SubtitlesGrid::JoinAsKaraoke(int n1,int n2) {
cur->UpdateData(); cur->UpdateData();
// Delete remaining lines (this will auto commit) // Delete remaining lines (this will auto commit)
DeleteLines(n1+1,n2,false); DeleteLines(GetRangeArray(n1+1,n2));
// Select new line // Select new line
editBox->SetToLine(n1); editBox->SetToLine(n1);

View file

@ -114,7 +114,7 @@ public:
void SwapLines(int n1,int n2); void SwapLines(int n1,int n2);
void DuplicateLines(int n1,int n2,bool nextFrame=false); 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 JoinLines(int n1,int n2,bool concat=true);
void JoinAsKaraoke(int n1,int n2); void JoinAsKaraoke(int n1,int n2);
void AdjoinLines(int n1,int n2,bool setStart); void AdjoinLines(int n1,int n2,bool setStart);