forked from mia/Aegisub
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:
parent
c8d67ea0ff
commit
86aacca631
|
@ -258,7 +258,7 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
|
||||||
MiddleBotSizer->Add(ByFrame,0,wxRIGHT | wxALIGN_CENTER | wxEXPAND,5);
|
MiddleBotSizer->Add(ByFrame,0,wxRIGHT | wxALIGN_CENTER | wxEXPAND,5);
|
||||||
|
|
||||||
// Text editor
|
// 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->Bind(wxEVT_KEY_DOWN, &SubsEditBox::OnKeyDown, this);
|
||||||
TextEdit->SetUndoCollection(false);
|
TextEdit->SetUndoCollection(false);
|
||||||
BottomSizer = new wxBoxSizer(wxHORIZONTAL);
|
BottomSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
|
|
@ -46,14 +46,15 @@
|
||||||
#include <wx/intl.h>
|
#include <wx/intl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "subs_edit_ctrl.h"
|
||||||
|
|
||||||
#include "ass_dialogue.h"
|
#include "ass_dialogue.h"
|
||||||
|
#include "ass_file.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "include/aegisub/context.h"
|
||||||
#include "include/aegisub/spellchecker.h"
|
#include "include/aegisub/spellchecker.h"
|
||||||
#include "selection_controller.h"
|
#include "selection_controller.h"
|
||||||
#include "subs_edit_box.h"
|
|
||||||
#include "subs_edit_ctrl.h"
|
|
||||||
#include "subs_grid.h"
|
|
||||||
#include "thesaurus.h"
|
#include "thesaurus.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
@ -76,11 +77,11 @@ enum {
|
||||||
EDIT_MENU_THES_LANGS
|
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)
|
: ScintillaTextCtrl(parent, -1, "", wxDefaultPosition, wsize, style)
|
||||||
, spellchecker(SpellCheckerFactory::GetSpellChecker())
|
, spellchecker(SpellCheckerFactory::GetSpellChecker())
|
||||||
, thesaurus(new Thesaurus)
|
, thesaurus(new Thesaurus)
|
||||||
, grid(grid)
|
, context(context)
|
||||||
{
|
{
|
||||||
// Set properties
|
// Set properties
|
||||||
SetWrapMode(wxSTC_WRAP_WORD);
|
SetWrapMode(wxSTC_WRAP_WORD);
|
||||||
|
@ -279,7 +280,7 @@ void SubsTextEditCtrl::UpdateStyle() {
|
||||||
if (text.empty()) return;
|
if (text.empty()) return;
|
||||||
|
|
||||||
// Check if it's a template line
|
// 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 templateLine = diag && diag->Comment && diag->Effect.Lower().StartsWith("template");
|
||||||
|
|
||||||
bool in_parens = false;
|
bool in_parens = false;
|
||||||
|
@ -632,7 +633,7 @@ void SubsTextEditCtrl::UpdateCallTip(wxStyledTextEvent &) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsTextEditCtrl::StyleSpellCheck() {
|
void SubsTextEditCtrl::StyleSpellCheck() {
|
||||||
if (!spellchecker.get()) return;
|
if (!spellchecker) return;
|
||||||
|
|
||||||
// Results
|
// Results
|
||||||
wxString text = GetText();
|
wxString text = GetText();
|
||||||
|
@ -706,7 +707,7 @@ void SubsTextEditCtrl::Paste() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) {
|
void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) {
|
||||||
if (!grid->GetActiveLine())
|
if (!context->selectionController->GetActiveLine())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxPoint pos = event.GetPosition();
|
wxPoint pos = event.GetPosition();
|
||||||
|
@ -723,9 +724,9 @@ void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) {
|
||||||
|
|
||||||
wxMenu menu;
|
wxMenu menu;
|
||||||
if (!currentWord.empty()) {
|
if (!currentWord.empty()) {
|
||||||
if (spellchecker.get())
|
if (spellchecker)
|
||||||
AddSpellCheckerEntries(menu);
|
AddSpellCheckerEntries(menu);
|
||||||
if (thesaurus.get())
|
if (thesaurus)
|
||||||
AddThesaurusEntries(menu);
|
AddThesaurusEntries(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,23 +832,37 @@ wxMenu *SubsTextEditCtrl::GetLanguagesMenu(int base_id, wxString const& curLang,
|
||||||
return languageMenu;
|
return languageMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SubsTextEditCtrl::SplitLine(bool estimateTimes) {
|
||||||
void SubsTextEditCtrl::OnSplitLinePreserve (wxCommandEvent &) {
|
int from, to;
|
||||||
int from,to;
|
|
||||||
GetSelection(&from, &to);
|
GetSelection(&from, &to);
|
||||||
from = GetReverseUnicodePosition(from);
|
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 &) {
|
void SubsTextEditCtrl::OnSplitLinePreserve(wxCommandEvent &) {
|
||||||
int from,to;
|
SplitLine(false);
|
||||||
GetSelection(&from, &to);
|
}
|
||||||
from = GetReverseUnicodePosition(from);
|
|
||||||
grid->SplitLine(grid->GetActiveLine(),from,1);
|
void SubsTextEditCtrl::OnSplitLineEstimate(wxCommandEvent &) {
|
||||||
|
SplitLine(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &) {
|
void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &) {
|
||||||
if (spellchecker.get()) spellchecker->AddWord(currentWord);
|
if (spellchecker) spellchecker->AddWord(currentWord);
|
||||||
UpdateStyle();
|
UpdateStyle();
|
||||||
SetFocus();
|
SetFocus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,15 +35,18 @@
|
||||||
///
|
///
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
#include <memory>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "scintilla_text_ctrl.h"
|
#include "scintilla_text_ctrl.h"
|
||||||
|
|
||||||
|
#include <libaegisub/scoped_ptr.h>
|
||||||
|
|
||||||
class SpellChecker;
|
class SpellChecker;
|
||||||
class SubsEditBox;
|
class SubsEditBox;
|
||||||
class SubtitlesGrid;
|
|
||||||
class Thesaurus;
|
class Thesaurus;
|
||||||
|
namespace agi { struct Context; }
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
/// @class SubsTextEditCtrl
|
/// @class SubsTextEditCtrl
|
||||||
|
@ -52,27 +55,25 @@ class Thesaurus;
|
||||||
/// DOCME
|
/// DOCME
|
||||||
class SubsTextEditCtrl : public ScintillaTextCtrl {
|
class SubsTextEditCtrl : public ScintillaTextCtrl {
|
||||||
/// DOCME
|
/// DOCME
|
||||||
std::auto_ptr<SpellChecker> spellchecker;
|
agi::scoped_ptr<SpellChecker> spellchecker;
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
std::auto_ptr<Thesaurus> thesaurus;
|
agi::scoped_ptr<Thesaurus> thesaurus;
|
||||||
|
|
||||||
SubtitlesGrid *grid;
|
agi::Context *context;
|
||||||
|
|
||||||
|
/// The word right-clicked on, used for spellchecker replacing
|
||||||
/// DOCME
|
|
||||||
wxString currentWord;
|
wxString currentWord;
|
||||||
|
|
||||||
|
/// The beginning of the word right-clicked on, for spellchecker replacing
|
||||||
|
int currentWordPos;
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
wxArrayString sugs;
|
wxArrayString sugs;
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
std::vector<std::string> thesSugs;
|
std::vector<std::string> thesSugs;
|
||||||
|
|
||||||
/// DOCME
|
|
||||||
int currentWordPos;
|
|
||||||
|
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
wxArrayString proto;
|
wxArrayString proto;
|
||||||
|
|
||||||
|
@ -97,6 +98,10 @@ class SubsTextEditCtrl : public ScintillaTextCtrl {
|
||||||
|
|
||||||
void UpdateStyle();
|
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
|
/// Add the thesaurus suggestions to a menu
|
||||||
void AddThesaurusEntries(wxMenu &menu);
|
void AddThesaurusEntries(wxMenu &menu);
|
||||||
|
|
||||||
|
@ -110,7 +115,7 @@ class SubsTextEditCtrl : public ScintillaTextCtrl {
|
||||||
wxMenu *GetLanguagesMenu(int base_id, wxString const& curLang, wxArrayString const& langs);
|
wxMenu *GetLanguagesMenu(int base_id, wxString const& curLang, wxArrayString const& langs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SubsTextEditCtrl(wxWindow* parent, wxSize size, long style, SubtitlesGrid *grid);
|
SubsTextEditCtrl(wxWindow* parent, wxSize size, long style, agi::Context *context);
|
||||||
~SubsTextEditCtrl();
|
~SubsTextEditCtrl();
|
||||||
|
|
||||||
void SetTextTo(wxString text);
|
void SetTextTo(wxString text);
|
||||||
|
|
|
@ -401,24 +401,6 @@ void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) {
|
||||||
SetActiveLine(GetDialogue(n1+step));
|
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)
|
/// @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
|
/// @return
|
||||||
///
|
///
|
||||||
|
|
|
@ -57,11 +57,7 @@ public:
|
||||||
/// @param n2 Last line to adjoin
|
/// @param n2 Last line to adjoin
|
||||||
/// @param setStart Set the start times (rather than end times)
|
/// @param setStart Set the start times (rather than end times)
|
||||||
void AdjoinLines(int first,int last,bool setStart);
|
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
|
/// @brief Duplicate lines
|
||||||
/// @param n1 First frame to duplicate
|
/// @param n1 First frame to duplicate
|
||||||
/// @param n2 Last frame to duplicate
|
/// @param n2 Last frame to duplicate
|
||||||
|
|
Loading…
Reference in a new issue