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.
This commit is contained in:
Thomas Goyne 2012-03-12 23:34:45 +00:00
parent de9cc755d2
commit 7e5b241260
4 changed files with 29 additions and 38 deletions

View file

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

View file

@ -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<PersistLocation> persist;

View file

@ -167,10 +167,15 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a
using namespace std::tr1;
Bind(wxEVT_COMMAND_MENU_SELECTED, function<void (wxCommandEvent &)>(bind(&SubsTextEditCtrl::Cut, this)), EDIT_MENU_CUT);
Bind(wxEVT_COMMAND_MENU_SELECTED, function<void (wxCommandEvent &)>(bind(&SubsTextEditCtrl::Copy, this)), EDIT_MENU_COPY);
Bind(wxEVT_COMMAND_MENU_SELECTED, function<void (wxCommandEvent &)>(bind(&SubsTextEditCtrl::Paste, this)), EDIT_MENU_PASTE);
Bind(wxEVT_COMMAND_MENU_SELECTED, function<void (wxCommandEvent &)>(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();

View file

@ -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> spellchecker;
/// DOCME
/// Backend thesaurus to use
agi::scoped_ptr<Thesaurus> 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<std::string> 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);