Move the split line at cursor functionality to commands

This commit is contained in:
Thomas Goyne 2012-10-30 12:32:47 -07:00
parent 9d4be82be8
commit b077c0991b
3 changed files with 46 additions and 27 deletions

View File

@ -825,6 +825,47 @@ struct edit_line_split_by_karaoke : public validate_sel_nonempty {
}
};
void split_lines(agi::Context *c, bool estimate) {
int pos = c->textSelectionController->GetSelectionStart();
AssDialogue *n1 = c->selectionController->GetActiveLine();
AssDialogue *n2 = new AssDialogue(*n1);
c->ass->Line.insert(++c->ass->Line.iterator_to(*n1), *n2);
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 (estimate && orig.size()) {
double splitPos = double(pos) / orig.size();
n2->Start = n1->End = (int)((n1->End - n1->Start) * splitPos) + n1->Start;
}
c->ass->Commit(_("split"), AssFile::COMMIT_DIAG_ADDREM | (estimate ? AssFile::COMMIT_DIAG_FULL : AssFile::COMMIT_DIAG_TEXT));
}
struct edit_line_split_estimate : public validate_sel_nonempty {
CMD_NAME("edit/line/split/estimate")
STR_MENU("Split at cursor (estimate times)")
STR_DISP("Split at cursor (estimate times)")
STR_HELP("Split the current line at the cursor, dividing the original line's duration between the new ones")
void operator()(agi::Context *c) {
split_lines(c, true);
}
};
struct edit_line_split_preserve : public validate_sel_nonempty {
CMD_NAME("edit/line/split/preserve")
STR_MENU("Split at cursor (preserve times)")
STR_DISP("Split at cursor (preserve times)")
STR_HELP("Split the current line at the cursor, setting both lines to the original line's times")
void operator()(agi::Context *c) {
split_lines(c, false);
}
};
/// Redoes last action.
struct edit_redo : public Command {
CMD_NAME("edit/redo")
@ -900,6 +941,8 @@ namespace cmd {
reg(new edit_line_paste_over);
reg(new edit_line_recombine);
reg(new edit_line_split_by_karaoke);
reg(new edit_line_split_estimate);
reg(new edit_line_split_preserve);
reg(new edit_style_bold);
reg(new edit_style_italic);
reg(new edit_style_underline);

View File

@ -50,6 +50,7 @@
#include "ass_dialogue.h"
#include "ass_file.h"
#include "command/command.h"
#include "compat.h"
#include "main.h"
#include "include/aegisub/context.h"
@ -175,8 +176,8 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::SelectAll, this), EDIT_MENU_SELECT_ALL);
if (context) {
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::SplitLine, this, false), EDIT_MENU_SPLIT_PRESERVE);
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::SplitLine, this, true), EDIT_MENU_SPLIT_ESTIMATE);
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&cmd::call, "edit/line/split/preserve", context), EDIT_MENU_SPLIT_PRESERVE);
Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&cmd::call, "edit/line/split/estimate", context), EDIT_MENU_SPLIT_ESTIMATE);
}
Bind(wxEVT_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this);
@ -667,27 +668,6 @@ wxMenu *SubsTextEditCtrl::GetLanguagesMenu(int base_id, wxString const& curLang,
return languageMenu;
}
void SubsTextEditCtrl::SplitLine(bool estimateTimes) {
int from, to;
GetSelection(&from, &to);
from = GetReverseUnicodePosition(from);
AssDialogue *n1 = context->selectionController->GetActiveLine();
AssDialogue *n2 = new AssDialogue(*n1);
context->ass->Line.insert(++context->ass->Line.iterator_to(*n1), *n2);
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 && orig.size()) {
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 | (estimateTimes ? AssFile::COMMIT_DIAG_FULL : AssFile::COMMIT_DIAG_TEXT));
}
void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &) {
if (spellchecker) spellchecker->AddWord(currentWord);
UpdateStyle();

View File

@ -95,10 +95,6 @@ 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);