Move SplitLine from SubtitlesGrid to SubsEditCtrl

This still isn't a very good place for the functionality, but it breaks
SubsEditCtrl's dependency on SubtitlesGrid.

Originally committed to SVN as r6275.
This commit is contained in:
Thomas Goyne 2012-01-11 19:19:30 +00:00
parent c8d67ea0ff
commit 86aacca631
5 changed files with 54 additions and 56 deletions

View File

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

View File

@ -46,14 +46,15 @@
#include <wx/intl.h>
#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();
}

View File

@ -35,15 +35,18 @@
///
#ifndef AGI_PRE
#include <memory>
#include <string>
#include <vector>
#endif
#include "scintilla_text_ctrl.h"
#include <libaegisub/scoped_ptr.h>
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> spellchecker;
agi::scoped_ptr<SpellChecker> spellchecker;
/// DOCME
std::auto_ptr<Thesaurus> thesaurus;
agi::scoped_ptr<Thesaurus> 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<std::string> 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);

View File

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

View File

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