A lot more code clean-up

Originally committed to SVN as r110.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-22 06:49:20 +00:00
parent 38f3c19d64
commit 53d40024df
6 changed files with 66 additions and 238 deletions

View File

@ -252,7 +252,7 @@ wxArrayInt BaseGrid::GetSelection(bool *cont) {
// Scan // Scan
for (int i=0;i<nrows;i++) { for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) { if (selMap[i]) {
selections.Add(i); selections.Add(i);
if (last != -1 && i != last+1) continuous = false; if (last != -1 && i != last+1) continuous = false;
last = i; last = i;

View File

@ -956,11 +956,11 @@ void FrameMain::OnCloseWindow (wxCloseEvent &event) {
////////////////// //////////////////
// Cut/copy/paste // Cut/copy/paste
void FrameMain::OnCut (wxCommandEvent &event) { void FrameMain::OnCut (wxCommandEvent &event) {
SubsBox->CutLines(); SubsBox->CutLines(SubsBox->GetSelection());
} }
void FrameMain::OnCopy (wxCommandEvent &event) { void FrameMain::OnCopy (wxCommandEvent &event) {
SubsBox->CopyLines(); SubsBox->CopyLines(SubsBox->GetSelection());
} }
void FrameMain::OnPaste (wxCommandEvent &event) { void FrameMain::OnPaste (wxCommandEvent &event) {

View File

@ -99,8 +99,6 @@ SubtitlesGrid::SubtitlesGrid(FrameMain* parentFr, wxWindow *parent, wxWindowID i
////////////// //////////////
// Destructor // Destructor
SubtitlesGrid::~SubtitlesGrid() { SubtitlesGrid::~SubtitlesGrid() {
wxRemoveFile(tempfile);
tempfile = _T("");
} }
@ -267,178 +265,61 @@ void SubtitlesGrid::OnKeyDown(wxKeyEvent &event) {
/////////////////////// ///////////////////////
// Duplicate selection // Duplicate selection
void SubtitlesGrid::OnDuplicate (wxCommandEvent &WXUNUSED(&event)) { void SubtitlesGrid::OnDuplicate (wxCommandEvent &WXUNUSED(&event)) {
int n1 = -1; wxArrayInt sels = GetSelection();
int n2 = -1; DuplicateLines(sels.front(),sels.back());
bool gotfirst = false;
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!gotfirst) {
n1 = i;
gotfirst = true;
}
else n2 = i;
}
}
if (n1 == -1) return;
if (n2 == -1) n2 = n1;
DuplicateLines(n1,n2);
} }
////////////////////////////////////////////// //////////////////////////////////////////////
// Duplicate selection and shift by one frame // Duplicate selection and shift by one frame
void SubtitlesGrid::OnDuplicateNextFrame (wxCommandEvent &WXUNUSED(&event)) { void SubtitlesGrid::OnDuplicateNextFrame (wxCommandEvent &WXUNUSED(&event)) {
int n1 = -1; wxArrayInt sels = GetSelection();
int n2 = -1; DuplicateLines(sels.front(),sels.back(),true);
bool gotfirst = false;
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!gotfirst) {
n1 = i;
gotfirst = true;
}
else n2 = i;
}
}
// Duplicate
if (n1 == -1) return;
if (n2 == -1) n2 = n1;
DuplicateLines(n1,n2,true);
} }
///////////// /////////////
// Call swap // Call swap
void SubtitlesGrid::OnSwap (wxCommandEvent &event) { void SubtitlesGrid::OnSwap (wxCommandEvent &event) {
int n1,n2; wxArrayInt sels = GetSelection();
int n_found = 0; SwapLines(sels.front(),sels.back());
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (n_found == 0) n1 = i;
else if (n_found == 1) n2 = i;
else throw _T("Too many lines found!");
n_found++;
}
}
SwapLines(n1,n2);
} }
/////////////////////////// ///////////////////////////
// Call join (concatenate) // Call join (concatenate)
void SubtitlesGrid::OnJoinConcat (wxCommandEvent &event) { void SubtitlesGrid::OnJoinConcat (wxCommandEvent &event) {
int n1 = -1; wxArrayInt sels = GetSelection();
int n2 = -1; JoinLines(sels.front(),sels.back(),true);
bool gotfirst = false;
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!gotfirst) {
n1 = i;
gotfirst = true;
}
else n2 = i;
}
}
if (n1 == -1) return;
if (n2 == -1) n2 = n1;
JoinLines(n1,n2,true);
} }
/////////////////////// ///////////////////////
// Call join (replace) // Call join (replace)
void SubtitlesGrid::OnJoinReplace (wxCommandEvent &event) { void SubtitlesGrid::OnJoinReplace (wxCommandEvent &event) {
int n1 = -1; wxArrayInt sels = GetSelection();
int n2 = -1; JoinLines(sels.front(),sels.back(),false);
bool gotfirst = false;
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!gotfirst) {
n1 = i;
gotfirst = true;
}
else n2 = i;
}
}
if (n1 == -1) return;
if (n2 == -1) n2 = n1;
JoinLines(n1,n2,false);
} }
//////////////// ////////////////
// Adjoin lines // Adjoin lines
void SubtitlesGrid::OnAdjoin (wxCommandEvent &event) { void SubtitlesGrid::OnAdjoin (wxCommandEvent &event) {
int n1 = -1; wxArrayInt sels = GetSelection();
int n2 = -1; AdjoinLines(sels.front(),sels.back(),true);
bool gotfirst = false;
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!gotfirst) {
n1 = i;
gotfirst = true;
}
else n2 = i;
}
}
if (n1 == -1) return;
if (n2 == -1) n2 = n1;
AdjoinLines(n1,n2,true);
} }
void SubtitlesGrid::OnAdjoin2 (wxCommandEvent &event) { void SubtitlesGrid::OnAdjoin2 (wxCommandEvent &event) {
int n1 = -1; wxArrayInt sels = GetSelection();
int n2 = -1; AdjoinLines(sels.front(),sels.back(),false);
bool gotfirst = false;
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!gotfirst) {
n1 = i;
gotfirst = true;
}
else n2 = i;
}
}
if (n1 == -1) return;
if (n2 == -1) n2 = n1;
AdjoinLines(n1,n2,false);
} }
//////////////////////// ////////////////////////
// Call join as karaoke // Call join as karaoke
void SubtitlesGrid::OnJoinAsKaraoke (wxCommandEvent &event) { void SubtitlesGrid::OnJoinAsKaraoke (wxCommandEvent &event) {
int n1 = -1; wxArrayInt sels = GetSelection();
int n2 = -1; JoinAsKaraoke(sels.front(),sels.back());
bool gotfirst = false;
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!gotfirst) {
n1 = i;
gotfirst = true;
}
else n2 = i;
}
}
if (n1 == -1) return;
if (n2 == -1) n2 = n1;
JoinAsKaraoke(n1,n2);
} }
@ -446,14 +327,7 @@ void SubtitlesGrid::OnJoinAsKaraoke (wxCommandEvent &event) {
// Call insert before // Call insert before
void SubtitlesGrid::OnInsertBefore (wxCommandEvent &event) { void SubtitlesGrid::OnInsertBefore (wxCommandEvent &event) {
// Find line // Find line
int n; int n = GetFirstSelRow();
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
n = i;
break;
}
}
// Create line to add // Create line to add
AssDialogue *def = new AssDialogue; AssDialogue *def = new AssDialogue;
@ -479,14 +353,8 @@ void SubtitlesGrid::OnInsertBefore (wxCommandEvent &event) {
// Call insert after // Call insert after
void SubtitlesGrid::OnInsertAfter (wxCommandEvent &event) { void SubtitlesGrid::OnInsertAfter (wxCommandEvent &event) {
// Find line // Find line
int n; int n = GetFirstSelRow();
int nrows = GetRows(); int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
n = i;
break;
}
}
// Create line to add // Create line to add
AssDialogue *def = new AssDialogue; AssDialogue *def = new AssDialogue;
@ -513,14 +381,7 @@ void SubtitlesGrid::OnInsertAfter (wxCommandEvent &event) {
// Call insert before with video // Call insert before with video
void SubtitlesGrid::OnInsertBeforeVideo (wxCommandEvent &event) { void SubtitlesGrid::OnInsertBeforeVideo (wxCommandEvent &event) {
// Find line // Find line
int n; int n = GetFirstSelRow();
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
n = i;
break;
}
}
// Create line to add // Create line to add
AssDialogue *def = new AssDialogue; AssDialogue *def = new AssDialogue;
@ -540,14 +401,7 @@ void SubtitlesGrid::OnInsertBeforeVideo (wxCommandEvent &event) {
// Call insert after with video // Call insert after with video
void SubtitlesGrid::OnInsertAfterVideo (wxCommandEvent &event) { void SubtitlesGrid::OnInsertAfterVideo (wxCommandEvent &event) {
// Find line // Find line
int n; int n = GetFirstSelRow();
int nrows = GetRows();
for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
n = i;
break;
}
}
// Create line to add // Create line to add
AssDialogue *def = new AssDialogue; AssDialogue *def = new AssDialogue;
@ -566,14 +420,14 @@ void SubtitlesGrid::OnInsertAfterVideo (wxCommandEvent &event) {
/////////////////////////////// ///////////////////////////////
// Copy selection to clipboard // Copy selection to clipboard
void SubtitlesGrid::OnCopyLines (wxCommandEvent &WXUNUSED(&event)) { void SubtitlesGrid::OnCopyLines (wxCommandEvent &WXUNUSED(&event)) {
CopyLines(); CopyLines(GetSelection());
} }
/////////////////////////////// ///////////////////////////////
// Cuts selection to clipboard // Cuts selection to clipboard
void SubtitlesGrid::OnCutLines (wxCommandEvent &WXUNUSED(&event)) { void SubtitlesGrid::OnCutLines (wxCommandEvent &WXUNUSED(&event)) {
CutLines(); CutLines(GetSelection());
} }
@ -855,20 +709,18 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
/////////////////////////// ///////////////////////////
// Copy lines to clipboard // Copy lines to clipboard
void SubtitlesGrid::CopyLines() { void SubtitlesGrid::CopyLines(wxArrayInt target) {
// Prepare text // Prepare text
wxString data = _T(""); wxString data = _T("");
AssDialogue *cur; AssDialogue *cur;
int nrows = GetRows(); int nrows = target.Count();
bool first = true; bool first = true;
for (int i=0;i<nrows;i++) { for (int i=0;i<nrows;i++) {
if (IsInSelection(i,0)) {
if (!first) data += _T("\r\n"); if (!first) data += _T("\r\n");
first = false; first = false;
cur = GetDialogue(i); cur = GetDialogue(target[i]);
data += cur->data; data += cur->data;
} }
}
// Send to clipboard // Send to clipboard
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
@ -880,9 +732,9 @@ void SubtitlesGrid::CopyLines() {
//////////////////// ////////////////////
// Cut to clipboard // Cut to clipboard
void SubtitlesGrid::CutLines() { void SubtitlesGrid::CutLines(wxArrayInt target) {
CopyLines(); CopyLines(target);
DeleteLines(GetSelection()); DeleteLines(target);
} }
@ -942,31 +794,6 @@ void SubtitlesGrid::DeleteLines(wxArrayInt target) {
// Check if it's wiping file // Check if it's wiping file
int deleted = 0; int deleted = 0;
//// 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;
//}
//// 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 // Delete lines
int size = target.Count(); int size = target.Count();
for (int i=0;i<size;i++) { for (int i=0;i<size;i++) {
@ -1240,7 +1067,7 @@ void SubtitlesGrid::CommitChanges(bool force) {
} }
// Export // Export
wxString workfile = GetTempWorkFile(); wxString workfile = video->GetTempWorkFile();
ass->Export(workfile); ass->Export(workfile);
if (video->loaded) if (video->loaded)
@ -1255,17 +1082,6 @@ void SubtitlesGrid::CommitChanges(bool force) {
} }
//////////////////////////////
// Get name of temp work file
wxString SubtitlesGrid::GetTempWorkFile () {
if (tempfile.IsEmpty()) {
tempfile = wxFileName::CreateTempFileName(_T("aegisub"));
tempfile += _T(".ass");
}
return tempfile;
}
////////////////////////// //////////////////////////
// Set start to video pos // Set start to video pos
void SubtitlesGrid::SetSubsToVideo(bool start) { void SubtitlesGrid::SetSubsToVideo(bool start) {

View File

@ -66,12 +66,8 @@ typedef std::list<AssEntry*>::iterator entryIter;
// Main class // Main class
class SubtitlesGrid: public BaseGrid { class SubtitlesGrid: public BaseGrid {
private: private:
wxString tempfile;
bool ready; bool ready;
void OnCellLeftClick(wxGridEvent &event);
void OnCellChange(wxGridEvent &event);
void OnSelectCell(wxGridEvent &event);
void OnPopupMenu(); void OnPopupMenu();
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
@ -112,22 +108,22 @@ public:
void SetVideoToSubs(bool start); void SetVideoToSubs(bool start);
void SetSubsToVideo(bool start); void SetSubsToVideo(bool start);
void SwapLines(int n1,int n2); void JoinLines(int first,int last,bool concat=true);
void DuplicateLines(int n1,int n2,bool nextFrame=false); void JoinAsKaraoke(int first,int last);
void AdjoinLines(int first,int last,bool setStart);
void SplitLine(int lineNumber,int splitPosition,int mode);
void DuplicateLines(int first,int last,bool nextFrame=false);
void SwapLines(int line1,int line2);
void ShiftLineByTime(int lineNumber,int len,int type);
void ShiftLineByFrames(int lineNumber,int len,int type);
void InsertLine(AssDialogue *line,int position,bool insertAfter,bool update=true);
void DeleteLines(wxArrayInt lines); 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);
void InsertLine(AssDialogue *line,int n,bool after,bool update=true);
void ShiftLineByTime(int n,int len,int type);
void ShiftLineByFrames(int n,int len,int type);
void SplitLine(int n,int pos,int mode);
void CopyLines(); void CopyLines(wxArrayInt lines);
void CutLines(); void CutLines(wxArrayInt lines);
void PasteLines(int n); void PasteLines(int pos);
wxString GetTempWorkFile ();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@ -115,6 +115,8 @@ VideoDisplay::VideoDisplay(wxWindow* parent, wxWindowID id, const wxPoint& pos,
////////////// //////////////
// Destructor // Destructor
VideoDisplay::~VideoDisplay () { VideoDisplay::~VideoDisplay () {
wxRemoveFile(tempfile);
tempfile = _T("");
SetVideo(_T("")); SetVideo(_T(""));
delete backbuffer; delete backbuffer;
} }
@ -154,7 +156,7 @@ void VideoDisplay::SetVideo(const wxString &filename) {
bool usedDirectshow; bool usedDirectshow;
provider = new VideoProvider(filename,grid->GetTempWorkFile(),zoomValue,usedDirectshow,true); provider = new VideoProvider(filename,GetTempWorkFile(),zoomValue,usedDirectshow,true);
// Set keyframes // Set keyframes
if (filename.Right(4).Lower() == _T(".avi")) if (filename.Right(4).Lower() == _T(".avi"))
@ -844,3 +846,14 @@ void VideoDisplay::OnPlayTimer(wxTimerEvent &event) {
audio->provider->realPlayPos = audPos; audio->provider->realPlayPos = audPos;
} }
} }
//////////////////////////////
// Get name of temp work file
wxString VideoDisplay::GetTempWorkFile () {
if (tempfile.IsEmpty()) {
tempfile = wxFileName::CreateTempFileName(_T("aegisub"));
tempfile += _T(".ass");
}
return tempfile;
}

View File

@ -61,6 +61,8 @@ class VideoDisplay: public wxWindow {
friend class AudioProvider; friend class AudioProvider;
private: private:
wxString tempfile;
int mouse_x,mouse_y; int mouse_x,mouse_y;
wxBitmap *backbuffer; wxBitmap *backbuffer;
@ -136,6 +138,7 @@ public:
void SetZoomPos(int pos); void SetZoomPos(int pos);
void UpdateSubsRelativeTime(); void UpdateSubsRelativeTime();
void GetScriptSize(int &w,int &h); void GetScriptSize(int &w,int &h);
wxString GetTempWorkFile ();
void Play(); void Play();
void PlayLine(); void PlayLine();