diff --git a/core/audio_display.cpp b/core/audio_display.cpp index 5b04e98ca..c35b627b6 100644 --- a/core/audio_display.cpp +++ b/core/audio_display.cpp @@ -995,7 +995,6 @@ void AudioDisplay::CommitChanges () { } // Update grid - grid->SetRowToLine(line_n,dialogue); grid->editBox->Update(!karaoke->enabled); grid->ass->FlagAsModified(); grid->CommitChanges(); diff --git a/core/base_grid.cpp b/core/base_grid.cpp index 6586de69b..3918b01b3 100644 --- a/core/base_grid.cpp +++ b/core/base_grid.cpp @@ -198,6 +198,43 @@ int BaseGrid::GetNumberSelection() { } +/////////////////////////// +// Gets first selected row +int BaseGrid::GetFirstSelRow() { + int nrows = GetRows(); + for (int i=0;iUpdateData(); // Commit - grid->SetRowToLine(curLine,cur); grid->ass->FlagAsModified(); } @@ -387,8 +386,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) { // Update video if (updateVideo) { grid->CommitChanges(); - wxCommandEvent dummy; - grid->OnSetVideoToStart(dummy); + grid->SetVideoToSubs(true); } else if (DoReplace) Modified = true; @@ -455,7 +453,6 @@ void SearchReplaceEngine::ReplaceAll() { AssDialogue *cur = grid->GetDialogue(i); cur->UpdateData(); //cur->ParseASSTags(); - grid->SetRowToLine(i,cur); } } diff --git a/core/dialog_spellcheck.cpp b/core/dialog_spellcheck.cpp index c17df6f6c..1f0c5a67e 100644 --- a/core/dialog_spellcheck.cpp +++ b/core/dialog_spellcheck.cpp @@ -571,8 +571,8 @@ void DialogSpellCheck::BlockStore() { curPlain->text = current_block; current_line->UpdateText(); current_line->UpdateData(); - grid->SetRowToLine(curLineNumber,current_line); subs->FlagAsModified(); + grid->CommitChanges(); } curPlain = 0; current_line->ClearBlocks(); diff --git a/core/dialog_styling_assistant.cpp b/core/dialog_styling_assistant.cpp index c9577fbe7..fc861d411 100644 --- a/core/dialog_styling_assistant.cpp +++ b/core/dialog_styling_assistant.cpp @@ -215,7 +215,7 @@ void DialogStyling::SetStyle (wxString curName, bool jump) { line->UpdateData(); // Update grid/subs - grid->SetRowToLine(linen,line); + grid->Refresh(false); if (PreviewCheck->IsChecked()) { grid->ass->FlagAsModified(); grid->CommitChanges(); diff --git a/core/dialog_translation.cpp b/core/dialog_translation.cpp index 2bb1b6ff2..6027a9c72 100644 --- a/core/dialog_translation.cpp +++ b/core/dialog_translation.cpp @@ -314,7 +314,6 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) { cur->UpdateText(); cur->UpdateData(); cur->ClearBlocks(); - grid->SetRowToLine(curline,cur); subs->FlagAsModified(); grid->CommitChanges(); ((FrameMain*)main)->UpdateTitle(); diff --git a/core/frame_main_events.cpp b/core/frame_main_events.cpp index 7e6e16d44..dd200c603 100644 --- a/core/frame_main_events.cpp +++ b/core/frame_main_events.cpp @@ -729,9 +729,7 @@ void FrameMain::OnSnapSubsStartToVid (wxCommandEvent &event) { wxArrayInt sel = SubsBox->GetSelection(); if (sel.Count() > 0) { wxCommandEvent dummy; - SubsBox->OnSetStartToVideo(dummy); - //SubsBox->ass->FlagAsModified(); - //SubsBox->CommitChanges(); + SubsBox->SetSubsToVideo(true); } } } @@ -741,9 +739,7 @@ void FrameMain::OnSnapSubsEndToVid (wxCommandEvent &event) { wxArrayInt sel = SubsBox->GetSelection(); if (sel.Count() > 0) { wxCommandEvent dummy; - SubsBox->OnSetEndToVideo(dummy); - //SubsBox->ass->FlagAsModified(); - //SubsBox->CommitChanges(); + SubsBox->SetSubsToVideo(false); } } } @@ -756,7 +752,7 @@ void FrameMain::OnSnapVidToSubsStart (wxCommandEvent &event) { wxArrayInt sel = SubsBox->GetSelection(); if (sel.Count() > 0) { wxCommandEvent dummy; - SubsBox->OnSetVideoToStart(dummy); + SubsBox->SetVideoToSubs(true); } } } @@ -766,7 +762,7 @@ void FrameMain::OnSnapVidToSubsEnd (wxCommandEvent &event) { wxArrayInt sel = SubsBox->GetSelection(); if (sel.Count() > 0) { wxCommandEvent dummy; - SubsBox->OnSetVideoToEnd(dummy); + SubsBox->SetVideoToSubs(false); } } } @@ -822,7 +818,6 @@ void FrameMain::OnSnapToScene (wxCommandEvent &event) { cur->Start.SetMS(start_ms); cur->End.SetMS(end_ms); cur->UpdateData(); - SubsBox->SetRowToLine(sel[i],cur); } // Commit @@ -853,7 +848,6 @@ void FrameMain::OnShiftToFrame (wxCommandEvent &event) { cur->Start.SetMS(cur->Start.GetMS()+shiftBy); cur->End.SetMS(cur->End.GetMS()+shiftBy); cur->UpdateData(); - SubsBox->SetRowToLine(sels[i],cur); } } @@ -962,18 +956,15 @@ void FrameMain::OnCloseWindow (wxCloseEvent &event) { ////////////////// // Cut/copy/paste void FrameMain::OnCut (wxCommandEvent &event) { - wxCommandEvent dummy; - SubsBox->OnCutLines(dummy); + SubsBox->CutLines(); } void FrameMain::OnCopy (wxCommandEvent &event) { - wxCommandEvent dummy; - SubsBox->OnCopyLines(dummy); + SubsBox->CopyLines(); } void FrameMain::OnPaste (wxCommandEvent &event) { - wxCommandEvent dummy; - SubsBox->OnPasteLines(dummy); + SubsBox->PasteLines(SubsBox->GetFirstSelRow()); } diff --git a/core/subs_edit_box.cpp b/core/subs_edit_box.cpp index a6f711b83..70342013e 100644 --- a/core/subs_edit_box.cpp +++ b/core/subs_edit_box.cpp @@ -577,7 +577,6 @@ void SubsEditBox::OnStyleChange(wxCommandEvent &event) { if (cur) { cur->Style = StyleBox->GetValue(); cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } grid->AutoSizeColumn(3); @@ -602,7 +601,6 @@ void SubsEditBox::OnActorChange(wxCommandEvent &event) { if (cur) { cur->Actor = actor; cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } @@ -635,7 +633,6 @@ void SubsEditBox::OnLayerChange(wxCommandEvent &event) { Layer->GetValue().ToLong(&temp); cur->Layer = temp; cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } grid->AutoSizeColumn(0); @@ -704,7 +701,6 @@ void SubsEditBox::CommitTimes(bool start,bool end,bool fromStart) { // Update cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } @@ -730,7 +726,6 @@ void SubsEditBox::OnMarginLChange(wxCommandEvent &event) { if (cur) { cur->SetMarginString(MarginL->GetValue(),1); cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } MarginL->SetValue(cur->GetMarginString(1)); @@ -753,7 +748,6 @@ void SubsEditBox::OnMarginRChange(wxCommandEvent &event) { if (cur) { cur->SetMarginString(MarginR->GetValue(),2); cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } MarginR->SetValue(cur->GetMarginString(2)); @@ -776,7 +770,6 @@ void SubsEditBox::OnMarginVChange(wxCommandEvent &event) { if (cur) { cur->SetMarginString(MarginV->GetValue(),3); cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } MarginV->SetValue(cur->GetMarginString(3)); @@ -798,7 +791,6 @@ void SubsEditBox::OnCommentChange(wxCommandEvent &event) { if (cur) { cur->Comment = CommentBox->GetValue(); cur->UpdateData(); - grid->SetRowToLine(sel[i],cur); } } grid->ass->FlagAsModified(); @@ -876,7 +868,7 @@ void SubsEditBox::CommitText() { cur->Text = TextEdit->GetValue(); //cur->ParseASSTags(); cur->UpdateData(); - grid->SetRowToLine(linen,cur); + grid->Refresh(false); audio->SetDialogue(grid,cur,linen); } } diff --git a/core/subs_grid.cpp b/core/subs_grid.cpp index f4317cb19..ad8b70a7d 100644 --- a/core/subs_grid.cpp +++ b/core/subs_grid.cpp @@ -79,8 +79,6 @@ BEGIN_EVENT_TABLE(SubtitlesGrid, BaseGrid) EVT_MENU(MENU_1_12_2_RECOMBINE,SubtitlesGrid::On1122Recombine) EVT_MENU(MENU_12_2_RECOMBINE,SubtitlesGrid::On122Recombine) EVT_MENU(MENU_1_12_RECOMBINE,SubtitlesGrid::On112Recombine) - - EVT_ERASE_BACKGROUND(SubtitlesGrid::OnEraseBackground) END_EVENT_TABLE() @@ -90,22 +88,11 @@ SubtitlesGrid::SubtitlesGrid(FrameMain* parentFr, wxWindow *parent, wxWindowID i : BaseGrid(parent,id,pos,size,style,name) { // Vars - changingCol = false; byFrame = false; ass = NULL; video = _video; editBox = NULL; parentFrame = parentFr; - - // Font size - int fontSize = Options.AsInt(_T("Grid font size")); - wxFont font; - font.SetPointSize(fontSize); - wxClientDC dc(this); - dc.SetFont(font); - int w,h; - dc.GetTextExtent(_T("#TWFfgGhH"), &w, &h, NULL, NULL, &font); - RowHeight = h+4; } @@ -586,24 +573,14 @@ void SubtitlesGrid::OnCopyLines (wxCommandEvent &WXUNUSED(&event)) { /////////////////////////////// // Cuts selection to clipboard void SubtitlesGrid::OnCutLines (wxCommandEvent &WXUNUSED(&event)) { - CopyLines(); - DeleteLines(-1,-1,true); + CutLines(); } //////////////////////// // Paste from clipboard void SubtitlesGrid::OnPasteLines (wxCommandEvent &WXUNUSED(&event)) { - int n; - int nrows = GetRows(); - for (int i=0;iframe_n,true); - - // Update selection - wxArrayInt sel = GetSelection(); - AssDialogue *cur; - int modified =0; - for (size_t i=0;iStart.SetMS(ms); - cur->UpdateData(); - SetRowToLine(sel[i],cur); - } - } - - // Commit - if (modified) { - ass->FlagAsModified(); - CommitChanges(); - editBox->Update(); - } + SetSubsToVideo(true); } //////////////////////// // Set end to video pos void SubtitlesGrid::OnSetEndToVideo(wxCommandEvent &event) { - // Check if it's OK to do it - if (!VFR_Output.loaded) return; - - // Get new time - int ms = VFR_Output.CorrectTimeAtFrame(video->frame_n,false); - - // Update selection - wxArrayInt sel = GetSelection(); - AssDialogue *cur; - int modified = 0; - for (size_t i=0;iEnd.SetMS(ms); - cur->UpdateData(); - modified++; - SetRowToLine(sel[i],cur); - } - } - - // Commit - if (modified) { - ass->FlagAsModified(); - CommitChanges(); - editBox->Update(); - } + SetSubsToVideo(false); } ////////////////////////// // Set video pos to start void SubtitlesGrid::OnSetVideoToStart(wxCommandEvent &event) { - wxArrayInt sel = GetSelection(); - if (sel.Count() == 0) return; - AssDialogue *cur = GetDialogue(sel[0]); - if (cur) video->JumpToFrame(VFR_Output.CorrectFrameAtTime(cur->Start.GetMS(),true)); + SetVideoToSubs(true); } //////////////////////// // Set video pos to end void SubtitlesGrid::OnSetVideoToEnd(wxCommandEvent &event) { - wxArrayInt sel = GetSelection(); - if (sel.Count() == 0) return; - AssDialogue *cur = GetDialogue(sel[0]); - //if (cur) video->JumpToTime(cur->End.GetMS()); - if (cur) video->JumpToFrame(VFR_Output.CorrectFrameAtTime(cur->End.GetMS(),false)); + SetVideoToSubs(false); } @@ -752,8 +672,6 @@ void SubtitlesGrid::On122Recombine(wxCommandEvent &event) { n2->UpdateData(); // Commit - SetRowToLine(n,n1); - SetRowToLine(n+1,n2); ass->FlagAsModified(); CommitChanges(); } else { @@ -791,8 +709,6 @@ void SubtitlesGrid::On112Recombine(wxCommandEvent &event) { n2->UpdateData(); // Commit - SetRowToLine(n,n1); - SetRowToLine(n+1,n2); ass->FlagAsModified(); CommitChanges(); } else { @@ -903,27 +819,6 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif } -///////////////////////////////////////// -// Sets one line to a line from the subs -void SubtitlesGrid::SetRowToLine(int n,AssDialogue *line) { - Refresh(false); -} - - -////////////////// -// Sets row color -void SubtitlesGrid::SetRowColour(int n,AssDialogue *line) { - Refresh(false); -} - - -////////////////////// -// Update row colours -void SubtitlesGrid::UpdateRowColours() { - Refresh(false); -} - - /////////////////// // Swaps two lines void SubtitlesGrid::SwapLines(int n1,int n2) { @@ -936,10 +831,6 @@ void SubtitlesGrid::SwapLines(int n1,int n2) { // Swaps iter_swap(src1,src2); - // Update display - SetRowToLine(n1,AssEntry::GetAsDialogue(*src1)); - SetRowToLine(n2,AssEntry::GetAsDialogue(*src2)); - // Update mapping diagMap[n1] = src1; diagMap[n2] = src2; @@ -999,6 +890,14 @@ void SubtitlesGrid::CopyLines() { } +//////////////////// +// Cut to clipboard +void SubtitlesGrid::CutLines() { + CopyLines(); + DeleteLines(-1,-1,true); +} + + ////////////////////////////// // Paste lines from clipboard void SubtitlesGrid::PasteLines(int n) { @@ -1151,7 +1050,6 @@ void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) { if (!cur) return; cur->Start = prev->End; cur->UpdateData(); - SetRowToLine(i,cur); prev = cur; } } @@ -1165,7 +1063,6 @@ void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) { if (!next) return; cur->End = next->Start; cur->UpdateData(); - SetRowToLine(i,cur); cur = next; } } @@ -1329,8 +1226,6 @@ void SubtitlesGrid::SplitLine(int n,int pos,int mode) { // Update data n1->UpdateData(); n2->UpdateData(); - SetRowToLine(n,n1); - SetRowToLine(n+1,n2); // Update editbox and audio editBox->SetToLine(n); @@ -1365,53 +1260,6 @@ void SubtitlesGrid::CommitChanges(bool force) { if (playing) video->Play(); } parentFrame->UpdateTitle(); -} - - -/////////////////////////// -// Gets first selected row -int SubtitlesGrid::GetFirstSelRow() { - int nrows = GetRows(); - for (int i=0;iframe_n,true); + + // Update selection + wxArrayInt sel = GetSelection(); + AssDialogue *cur; + int modified =0; + for (size_t i=0;iStart.SetMS(ms); + else cur->End.SetMS(ms); + cur->UpdateData(); + } + } + + // Commit + if (modified) { + ass->FlagAsModified(); + CommitChanges(); + editBox->Update(); + } +} + + +////////////////////////////// +// Set video pos to start/end +void SubtitlesGrid::SetVideoToSubs(bool start) { + wxArrayInt sel = GetSelection(); + if (sel.Count() == 0) return; + AssDialogue *cur = GetDialogue(sel[0]); + if (cur) { + if (start) video->JumpToFrame(VFR_Output.CorrectFrameAtTime(cur->Start.GetMS(),true)); + else video->JumpToFrame(VFR_Output.CorrectFrameAtTime(cur->End.GetMS(),false)); + } +} diff --git a/core/subs_grid.h b/core/subs_grid.h index dd5986232..29ff1f731 100644 --- a/core/subs_grid.h +++ b/core/subs_grid.h @@ -67,17 +67,8 @@ typedef std::list::iterator entryIter; class SubtitlesGrid: public BaseGrid { private: wxString tempfile; - bool changingCol; bool ready; - int RowHeight; -public: - AssFile *ass; - - SubtitlesGrid(FrameMain* parentFrame,wxWindow *parent, wxWindowID id, VideoDisplay* video, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr); - ~SubtitlesGrid(); - - void OnEraseBackground(wxEraseEvent& event) {} void OnCellLeftClick(wxGridEvent &event); void OnCellChange(wxGridEvent &event); void OnSelectCell(wxGridEvent &event); @@ -107,31 +98,38 @@ public: void On1122Recombine(wxCommandEvent &event); void On122Recombine(wxCommandEvent &event); void On112Recombine(wxCommandEvent &event); - + +public: + AssFile *ass; + + SubtitlesGrid(FrameMain* parentFrame,wxWindow *parent, wxWindowID id, VideoDisplay* video, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr); + ~SubtitlesGrid(); + void LoadDefault(AssFile *ass=NULL); - void Clear(); - void SetRowColour(int n,AssDialogue *line=NULL); - void UpdateRowColours(); - void SelectVisible(); - void SetRowToLine(int n,AssDialogue *line); void LoadFromAss(AssFile *ass=NULL,bool keepSelection=false,bool dontModify=false); void CommitChanges(bool force=false); + + void Clear(); + void SelectVisible(); + + void SetVideoToSubs(bool start); + void SetSubsToVideo(bool start); + void SwapLines(int n1,int n2); - void CopyLines(); void DuplicateLines(int n1,int n2,bool nextFrame=false); - void PasteLines(int n); void DeleteLines(int n1,int n2,bool sel); 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 JoinAsKaraoke(int n1,int n2); void SplitLine(int n,int pos,int mode); - int GetFirstSelRow(); - wxArrayInt GetSelection(bool *continuous=NULL); - void SetByFrame (bool state); + void CopyLines(); + void CutLines(); + void PasteLines(int n); + wxString GetTempWorkFile (); DECLARE_EVENT_TABLE() diff --git a/core/video_display.cpp b/core/video_display.cpp index 93ff97ccc..ae855572b 100644 --- a/core/video_display.cpp +++ b/core/video_display.cpp @@ -411,7 +411,7 @@ void VideoDisplay::JumpToFrame(int n) { ControlSlider->SetValue(n); // Update grid - if (!IsPlaying && Options.AsBool(_T("Highlight subs in frame"))) grid->UpdateRowColours(); + if (!IsPlaying && Options.AsBool(_T("Highlight subs in frame"))) grid->Refresh(false); } diff --git a/core/video_slider.cpp b/core/video_slider.cpp index 75a9c4948..1a7219a35 100644 --- a/core/video_slider.cpp +++ b/core/video_slider.cpp @@ -288,9 +288,6 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) { // Jump to next sub boundary if (direction != 0) { - wxCommandEvent dummy; - //int target1 = VFR_Output.GetFrameAtTime(curDiag->Start.GetMS()+1)+1; - //int target2 = VFR_Output.GetFrameAtTime(curDiag->End.GetMS()); int target1 = VFR_Output.CorrectFrameAtTime(curDiag->Start.GetMS(),true); int target2 = VFR_Output.CorrectFrameAtTime(curDiag->End.GetMS(),false); bool drawn = false; @@ -301,12 +298,11 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) { else if (Display->frame_n < target2) Display->JumpToFrame(target2); else { if (cur+1 >= grid->GetRows()) return; - grid->BeginBatch(); grid->editBox->SetToLine(cur+1); grid->SelectRow(cur+1); grid->MakeCellVisible(cur+1,0); - grid->OnSetVideoToStart(dummy); - grid->EndBatch(); + grid->SetVideoToSubs(true); + grid->Refresh(false); drawn = true; } return; @@ -318,27 +314,15 @@ void VideoSlider::OnKeyDown(wxKeyEvent &event) { else if (Display->frame_n > target1) Display->JumpToFrame(target1); else { if (cur-1 < 0) return; - grid->BeginBatch(); grid->editBox->SetToLine(cur-1); grid->SelectRow(cur-1); grid->MakeCellVisible(cur-1,0); - grid->OnSetVideoToEnd(dummy); - grid->EndBatch(); + grid->SetVideoToSubs(false); + grid->Refresh(false); drawn = true; } return; } - - // Text - /* - if (drawn) { - wxMemoryDC dc; - dc.SelectObject(*Display->curFrame); - dc.BeginDrawing(); - dc.DrawText(_T("Hello world!"),10,10); - dc.EndDrawing(); - } - */ } }