diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index 6c659422c..8f25e5c6d 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -258,7 +258,7 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context) MiddleBotSizer->Add(ByFrame,0,wxRIGHT | wxALIGN_CENTER | wxEXPAND,5); // Text editor - TextEdit = new SubsTextEditCtrl(this, wxSize(300,50), wxBORDER_SUNKEN, c->subsGrid); + TextEdit = new SubsTextEditCtrl(this, wxSize(300,50), wxBORDER_SUNKEN, c); TextEdit->Bind(wxEVT_KEY_DOWN, &SubsEditBox::OnKeyDown, this); TextEdit->SetUndoCollection(false); BottomSizer = new wxBoxSizer(wxHORIZONTAL); diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index ba76844a5..e28b9c3c7 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -46,14 +46,15 @@ #include #endif +#include "subs_edit_ctrl.h" + #include "ass_dialogue.h" +#include "ass_file.h" #include "compat.h" #include "main.h" +#include "include/aegisub/context.h" #include "include/aegisub/spellchecker.h" #include "selection_controller.h" -#include "subs_edit_box.h" -#include "subs_edit_ctrl.h" -#include "subs_grid.h" #include "thesaurus.h" #include "utils.h" @@ -76,11 +77,11 @@ enum { EDIT_MENU_THES_LANGS }; -SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, SubtitlesGrid *grid) +SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, agi::Context *context) : ScintillaTextCtrl(parent, -1, "", wxDefaultPosition, wsize, style) , spellchecker(SpellCheckerFactory::GetSpellChecker()) , thesaurus(new Thesaurus) -, grid(grid) +, context(context) { // Set properties SetWrapMode(wxSTC_WRAP_WORD); @@ -279,7 +280,7 @@ void SubsTextEditCtrl::UpdateStyle() { if (text.empty()) return; // Check if it's a template line - AssDialogue *diag = grid->GetActiveLine(); + AssDialogue *diag = context->selectionController->GetActiveLine(); bool templateLine = diag && diag->Comment && diag->Effect.Lower().StartsWith("template"); bool in_parens = false; @@ -632,7 +633,7 @@ void SubsTextEditCtrl::UpdateCallTip(wxStyledTextEvent &) { } void SubsTextEditCtrl::StyleSpellCheck() { - if (!spellchecker.get()) return; + if (!spellchecker) return; // Results wxString text = GetText(); @@ -706,7 +707,7 @@ void SubsTextEditCtrl::Paste() { } void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) { - if (!grid->GetActiveLine()) + if (!context->selectionController->GetActiveLine()) return; wxPoint pos = event.GetPosition(); @@ -723,9 +724,9 @@ void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) { wxMenu menu; if (!currentWord.empty()) { - if (spellchecker.get()) + if (spellchecker) AddSpellCheckerEntries(menu); - if (thesaurus.get()) + if (thesaurus) AddThesaurusEntries(menu); } @@ -831,23 +832,37 @@ wxMenu *SubsTextEditCtrl::GetLanguagesMenu(int base_id, wxString const& curLang, return languageMenu; } - -void SubsTextEditCtrl::OnSplitLinePreserve (wxCommandEvent &) { - int from,to; +void SubsTextEditCtrl::SplitLine(bool estimateTimes) { + int from, to; GetSelection(&from, &to); from = GetReverseUnicodePosition(from); - grid->SplitLine(grid->GetActiveLine(),from,0); + + AssDialogue *n2 = context->selectionController->GetActiveLine(); + AssDialogue *n1 = new AssDialogue(*n2); + context->ass->Line.insert(find(context->ass->Line.begin(), context->ass->Line.end(), n2), n1); + + wxString orig = n1->Text; + n1->Text = orig.Left(from).Trim(true); // Trim off trailing whitespace + n2->Text = orig.Mid(from).Trim(false); // Trim off leading whitespace + + if (estimateTimes) { + double splitPos = double(from) / orig.size(); + n2->Start = n1->End = (int)((n1->End - n1->Start) * splitPos) + n1->Start; + } + + context->ass->Commit(_("split"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL); } -void SubsTextEditCtrl::OnSplitLineEstimate (wxCommandEvent &) { - int from,to; - GetSelection(&from, &to); - from = GetReverseUnicodePosition(from); - grid->SplitLine(grid->GetActiveLine(),from,1); +void SubsTextEditCtrl::OnSplitLinePreserve(wxCommandEvent &) { + SplitLine(false); +} + +void SubsTextEditCtrl::OnSplitLineEstimate(wxCommandEvent &) { + SplitLine(true); } void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &) { - if (spellchecker.get()) spellchecker->AddWord(currentWord); + if (spellchecker) spellchecker->AddWord(currentWord); UpdateStyle(); SetFocus(); } diff --git a/aegisub/src/subs_edit_ctrl.h b/aegisub/src/subs_edit_ctrl.h index a941eabc7..7f67a2d80 100644 --- a/aegisub/src/subs_edit_ctrl.h +++ b/aegisub/src/subs_edit_ctrl.h @@ -35,15 +35,18 @@ /// #ifndef AGI_PRE -#include +#include +#include #endif #include "scintilla_text_ctrl.h" +#include + class SpellChecker; class SubsEditBox; -class SubtitlesGrid; class Thesaurus; +namespace agi { struct Context; } /// DOCME /// @class SubsTextEditCtrl @@ -52,27 +55,25 @@ class Thesaurus; /// DOCME class SubsTextEditCtrl : public ScintillaTextCtrl { /// DOCME - std::auto_ptr spellchecker; + agi::scoped_ptr spellchecker; /// DOCME - std::auto_ptr thesaurus; + agi::scoped_ptr thesaurus; - SubtitlesGrid *grid; + agi::Context *context; - - /// DOCME + /// The word right-clicked on, used for spellchecker replacing wxString currentWord; + /// The beginning of the word right-clicked on, for spellchecker replacing + int currentWordPos; + /// DOCME wxArrayString sugs; /// DOCME std::vector thesSugs; - /// DOCME - int currentWordPos; - - /// DOCME wxArrayString proto; @@ -97,6 +98,10 @@ class SubsTextEditCtrl : public ScintillaTextCtrl { void UpdateStyle(); + /// Split the line at the current cursor position + /// @param estimateTimes Adjust the times based on the lengths of the halves + void SplitLine(bool estimateTimes); + /// Add the thesaurus suggestions to a menu void AddThesaurusEntries(wxMenu &menu); @@ -110,7 +115,7 @@ class SubsTextEditCtrl : public ScintillaTextCtrl { wxMenu *GetLanguagesMenu(int base_id, wxString const& curLang, wxArrayString const& langs); public: - SubsTextEditCtrl(wxWindow* parent, wxSize size, long style, SubtitlesGrid *grid); + SubsTextEditCtrl(wxWindow* parent, wxSize size, long style, agi::Context *context); ~SubsTextEditCtrl(); void SetTextTo(wxString text); diff --git a/aegisub/src/subs_grid.cpp b/aegisub/src/subs_grid.cpp index 19c3cf03d..5c185119e 100644 --- a/aegisub/src/subs_grid.cpp +++ b/aegisub/src/subs_grid.cpp @@ -401,24 +401,6 @@ void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) { SetActiveLine(GetDialogue(n1+step)); } -void SubtitlesGrid::SplitLine(AssDialogue *n1,int pos,bool estimateTimes) { - AssDialogue *n2 = new AssDialogue(*n1); - InsertLine(n2,GetDialogueIndex(n1),true,false); - - wxString orig = n1->Text; - n1->Text = orig.Left(pos).Trim(true); // Trim off trailing whitespace - n2->Text = orig.Mid(pos).Trim(false); // Trim off leading whitespace - - if (estimateTimes) { - double splitPos = double(pos)/orig.Length(); - int splitTime = (int)((n1->End - n1->Start)*splitPos) + n1->Start; - n1->End = splitTime; - n2->Start = splitTime; - } - - context->ass->Commit(_("split"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL); -} - /// @brief Retrieve a list of selected lines in the actual ASS file (ie. not as displayed in the grid but as represented in the file) /// @return /// diff --git a/aegisub/src/subs_grid.h b/aegisub/src/subs_grid.h index eb7036c30..56d79bfb4 100644 --- a/aegisub/src/subs_grid.h +++ b/aegisub/src/subs_grid.h @@ -57,11 +57,7 @@ public: /// @param n2 Last line to adjoin /// @param setStart Set the start times (rather than end times) void AdjoinLines(int first,int last,bool setStart); - /// @brief Split line at the given position - /// @param line Line to split - /// @param pos Position in line - /// @param estimateTimes Adjust the times based on the lengths of the halves - void SplitLine(AssDialogue *line,int splitPosition,bool estimateTimes); + /// @brief Duplicate lines /// @param n1 First frame to duplicate /// @param n2 Last frame to duplicate