Rewrite the translation assisant and make it work again

Originally committed to SVN as r5519.
This commit is contained in:
Thomas Goyne 2011-07-27 05:36:15 +00:00
parent 07b77203f1
commit fc46b25726
6 changed files with 342 additions and 556 deletions

View file

@ -228,12 +228,81 @@ struct tool_translation_assistant : public Command {
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
c->videoController->Stop(); c->videoController->Stop();
int start = c->subsGrid->GetFirstSelRow(); DialogTranslation d(c);
if (start == -1) start = 0; c->translationAssistant = &d;
DialogTranslation(c, start, true).ShowModal(); d.ShowModal();
c->translationAssistant = 0;
}
};
struct tool_translation_assistant_validator : public Command {
CMD_TYPE(COMMAND_VALIDATE)
bool Validate(agi::Context *c) {
return !!c->translationAssistant;
}
};
/// Commit changes and move to the next line.
struct tool_translation_assistant_commit : public tool_translation_assistant_validator {
CMD_NAME("tool/translation_assistant/commit")
STR_MENU("&Accept changes")
STR_DISP("Accept changes")
STR_HELP("Commit changes and move to the next line.")
void operator()(agi::Context *c) {
c->translationAssistant->Commit(true);
}
};
/// Commit changes and stay on the current line.
struct tool_translation_assistant_preview : public tool_translation_assistant_validator {
CMD_NAME("tool/translation_assistant/preview")
STR_MENU("&Preview changes")
STR_DISP("Preview changes")
STR_HELP("Commit changes and stay on the current line.")
void operator()(agi::Context *c) {
c->translationAssistant->Commit(false);
}
};
/// Move to the next line without committing changes.
struct tool_translation_assistant_next : public tool_translation_assistant_validator {
CMD_NAME("tool/translation_assistant/next")
STR_MENU("&Next line")
STR_DISP("Next line")
STR_HELP("Move to the next line without committing changes.")
void operator()(agi::Context *c) {
c->translationAssistant->NextBlock();
}
};
/// Move to the previous line without committing changes.
struct tool_translation_assistant_prev : public tool_translation_assistant_validator {
CMD_NAME("tool/translation_assistant/prev")
STR_MENU("&Prev line")
STR_DISP("Prev line")
STR_HELP("Move to the previous line without committing changes.")
void operator()(agi::Context *c) {
c->translationAssistant->PrevBlock();
} }
}; };
} }
/// Insert the untranslated text.
struct tool_translation_assistant_insert : public tool_translation_assistant_validator {
CMD_NAME("tool/translation_assistant/insert_original")
STR_MENU("&Insert Original")
STR_DISP("Insert Original")
STR_HELP("Insert the untranslated text.")
void operator()(agi::Context *c) {
c->translationAssistant->InsertOriginal();
}
};
/// @} /// @}
namespace cmd { namespace cmd {
@ -254,5 +323,10 @@ namespace cmd {
reg(new tool_assdraw); reg(new tool_assdraw);
} }
#endif #endif
reg(new tool_translation_assistant_commit);
reg(new tool_translation_assistant_preview);
reg(new tool_translation_assistant_next);
reg(new tool_translation_assistant_prev);
reg(new tool_translation_assistant_insert);
} }
} }

View file

@ -1,29 +1,16 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro // Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
// All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Permission to use, copy, modify, and distribute this software for any
// modification, are permitted provided that the following conditions are met: // purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
// //
// * Redistributions of source code must retain the above copyright notice, // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// this list of conditions and the following disclaimer. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// * Redistributions in binary form must reproduce the above copyright notice, // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// this list of conditions and the following disclaimer in the documentation // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// and/or other materials provided with the distribution. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// * Neither the name of the Aegisub Group nor the names of its contributors // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// may be used to endorse or promote products derived from this software // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// //
// Aegisub Project http://www.aegisub.org/ // Aegisub Project http://www.aegisub.org/
// //
@ -34,14 +21,9 @@
/// @ingroup tools_ui /// @ingroup tools_ui
/// ///
///////////
// Headers
#include "config.h" #include "config.h"
#ifndef AGI_PRE #include "dialog_translation.h"
#include <wx/settings.h>
#endif
#include "include/aegisub/context.h" #include "include/aegisub/context.h"
#include "include/aegisub/hotkey.h" #include "include/aegisub/hotkey.h"
@ -49,443 +31,238 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "audio_controller.h" #include "audio_controller.h"
#include "dialog_translation.h" #include "command/command.h"
#include "frame_main.h"
#include "help_button.h" #include "help_button.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "persist_location.h"
#include "scintilla_text_ctrl.h"
#include "selection_controller.h" #include "selection_controller.h"
#include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_context.h" #include "video_context.h"
#include "video_display.h"
#ifndef AGI_PRE
#include <wx/checkbox.h>
#include <wx/settings.h>
#include <wx/stattext.h>
#endif
/// @brief Constructor static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, const char *text) {
/// @param parent sizer->Add(new wxStaticText(parent, -1, _(text)));
/// @param _subs sizer->Add(new wxStaticText(parent, -1, hotkey::get_hotkey_str_first("Translation Assistant", command)));
/// @param _grid }
/// @param startrow
/// @param preview DialogTranslation::DialogTranslation(agi::Context *c)
/// : wxDialog(c->parent, -1, _("Translation Assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX, "TranslationAssistant")
DialogTranslation::DialogTranslation(agi::Context *c, int startrow, bool preview) , c(c)
: wxDialog(c->parent, -1, _("Translation Assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX, _T("TranslationAssistant")) , active_line(c->selectionController->GetActiveLine())
, cur_block(0)
, line_count(count_if(c->ass->Line.begin(), c->ass->Line.end(), cast<AssDialogue*>()))
, line_number(count_if(c->ass->Line.begin(), find(c->ass->Line.begin(), c->ass->Line.end(), active_line), cast<AssDialogue*>()) + 1)
{ {
// Set icon SetIcon(BitmapToIcon(GETIMAGE(translation_toolbutton_16)));
SetIcon(BitmapToIcon(GETIMAGE(translation_toolbutton_24)));
// Set variables wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
enablePreview = preview;
main = c->parent;
subs = c->ass;
grid = c->subsGrid;
audio = c->audioController;
video = c->videoController;
// Translation controls wxSizer *translation_sizer = new wxBoxSizer(wxVERTICAL);
OrigText = new ScintillaTextCtrl(this,TEXT_ORIGINAL,_T(""),wxDefaultPosition,wxSize(320,80)); {
OrigText->SetWrapMode(wxSTC_WRAP_WORD); wxSizer *original_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Original"));
OrigText->SetMarginWidth(1,0);
OrigText->StyleSetForeground(1,wxColour(10,60,200));
OrigText->SetReadOnly(true);
//OrigText->PushEventHandler(new DialogTranslationEvent(this));
TransText = new ScintillaTextCtrl(this,TEXT_TRANS,_T(""),wxDefaultPosition,wxSize(320,80));
TransText->SetWrapMode(wxSTC_WRAP_WORD);
TransText->SetMarginWidth(1,0);
TransText->PushEventHandler(new DialogTranslationEvent(this));
TransText->SetFocus();
// Translation box line_number_display = new wxStaticText(this, -1, "");
wxSizer *TranslationSizer = new wxBoxSizer(wxVERTICAL); original_box->Add(line_number_display, 0, wxBOTTOM, 5);
wxSizer *OriginalTransSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Original"));
wxSizer *TranslatedSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Translation"));
LineCount = new wxStaticText(this,-1,_("Current line: ?"));
OriginalTransSizer->Add(LineCount,0,wxBOTTOM,5);
OriginalTransSizer->Add(OrigText,1,wxEXPAND,0);
TranslatedSizer->Add(TransText,1,wxEXPAND,0);
TranslationSizer->Add(OriginalTransSizer,1,wxEXPAND,0);
TranslationSizer->Add(TranslatedSizer,1,wxTOP|wxEXPAND,5);
// Hotkeys original_text = new ScintillaTextCtrl(this, -1, "", wxDefaultPosition, wxSize(320, 80));
wxSizer *KeysSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Keys")); original_text->SetWrapMode(wxSTC_WRAP_WORD);
wxSizer *KeysInnerSizer = new wxGridSizer(2,0,5); original_text->SetMarginWidth(1, 0);
//H KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Translation Assistant Accept")) + _T(": "))); original_text->StyleSetForeground(1, wxColour(10, 60, 200));
KeysInnerSizer->Add(new wxStaticText(this,-1,_("Accept changes"))); original_text->SetReadOnly(true);
//H KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Translation Assistant Preview")) + _T(": "))); original_box->Add(original_text, 1, wxEXPAND, 0);
KeysInnerSizer->Add(new wxStaticText(this,-1,_("Preview changes")));
//H KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Translation Assistant Prev")) + _T(": ")));
KeysInnerSizer->Add(new wxStaticText(this,-1,_("Previous line")));
//H KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Translation Assistant Next")) + _T(": ")));
KeysInnerSizer->Add(new wxStaticText(this,-1,_("Next line")));
//H KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Translation Assistant Insert Original")) + _T(": ")));
KeysInnerSizer->Add(new wxStaticText(this,-1,_("Insert original")));
//H KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Translation Assistant Play Video")) + _T(": ")));
KeysInnerSizer->Add(new wxStaticText(this,-1,_("Play Video")));
//H KeysInnerSizer->Add(new wxStaticText(this,-1,Hotkeys.GetText(_T("Translation Assistant Play Audio")) + _T(": ")));
KeysInnerSizer->Add(new wxStaticText(this,-1,_("Play Audio")));
PreviewCheck = new wxCheckBox(this,PREVIEW_CHECK,_("Enable preview"));
PreviewCheck->SetValue(preview);
PreviewCheck->PushEventHandler(new DialogTranslationEvent(this));
KeysSizer->Add(KeysInnerSizer,0,wxEXPAND,0);
KeysSizer->Add(PreviewCheck,0,wxTOP,5);
// Tool sizer translation_sizer->Add(original_box, 1, wxEXPAND, 0);
wxStaticBoxSizer *ToolSizer = new wxStaticBoxSizer(wxVERTICAL,this, _("Actions"));
wxButton *PlayVideoButton = new wxButton(this,BUTTON_TRANS_PLAY_VIDEO,_("Play Video"));
wxButton *PlayAudioButton = new wxButton(this,BUTTON_TRANS_PLAY_AUDIO,_("Play Audio"));
PlayVideoButton->Enable(video->IsLoaded());
/// @todo Reinstate this when the audio context is made reachable from here
//PlayAudioButton->Enable(audio->loaded);
ToolSizer->Add(PlayAudioButton,0,wxALL,5);
ToolSizer->Add(PlayVideoButton,0,wxLEFT | wxRIGHT | wxBOTTOM,5);
// Hotkeys + Tool sizer
wxBoxSizer *HTSizer = new wxBoxSizer(wxHORIZONTAL);
HTSizer->Add(KeysSizer,1,wxRIGHT | wxEXPAND,5);
HTSizer->Add(ToolSizer,0);
// Button sizer
wxStdDialogButtonSizer *ButtonSizer = new wxStdDialogButtonSizer();
ButtonSizer->AddButton(new wxButton(this,wxID_CANCEL));
ButtonSizer->AddButton(new HelpButton(this,_T("Translation Assistant")));
ButtonSizer->Realize();
// General layout
wxSizer *MainSizer = new wxBoxSizer(wxVERTICAL);
MainSizer->Add(TranslationSizer,1,wxALL | wxEXPAND,5);
MainSizer->Add(HTSizer,0,wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND,5);
MainSizer->Add(ButtonSizer,0,wxALIGN_RIGHT | wxLEFT | wxBOTTOM | wxRIGHT,5);
// Set sizer
SetSizer(MainSizer);
MainSizer->SetSizeHints(this);
// Position window
if (lastx == -1 && lasty == -1) {
CenterOnParent();
} else {
Move(lastx, lasty);
} }
// Set subs/grid {
JumpToLine(startrow,0); translated_text = new ScintillaTextCtrl(this, -1, "", wxDefaultPosition, wxSize(320, 80));
UpdatePreview(); translated_text->SetWrapMode(wxSTC_WRAP_WORD);
translated_text->SetMarginWidth(1, 0);
translated_text->SetFocus();
translated_text->Bind(wxEVT_KEY_DOWN, &DialogTranslation::OnKeyDown, this);
wxSizer *translated_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Translation"));
translated_box->Add(translated_text, 1, wxEXPAND, 0);
translation_sizer->Add(translated_box, 1, wxTOP|wxEXPAND, 5);
}
main_sizer->Add(translation_sizer, 1, wxALL | wxEXPAND, 5);
wxSizer *right_box = new wxBoxSizer(wxHORIZONTAL);
{
wxSizer *hotkey_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Keys"));
wxSizer *hotkey_grid = new wxGridSizer(2, 0, 5);
add_hotkey(hotkey_grid, this, "tool/translation_assistant/commit", "Accept changes");
add_hotkey(hotkey_grid, this, "tool/translation_assistant/preview", "Preview changes");
add_hotkey(hotkey_grid, this, "tool/translation_assistant/prev", "Previous line");
add_hotkey(hotkey_grid, this, "tool/translation_assistant/next", "Next line");
add_hotkey(hotkey_grid, this, "tool/translation_assistant/insert_original", "Insert original");
add_hotkey(hotkey_grid, this, "video/play/line", "Play Video");
add_hotkey(hotkey_grid, this, "audio/play/selection", "Play Audio");
hotkey_box->Add(hotkey_grid, 0, wxEXPAND, 0);
seek_video = new wxCheckBox(this, -1, _("Enable preview"));
seek_video->SetValue(true);
hotkey_box->Add(seek_video, 0, wxTOP, 5);
right_box->Add(hotkey_box, 1, wxRIGHT | wxEXPAND, 5);
} }
{
wxStaticBoxSizer *actions_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Actions"));
wxButton *play_audio = new wxButton(this, -1, _("Play Audio"));
play_audio->Enable(c->audioController->IsAudioOpen());
play_audio->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogTranslation::OnPlayAudioButton, this);
actions_box->Add(play_audio, 0, wxALL, 5);
/// @brief Jumps to line at block wxButton *play_video = new wxButton(this, -1, _("Play Video"));
/// @param n play_video->Enable(c->videoController->IsLoaded());
/// @param block play_video->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogTranslation::OnPlayVideoButton, this);
/// @return actions_box->Add(play_video, 0, wxLEFT | wxRIGHT | wxBOTTOM, 5);
///
bool DialogTranslation::JumpToLine(int n,int block) { right_box->Add(actions_box, 0);
using std::vector; }
AssDialogue *nextLine; main_sizer->Add(right_box, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5);
try {
nextLine = grid->GetDialogue(n); {
} catch (...) { wxStdDialogButtonSizer *standard_buttons = new wxStdDialogButtonSizer();
standard_buttons->AddButton(new wxButton(this, wxID_CANCEL));
standard_buttons->AddButton(new HelpButton(this, "Translation Assistant"));
standard_buttons->Realize();
main_sizer->Add(standard_buttons, 0, wxALIGN_RIGHT | wxLEFT | wxBOTTOM | wxRIGHT, 5);
}
SetSizer(main_sizer);
main_sizer->SetSizeHints(this);
persist.reset(new PersistLocation(this, "Tool/Translation Assistant"));
Bind(wxEVT_KEY_DOWN, &DialogTranslation::OnKeyDown, this);
active_line->ParseASSTags();
UpdateDisplay();
}
DialogTranslation::~DialogTranslation() { }
// Skip over override blocks, comments, and whitespace between blocks
static bool bad_block(AssDialogueBlock *block) {
if (block->GetType() != BLOCK_PLAIN) return true;
wxString text = block->GetText();
if (text.Trim().Trim(false).empty()) return true;
if (text[0] == '{' && text.Last() == '}') return true;
return false; return false;
} }
if (!nextLine) return false;
current = nextLine;
// Count blocks bool DialogTranslation::NextBlock() {
int nblocks = 0; do {
current->ParseASSTags(); if (cur_block == active_line->Blocks.size() - 1) {
size_t size_blocks = current->Blocks.size(); c->selectionController->NextLine();
for (size_t i=0;i<size_blocks;i++) { AssDialogue *new_line = c->selectionController->GetActiveLine();
if (current->Blocks.at(i)->GetType() == BLOCK_PLAIN) nblocks++; if (active_line == new_line || !new_line) return false;
}
// Wrap around active_line->ClearBlocks();
if (block == 0xFFFF) block = nblocks-1; active_line = new_line;
if (block < 0) { active_line->ParseASSTags();
block = 0xFFFF; cur_block = 0;
n--; ++line_number;
return JumpToLine(n,block);
}
if (block >= nblocks) {
block = 0;
n++;
return JumpToLine(n,block);
} }
else
++cur_block;
} while (bad_block(active_line->Blocks[cur_block]));
// Set current UpdateDisplay();
curline = n;
current = grid->GetDialogue(n);
curblock = block;
LineCount->SetLabel(wxString::Format(_("Current line: %i/%i"),curline+1,grid->GetRows()));
// Update grid
grid->BeginBatch();
grid->SelectRow(curline);
grid->MakeCellVisible(curline,0);
grid->SetActiveLine(current);
grid->EndBatch();
// Adds blocks
OrigText->SetReadOnly(false);
OrigText->ClearAll();
AssDialogueBlock *curBlock;
bool found = false;
int pos=-1;
for (vector<AssDialogueBlock*>::iterator cur=current->Blocks.begin();cur!=current->Blocks.end();cur++) {
curBlock = *cur;
if (curBlock->GetType() == BLOCK_PLAIN) {
pos++;
int curLen = OrigText->GetReverseUnicodePosition(OrigText->GetLength());
OrigText->AppendText(curBlock->text);
if (pos == block) {
OrigText->StartUnicodeStyling(curLen);
OrigText->SetUnicodeStyling(curLen,curBlock->text.Length(),1);
found = true;
}
}
else if (curBlock->GetType() == BLOCK_OVERRIDE) OrigText->AppendText(_T("{") + curBlock->text + _T("}"));
}
current->ClearBlocks();
OrigText->SetReadOnly(true);
return true; return true;
} }
bool DialogTranslation::PrevBlock() {
do {
if (cur_block == 0) {
c->selectionController->PrevLine();
AssDialogue *new_line = c->selectionController->GetActiveLine();
if (active_line == new_line || !new_line) return false;
active_line->ClearBlocks();
active_line = new_line;
active_line->ParseASSTags();
cur_block = active_line->Blocks.size() - 1;
--line_number;
}
else
--cur_block;
} while (bad_block(active_line->Blocks[cur_block]));
/// @brief Updates video preview UpdateDisplay();
/// @return return true;
///
void DialogTranslation::UpdatePreview () {
if (enablePreview) {
try {
if (video->IsLoaded()) {
AssDialogue *cur = grid->GetDialogue(curline);
video->JumpToTime(cur->Start.GetMS());
}
}
catch (...) {
return;
}
}
} }
/////////////// void DialogTranslation::UpdateDisplay() {
// Event table line_number_display->SetLabel(wxString::Format(_("Current line: %d/%d"), line_number, line_count));
BEGIN_EVENT_TABLE(DialogTranslation, wxDialog)
EVT_BUTTON(wxID_CANCEL,DialogTranslation::OnClose)
EVT_BUTTON(BUTTON_TRANS_PLAY_VIDEO,DialogTranslation::OnPlayVideoButton)
EVT_BUTTON(BUTTON_TRANS_PLAY_AUDIO,DialogTranslation::OnPlayAudioButton)
END_EVENT_TABLE()
original_text->SetReadOnly(false);
original_text->ClearAll();
///////////////// for (size_t i = 0; i < active_line->Blocks.size(); ++i) {
// Event handler AssDialogueBlock *block = active_line->Blocks[i];
if (block->GetType() == BLOCK_PLAIN) {
int cur_size = original_text->GetReverseUnicodePosition(original_text->GetLength());
/// @brief Constructor original_text->AppendText(block->text);
/// @param ctrl if (i == cur_block) {
/// original_text->StartUnicodeStyling(cur_size);
DialogTranslationEvent::DialogTranslationEvent(DialogTranslation *ctrl) { original_text->SetUnicodeStyling(cur_size, block->text.size(), 1);
control = ctrl;
}
// Event table
BEGIN_EVENT_TABLE(DialogTranslationEvent, wxEvtHandler)
EVT_KEY_DOWN(DialogTranslationEvent::OnTransBoxKey)
EVT_CHECKBOX(PREVIEW_CHECK, DialogTranslationEvent::OnPreviewCheck)
END_EVENT_TABLE()
/// @brief Redirects
/// @param event
///
void DialogTranslationEvent::OnPreviewCheck(wxCommandEvent &event) { control->enablePreview = event.IsChecked(); }
/// @brief DOCME
/// @param event
///
void DialogTranslationEvent::OnTransBoxKey(wxKeyEvent &event) { control->OnTransBoxKey(event); }
/// @brief Key pressed event
/// @param event
/// @return
///
void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) {
if (!hotkey::check("Translation Assistant", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip();
event.StopPropagation();
// H convert below to commands.
/*
#ifdef __APPLE__
Hotkeys.SetPressed(event.GetKeyCode(),event.m_metaDown,event.m_altDown,event.m_shiftDown);
#else
Hotkeys.SetPressed(event.GetKeyCode(),event.m_controlDown,event.m_altDown,event.m_shiftDown);
#endif
// Previous
if (Hotkeys.IsPressed(_T("Translation Assistant Prev"))) {
bool ok = JumpToLine(curline,curblock-1);
if (ok) {
TransText->ClearAll();
TransText->SetFocus();
}
UpdatePreview();
return;
}
// Next
if (Hotkeys.IsPressed(_T("Translation Assistant Next")) || (Hotkeys.IsPressed(_T("Translation Assistant Accept")) && TransText->GetValue().IsEmpty())) {
bool ok = JumpToLine(curline,curblock+1);
if (ok) {
TransText->ClearAll();
TransText->SetFocus();
}
UpdatePreview();
return;
}
// Accept (enter)
if (Hotkeys.IsPressed(_T("Translation Assistant Accept")) || Hotkeys.IsPressed(_T("Translation Assistant Preview"))) {
// Store
AssDialogue *cur = grid->GetDialogue(curline);
cur->ParseASSTags();
int nblock = -1;
for (unsigned int i=0;i<cur->Blocks.size();i++) {
if (cur->Blocks.at(i)->GetType() == BLOCK_PLAIN) nblock++;
if (nblock == curblock) {
cur->Blocks.at(i)->text = TransText->GetValue();
break;
} }
} }
else if (block->GetType() == BLOCK_OVERRIDE)
original_text->AppendText("{" + block->text + "}");
}
// Update line original_text->SetReadOnly(true);
cur->UpdateText();
cur->ClearBlocks();
subs->Commit(_("translation assistant"), AssFile::COMMIT_TEXT);
UpdatePreview();
// Next if (seek_video->IsChecked()) c->videoController->JumpToTime(active_line->Start.GetMS());
if (Hotkeys.IsPressed(_T("Translation Assistant Accept"))) {
// JumpToLine() returns false if the requested line doesn't exist. translated_text->ClearAll();
// Assume that means we were on the last line. translated_text->SetFocus();
if (!JumpToLine(curline,curblock+1)) { }
void DialogTranslation::Commit(bool next) {
active_line->Blocks[cur_block]->text = translated_text->GetValue();
active_line->UpdateText();
c->ass->Commit(_("translation assistant"), AssFile::COMMIT_TEXT);
if (next) {
if (!NextBlock()) {
wxMessageBox(_("No more lines to translate.")); wxMessageBox(_("No more lines to translate."));
EndModal(1); EndModal(1);
return;
} }
TransText->ClearAll();
TransText->SetFocus();
} }
else JumpToLine(curline,curblock); else {
return; UpdateDisplay();
}
} }
// Insert original text (insert) void DialogTranslation::InsertOriginal() {
if (Hotkeys.IsPressed(_T("Translation Assistant Insert Original"))) { translated_text->AddText(active_line->Blocks[cur_block]->GetText());
using std::vector;
AssDialogueBlock *curBlock;
int pos = -1;
current->ParseASSTags();
for (vector<AssDialogueBlock*>::iterator cur=current->Blocks.begin();cur!=current->Blocks.end();cur++) {
curBlock = *cur;
if (curBlock->GetType() == BLOCK_PLAIN) {
pos++;
if (pos == curblock) {
TransText->AddText(curBlock->text);
}
}
}
current->ClearBlocks();
return;
}
// Play video
if (Hotkeys.IsPressed(_T("Translation Assistant Play Video"))) {
if (video->IsLoaded()) {
video->PlayLine();
TransText->SetFocus();
}
return;
}
// Play audio
if (Hotkeys.IsPressed(_T("Translation Assistant Play Audio"))) {
/// @todo Reinstate this when the audio controller is made reachable from here
//if (audio->loaded) {
// audio->Play(current->Start.GetMS(),current->End.GetMS());
// TransText->SetFocus();
//}
return;
}
// Close
if (event.GetKeyCode() == WXK_ESCAPE) EndModal(1);
// Ignore enter
if (event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) return;
// Skip anything else
event.Skip();
*/
} }
void DialogTranslation::OnKeyDown(wxKeyEvent &evt) {
/// @brief Play video button if (!hotkey::check("Translation Assistant", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers()))
/// @param event evt.Skip();
/// evt.StopPropagation();
void DialogTranslation::OnPlayVideoButton(wxCommandEvent &event) {
video->PlayLine();
TransText->SetFocus();
} }
void DialogTranslation::OnPlayVideoButton(wxCommandEvent &) {
c->videoController->PlayLine();
/// @brief Play audio button translated_text->SetFocus();
/// @param event
///
void DialogTranslation::OnPlayAudioButton(wxCommandEvent &event) {
audio->PlayRange(SampleRange(
audio->SamplesFromMilliseconds(current->Start.GetMS()),
audio->SamplesFromMilliseconds(current->End.GetMS())));
TransText->SetFocus();
} }
void DialogTranslation::OnPlayAudioButton(wxCommandEvent &) {
cmd::call("audio/play/selection", c);
/// @brief Close translated_text->SetFocus();
/// @param event
///
void DialogTranslation::OnClose (wxCommandEvent &event) {
GetPosition(&lastx, &lasty);
TransText->PopEventHandler(true);
PreviewCheck->PopEventHandler(true);
EndModal(0);
} }
/// @brief Minimize
/// @param event
///
void DialogTranslation::OnMinimize (wxIconizeEvent &event) {
//Iconize(true);
if (main) ((wxFrame*)main)->Iconize(true);
event.Skip();
}
/// DOCME
int DialogTranslation::lastx = -1;
/// DOCME
int DialogTranslation::lasty = -1;

View file

@ -1,29 +1,16 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro // Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
// All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Permission to use, copy, modify, and distribute this software for any
// modification, are permitted provided that the following conditions are met: // purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
// //
// * Redistributions of source code must retain the above copyright notice, // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// this list of conditions and the following disclaimer. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// * Redistributions in binary form must reproduce the above copyright notice, // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// this list of conditions and the following disclaimer in the documentation // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// and/or other materials provided with the distribution. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// * Neither the name of the Aegisub Group nor the names of its contributors // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// may be used to endorse or promote products derived from this software // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// //
// Aegisub Project http://www.aegisub.org/ // Aegisub Project http://www.aegisub.org/
// //
@ -31,118 +18,57 @@
/// @file dialog_translation.h /// @file dialog_translation.h
/// @see dialog_translation.cpp /// @see dialog_translation.cpp
/// @ingroup tools_ui/// /// @ingroup tools_ui
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/checkbox.h>
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/stattext.h>
#endif #endif
#include <libaegisub/scoped_ptr.h>
namespace agi { struct Context; } namespace agi { struct Context; }
class AssDialogue; class AssDialogue;
class AssFile; class PersistLocation;
class AudioController;
class AudioDisplay;
class ScintillaTextCtrl; class ScintillaTextCtrl;
class SubtitlesGrid; class wxStaticText;
class VideoContext; class wxCheckBox;
/// DOCME
/// @class DialogTranslation /// @class DialogTranslation
/// @brief DOCME /// @brief Assistant for translating subtitles in one language to another language
/// ///
/// DOCME /// DOCME
class DialogTranslation : public wxDialog { class DialogTranslation : public wxDialog {
private: agi::Context *c;
/// DOCME /// The active line
AudioController *audio; AssDialogue *active_line;
/// Which dialogue block in the active line is currrently being translated
size_t cur_block;
/// DOCME /// Total number of dialogue lines in the file
VideoContext *video; size_t line_count;
/// Line number of the currently active line
size_t line_number;
/// DOCME wxStaticText *line_number_display;
AssFile *subs; ScintillaTextCtrl *original_text;
ScintillaTextCtrl *translated_text;
wxCheckBox *seek_video;
/// DOCME agi::scoped_ptr<PersistLocation> persist;
SubtitlesGrid *grid;
/// DOCME void OnPlayAudioButton(wxCommandEvent &);
AssDialogue *current; void OnPlayVideoButton(wxCommandEvent &);
void OnKeyDown(wxKeyEvent &evt);
/// DOCME void UpdateDisplay();
wxWindow *main;
/// DOCME
int curline;
/// DOCME
int curblock;
/// DOCME
wxStaticText *LineCount;
/// DOCME
ScintillaTextCtrl *OrigText;
/// DOCME
ScintillaTextCtrl *TransText;
/// DOCME
wxCheckBox *PreviewCheck;
void OnMinimize(wxIconizeEvent &event);
void OnPlayAudioButton(wxCommandEvent &event);
void OnPlayVideoButton(wxCommandEvent &event);
void OnClose(wxCommandEvent &event);
bool JumpToLine(int n,int block);
void UpdatePreview();
/// DOCME
/// DOCME
static int lastx, lasty;
public: public:
DialogTranslation(agi::Context *context);
~DialogTranslation();
/// DOCME bool NextBlock();
bool enablePreview; bool PrevBlock();
DialogTranslation(agi::Context *context, int startrow=0, bool preview=false); void Commit(bool next);
void InsertOriginal();
void OnTransBoxKey(wxKeyEvent &event);
DECLARE_EVENT_TABLE()
};
/// DOCME
/// @class DialogTranslationEvent
/// @brief DOCME
///
/// DOCME
class DialogTranslationEvent : public wxEvtHandler {
private:
/// DOCME
DialogTranslation *control;
void OnPreviewCheck(wxCommandEvent &event);
void OnTransBoxKey(wxKeyEvent &event);
public:
DialogTranslationEvent(DialogTranslation *control);
DECLARE_EVENT_TABLE()
};
/// Event IDs
enum {
TEXT_ORIGINAL = 1100,
TEXT_TRANS,
PREVIEW_CHECK,
BUTTON_TRANS_PLAY_AUDIO,
BUTTON_TRANS_PLAY_VIDEO
}; };

View file

@ -4,6 +4,7 @@ class AudioController;
class AssDialogue; class AssDialogue;
class DialogDetachedVideo; class DialogDetachedVideo;
class DialogStyling; class DialogStyling;
class DialogTranslation;
template<class T> class SelectionController; template<class T> class SelectionController;
class SubsEditBox; class SubsEditBox;
class SubtitlesGrid; class SubtitlesGrid;
@ -32,6 +33,7 @@ struct Context {
AudioBox *audioBox; AudioBox *audioBox;
DialogDetachedVideo *detachedVideo; DialogDetachedVideo *detachedVideo;
DialogStyling *stylingAssistant; DialogStyling *stylingAssistant;
DialogTranslation *translationAssistant;
SubsEditBox *editBox; SubsEditBox *editBox;
SubtitlesGrid *subsGrid; SubtitlesGrid *subsGrid;
VideoBox *videoBox; VideoBox *videoBox;

View file

@ -374,6 +374,13 @@
"Key Start Before" : 5 "Key Start Before" : 5
} }
}, },
"Translation Assistant" : {
"Last" : {
"X" : -1,
"Y" : -1
},
"Maximized" : false
},
"Visual" : { "Visual" : {
"Always Show": true "Always Show": true
} }

View file

@ -579,43 +579,43 @@
}, },
"Translation Assistant" : { "Translation Assistant" : {
"audio play" : [ "audio/play/selection" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "End" "key" : "End"
} }
], ],
"translation assiatant prev item" : [ "tool/translation_assistant/prev" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "PageUp" "key" : "PageUp"
} }
], ],
"translation assistant commit" : [ "tool/translation_assistant/commit" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "Enter" "key" : "Enter"
} }
], ],
"translation assistant insert original" : [ "tool/translation_assistant/insert_original" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "Insert" "key" : "Insert"
} }
], ],
"translation assistant next item" : [ "tool/translation_assistant/next" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "PageDown" "key" : "PageDown"
} }
], ],
"translation assistant preview" : [ "tool/translation_assistant/preview" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "F8" "key" : "F8"
} }
], ],
"video/play" : [ "video/play/line" : [
{ {
"modifiers" : [], "modifiers" : [],
"key" : "Home" "key" : "Home"