From 7e5b241260e5f5fd9b541671b6f46b51a12a8390 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 12 Mar 2012 23:34:45 +0000 Subject: [PATCH] Use SubsTextEditCtrl in the translation assistant This gives spellchecking and thesaurus support for the translation (and syntax highlighting, but that usually won't be useful). Originally committed to SVN as r6578. --- aegisub/src/dialog_translation.cpp | 6 ++--- aegisub/src/dialog_translation.h | 5 +++-- aegisub/src/subs_edit_ctrl.cpp | 36 +++++++++++++----------------- aegisub/src/subs_edit_ctrl.h | 20 +++++++---------- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/aegisub/src/dialog_translation.cpp b/aegisub/src/dialog_translation.cpp index a336c4576..e96fe0f9d 100644 --- a/aegisub/src/dialog_translation.cpp +++ b/aegisub/src/dialog_translation.cpp @@ -36,7 +36,7 @@ #include "help_button.h" #include "libresrc/libresrc.h" #include "persist_location.h" -#include "scintilla_text_ctrl.h" +#include "subs_edit_ctrl.h" #include "selection_controller.h" #include "utils.h" #include "video_context.h" @@ -64,7 +64,7 @@ static bool bad_block(AssDialogueBlock *block) { } DialogTranslation::DialogTranslation(agi::Context *c) -: wxDialog(c->parent, -1, _("Translation Assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX, "TranslationAssistant") +: wxDialog(c->parent, -1, _("Translation Assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX) , c(c) , active_line(c->selectionController->GetActiveLine()) , cur_block(0) @@ -93,7 +93,7 @@ DialogTranslation::DialogTranslation(agi::Context *c) } { - translated_text = new ScintillaTextCtrl(this, -1, "", wxDefaultPosition, wxSize(320, 80)); + translated_text = new SubsTextEditCtrl(this, wxSize(320, 80), 0, 0); translated_text->SetWrapMode(wxSTC_WRAP_WORD); translated_text->SetMarginWidth(1, 0); translated_text->SetFocus(); diff --git a/aegisub/src/dialog_translation.h b/aegisub/src/dialog_translation.h index 569e989ac..7831598ba 100644 --- a/aegisub/src/dialog_translation.h +++ b/aegisub/src/dialog_translation.h @@ -31,6 +31,7 @@ namespace agi { struct Context; } class AssDialogue; class PersistLocation; class ScintillaTextCtrl; +class SubsTextEditCtrl; class wxStaticText; class wxCheckBox; @@ -43,7 +44,7 @@ class DialogTranslation : public wxDialog { /// The active line AssDialogue *active_line; - /// Which dialogue block in the active line is currrently being translated + /// Which dialogue block in the active line is currently being translated size_t cur_block; /// Total number of dialogue lines in the file @@ -53,7 +54,7 @@ class DialogTranslation : public wxDialog { wxStaticText *line_number_display; ScintillaTextCtrl *original_text; - ScintillaTextCtrl *translated_text; + SubsTextEditCtrl *translated_text; wxCheckBox *seek_video; agi::scoped_ptr persist; diff --git a/aegisub/src/subs_edit_ctrl.cpp b/aegisub/src/subs_edit_ctrl.cpp index faadeb2df..c3e09f15b 100644 --- a/aegisub/src/subs_edit_ctrl.cpp +++ b/aegisub/src/subs_edit_ctrl.cpp @@ -167,10 +167,15 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a using namespace std::tr1; - Bind(wxEVT_COMMAND_MENU_SELECTED, function(bind(&SubsTextEditCtrl::Cut, this)), EDIT_MENU_CUT); - Bind(wxEVT_COMMAND_MENU_SELECTED, function(bind(&SubsTextEditCtrl::Copy, this)), EDIT_MENU_COPY); - Bind(wxEVT_COMMAND_MENU_SELECTED, function(bind(&SubsTextEditCtrl::Paste, this)), EDIT_MENU_PASTE); - Bind(wxEVT_COMMAND_MENU_SELECTED, function(bind(&SubsTextEditCtrl::SelectAll, this)), EDIT_MENU_SELECT_ALL); + Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::Cut, this), EDIT_MENU_CUT); + Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::Copy, this), EDIT_MENU_COPY); + Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::Paste, this), EDIT_MENU_PASTE); + Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::SelectAll, this), EDIT_MENU_SELECT_ALL); + + if (context) { + Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::SplitLine, this, true), EDIT_MENU_SPLIT_PRESERVE); + Bind(wxEVT_COMMAND_MENU_SELECTED, bind(&SubsTextEditCtrl::SplitLine, this, false), EDIT_MENU_SPLIT_ESTIMATE); + } Bind(wxEVT_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this); @@ -208,8 +213,6 @@ void SubsTextEditCtrl::Subscribe(std::string const& name) { BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl) EVT_KILL_FOCUS(SubsTextEditCtrl::OnLoseFocus) - EVT_MENU(EDIT_MENU_SPLIT_PRESERVE,SubsTextEditCtrl::OnSplitLinePreserve) - EVT_MENU(EDIT_MENU_SPLIT_ESTIMATE,SubsTextEditCtrl::OnSplitLineEstimate) EVT_MENU(EDIT_MENU_ADD_TO_DICT,SubsTextEditCtrl::OnAddToDictionary) EVT_MENU_RANGE(EDIT_MENU_SUGGESTIONS,EDIT_MENU_THESAURUS-1,SubsTextEditCtrl::OnUseSuggestion) EVT_MENU_RANGE(EDIT_MENU_THESAURUS_SUGS,EDIT_MENU_DIC_LANGUAGE-1,SubsTextEditCtrl::OnUseSuggestion) @@ -282,7 +285,7 @@ void SubsTextEditCtrl::UpdateStyle() { if (text.empty()) return; // Check if it's a template line - AssDialogue *diag = context->selectionController->GetActiveLine(); + AssDialogue *diag = context ? context->selectionController->GetActiveLine() : 0; bool templateLine = diag && diag->Comment && diag->Effect.Lower().StartsWith("template"); size_t last_template = 0; @@ -719,9 +722,6 @@ void SubsTextEditCtrl::Paste() { } void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) { - if (!context->selectionController->GetActiveLine()) - return; - wxPoint pos = event.GetPosition(); int activePos; if (pos == wxDefaultPosition) { @@ -750,9 +750,11 @@ void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) { menu.Append(EDIT_MENU_SELECT_ALL,_("Select &All")); // Split - menu.AppendSeparator(); - menu.Append(EDIT_MENU_SPLIT_PRESERVE,_("Split at cursor (preserve times)")); - menu.Append(EDIT_MENU_SPLIT_ESTIMATE,_("Split at cursor (estimate times)")); + if (context) { + menu.AppendSeparator(); + menu.Append(EDIT_MENU_SPLIT_PRESERVE,_("Split at cursor (preserve times)")); + menu.Append(EDIT_MENU_SPLIT_ESTIMATE,_("Split at cursor (estimate times)")); + } PopupMenu(&menu); } @@ -865,14 +867,6 @@ void SubsTextEditCtrl::SplitLine(bool estimateTimes) { context->ass->Commit(_("split"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL); } -void SubsTextEditCtrl::OnSplitLinePreserve(wxCommandEvent &) { - SplitLine(false); -} - -void SubsTextEditCtrl::OnSplitLineEstimate(wxCommandEvent &) { - SplitLine(true); -} - void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &) { if (spellchecker) spellchecker->AddWord(currentWord); UpdateStyle(); diff --git a/aegisub/src/subs_edit_ctrl.h b/aegisub/src/subs_edit_ctrl.h index 7f67a2d80..db3b97ae6 100644 --- a/aegisub/src/subs_edit_ctrl.h +++ b/aegisub/src/subs_edit_ctrl.h @@ -48,18 +48,16 @@ class SubsEditBox; class Thesaurus; namespace agi { struct Context; } -/// DOCME /// @class SubsTextEditCtrl -/// @brief DOCME -/// -/// DOCME +/// @brief A Scintilla control with spell checking and syntax highlighting class SubsTextEditCtrl : public ScintillaTextCtrl { - /// DOCME + /// Backend spellchecker to use agi::scoped_ptr spellchecker; - /// DOCME + /// Backend thesaurus to use agi::scoped_ptr thesaurus; + /// Project context, for splitting lines agi::Context *context; /// The word right-clicked on, used for spellchecker replacing @@ -68,21 +66,19 @@ class SubsTextEditCtrl : public ScintillaTextCtrl { /// The beginning of the word right-clicked on, for spellchecker replacing int currentWordPos; - /// DOCME + /// Spellchecker suggestions for the last right-clicked word wxArrayString sugs; - /// DOCME + /// Thesaurus suggestions for the last right-clicked word std::vector thesSugs; - /// DOCME + /// Calltip prototypes wxArrayString proto; - /// DOCME + /// Last show calltip, to avoid flickering the currently active one int tipProtoN; void OnContextMenu(wxContextMenuEvent &); - void OnSplitLinePreserve(wxCommandEvent &event); - void OnSplitLineEstimate(wxCommandEvent &event); void OnAddToDictionary(wxCommandEvent &event); void OnUseSuggestion(wxCommandEvent &event); void OnSetDicLanguage(wxCommandEvent &event);