Make the subtitle edit box auto-commit all changes

This happens to fix most of the undo issues, as it's now much harder to
have uncommitted changes to the file.

Closes #355 and #586.

Originally committed to SVN as r4699.
This commit is contained in:
Thomas Goyne 2010-07-20 03:11:11 +00:00
parent 51a75cd0fd
commit fde4a7815d
41 changed files with 1120 additions and 2933 deletions

View File

@ -671,14 +671,6 @@
RelativePath="..\..\src\help_button.h" RelativePath="..\..\src\help_button.h"
> >
</File> </File>
<File
RelativePath="..\..\src\hilimod_textctrl.cpp"
>
</File>
<File
RelativePath="..\..\src\hilimod_textctrl.h"
>
</File>
<File <File
RelativePath="..\..\src\scintilla_text_ctrl.cpp" RelativePath="..\..\src\scintilla_text_ctrl.cpp"
> >
@ -819,14 +811,6 @@
RelativePath="..\..\src\font_file_lister_freetype.h" RelativePath="..\..\src\font_file_lister_freetype.h"
> >
</File> </File>
<File
RelativePath="..\..\src\idle_field_event.cpp"
>
</File>
<File
RelativePath="..\..\src\idle_field_event.h"
>
</File>
<File <File
RelativePath="..\..\src\kana_table.cpp" RelativePath="..\..\src\kana_table.cpp"
> >

View File

@ -22,8 +22,10 @@
#ifndef LAGI_PRE #ifndef LAGI_PRE
#include <algorithm> #include <algorithm>
#include <cmath>
#include <functional> #include <functional>
#include <iterator> #include <iterator>
#include <list>
#include <numeric> #include <numeric>
#endif #endif

View File

@ -72,17 +72,20 @@
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <map> #include <map>
#ifdef _WIN32
#include <memory>
#else
#include <tr1/memory>
#endif
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector> #include <vector>
#ifdef _WIN32
#include <functional>
#include <memory>
#else
#include <tr1/functional>
#include <tr1/memory>
#endif
#include "boost/shared_ptr.hpp" #include "boost/shared_ptr.hpp"
// General headers // General headers

View File

@ -221,6 +221,8 @@ public:
/// Do nothing /// Do nothing
void SetEntryData(wxString) { } void SetEntryData(wxString) { }
template<int which>
void SetMarginString(const wxString value) { SetMarginString(value, which);}
/// @brief Set a margin /// @brief Set a margin
/// @param value New value of the margin /// @param value New value of the margin
/// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom /// @param which 0 = left, 1 = right, 2 = vertical/top, 3 = bottom

View File

@ -78,6 +78,7 @@ AssFile::~AssFile() {
delete_clear(Line); delete_clear(Line);
} }
/// @brief Load generic subs
void AssFile::Load (const wxString &_filename,wxString charset,bool addToRecent) { void AssFile::Load (const wxString &_filename,wxString charset,bool addToRecent) {
bool ok = false; bool ok = false;
Clear(); Clear();
@ -447,11 +448,11 @@ void AssFile::LoadDefault (bool defline) {
AddLine(_T("PlayResX: 640"),_T("[Script Info]"),version); AddLine(_T("PlayResX: 640"),_T("[Script Info]"),version);
AddLine(_T("PlayResY: 480"),_T("[Script Info]"),version); AddLine(_T("PlayResY: 480"),_T("[Script Info]"),version);
AddLine(_T("ScaledBorderAndShadow: yes"),_T("[Script Info]"),version); AddLine(_T("ScaledBorderAndShadow: yes"),_T("[Script Info]"),version);
AddLine(_T(""),_T("[Script Info]"),version); AddLine("",_T("[Script Info]"),version);
AddLine(_T("[V4+ Styles]"),_T("[V4+ Styles]"),version); AddLine(_T("[V4+ Styles]"),_T("[V4+ Styles]"),version);
AddLine(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"),_T("[V4+ Styles]"),version); AddLine(_T("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"),_T("[V4+ Styles]"),version);
AddLine(defstyle.GetEntryData(),_T("[V4+ Styles]"),version); AddLine(defstyle.GetEntryData(),_T("[V4+ Styles]"),version);
AddLine(_T(""),_T("[V4+ Styles]"),version); AddLine("",_T("[V4+ Styles]"),version);
AddLine(_T("[Events]"),_T("[Events]"),version); AddLine(_T("[Events]"),_T("[Events]"),version);
AddLine(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"),_T("[Events]"),version); AddLine(_T("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"),_T("[Events]"),version);
@ -506,7 +507,7 @@ void AssFile::InsertStyle (AssStyle *style) {
// No styles found, add them // No styles found, add them
if (lastStyle == Line.end()) { if (lastStyle == Line.end()) {
// Add space // Add space
curEntry = new AssEntry(_T("")); curEntry = new AssEntry("");
curEntry->group = lastGroup; curEntry->group = lastGroup;
Line.push_back(curEntry); Line.push_back(curEntry);
@ -559,10 +560,10 @@ void AssFile::InsertAttachment (AssAttachment *attach) {
// Otherwise, create the [Fonts] group and insert // Otherwise, create the [Fonts] group and insert
else { else {
int version=1; int version=1;
AddLine(_T(""),Line.back()->group,version); AddLine("",Line.back()->group,version);
AddLine(attach->group,attach->group,version); AddLine(attach->group,attach->group,version);
Line.push_back(attach); Line.push_back(attach);
AddLine(_T(""),attach->group,version); AddLine("",attach->group,version);
} }
} }
@ -640,7 +641,7 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
// Found // Found
if (curText.StartsWith(key)) { if (curText.StartsWith(key)) {
// Set value // Set value
if (value != _T("")) { if (value != "") {
wxString result = _key; wxString result = _key;
result += _T(": "); result += _T(": ");
result += value; result += value;
@ -660,7 +661,7 @@ void AssFile::SetScriptInfo(const wxString _key,const wxString value) {
// Add // Add
else if (GotIn) { else if (GotIn) {
if (value != _T("")) { if (value != "") {
wxString result = _key; wxString result = _key;
result += _T(": "); result += _T(": ");
result += value; result += value;
@ -762,7 +763,7 @@ wxString AssFile::GetWildcardList(int mode) {
if (mode == 0) return SubtitleFormat::GetWildcards(0); if (mode == 0) return SubtitleFormat::GetWildcards(0);
else if (mode == 1) return _T("Advanced Substation Alpha (*.ass)|*.ass"); else if (mode == 1) return _T("Advanced Substation Alpha (*.ass)|*.ass");
else if (mode == 2) return SubtitleFormat::GetWildcards(1); else if (mode == 2) return SubtitleFormat::GetWildcards(1);
else return _T(""); else return "";
} }
int AssFile::Commit(wxString desc, int amendId) { int AssFile::Commit(wxString desc, int amendId) {
@ -844,9 +845,7 @@ void AssFile::Sort(std::list<AssEntry*> &lst, CompFunc comp) {
entryIter end = begin; entryIter end = begin;
while (end != lst.end() && dynamic_cast<AssDialogue*>(*end)) ++end; while (end != lst.end() && dynamic_cast<AssDialogue*>(*end)) ++end;
// std::list::sort doesn't support sorting only part of the list, but // used instead of std::list::sort for partial list sorting
// splice is constant-time, so just sort a temp list with only the part we
// want sorted
std::list<AssEntry*> tmp; std::list<AssEntry*> tmp;
tmp.splice(tmp.begin(), lst, begin, end); tmp.splice(tmp.begin(), lst, begin, end);
tmp.sort(compE); tmp.sort(compE);

View File

@ -322,6 +322,13 @@ bool operator != (const AssTime &t1, const AssTime &t2) {
return (t1.GetMS() != t2.GetMS()); return (t1.GetMS() != t2.GetMS());
} }
AssTime operator + (const AssTime &t1, const AssTime &t2) {
return AssTime(t1.GetMS() + t2.GetMS());
}
AssTime operator - (const AssTime &t1, const AssTime &t2) {
return AssTime(t1.GetMS() - t2.GetMS());
}
/// DOCME /// DOCME

View File

@ -72,8 +72,8 @@ public:
int GetTimeMiliseconds(); int GetTimeMiliseconds();
int GetTimeCentiseconds(); int GetTimeCentiseconds();
int GetMS() const; // Returns miliseconds int GetMS() const; // Returns milliseconds
void SetMS(int ms); // Sets values to miliseconds void SetMS(int ms); // Sets values to milliseconds
void ParseASS(const wxString text); // Sets value to text-form time, in ASS format void ParseASS(const wxString text); // Sets value to text-form time, in ASS format
void ParseSRT(const wxString text); // Sets value to text-form time, in SRT format void ParseSRT(const wxString text); // Sets value to text-form time, in SRT format
wxString GetASSFormated(bool ms=false) const; // Returns the ASS representation of time wxString GetASSFormated(bool ms=false) const; // Returns the ASS representation of time
@ -87,6 +87,9 @@ bool operator < (const AssTime &t1, const AssTime &t2);
bool operator > (const AssTime &t1, const AssTime &t2); bool operator > (const AssTime &t1, const AssTime &t2);
bool operator <= (const AssTime &t1, const AssTime &t2); bool operator <= (const AssTime &t1, const AssTime &t2);
bool operator >= (const AssTime &t1, const AssTime &t2); bool operator >= (const AssTime &t1, const AssTime &t2);
// Arithmetic operators
AssTime operator + (const AssTime &t1, const AssTime &t2);
AssTime operator - (const AssTime &t1, const AssTime &t2);

View File

@ -61,6 +61,7 @@
#include "main.h" #include "main.h"
#include "standard_paths.h" #include "standard_paths.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "timeedit_ctrl.h" #include "timeedit_ctrl.h"
#include "utils.h" #include "utils.h"
@ -2320,8 +2321,8 @@ void AudioDisplay::OnLoseFocus(wxFocusEvent &event) {
/// @brief Update time edit controls /// @brief Update time edit controls
void AudioDisplay::UpdateTimeEditCtrls() { void AudioDisplay::UpdateTimeEditCtrls() {
grid->editBox->StartTime->SetTime(curStartMS,true); grid->editBox->StartTime->SetTime(curStartMS);
grid->editBox->EndTime->SetTime(curEndMS,true); grid->editBox->EndTime->SetTime(curEndMS);
grid->editBox->Duration->SetTime(curEndMS-curStartMS,true); grid->editBox->Duration->SetTime(curEndMS-curStartMS);
} }

View File

@ -42,11 +42,12 @@
#include <wx/sizer.h> #include <wx/sizer.h>
#endif #endif
#include "base_grid.h"
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "ass_style.h" #include "ass_style.h"
#include "audio_display.h" #include "audio_display.h"
#include "base_grid.h"
#include "compat.h" #include "compat.h"
#include "frame_main.h" #include "frame_main.h"
#include "main.h" #include "main.h"
@ -1112,10 +1113,10 @@ int BaseGrid::GetDialogueIndex(AssDialogue *diag) const {
bool BaseGrid::IsDisplayed(AssDialogue *line) { bool BaseGrid::IsDisplayed(AssDialogue *line) {
VideoContext* con = VideoContext::Get(); VideoContext* con = VideoContext::Get();
if (!con->IsLoaded()) return false; if (!con->IsLoaded()) return false;
int f1 = con->FrameAtTime(line->Start.GetMS(),agi::vfr::START); int frame = con->GetFrameN();
int f2 = con->FrameAtTime(line->End.GetMS(),agi::vfr::END); return
if (f1 <= con->GetFrameN() && f2 >= con->GetFrameN()) return true; con->FrameAtTime(line->Start.GetMS(),agi::vfr::START) <= frame &&
return false; con->FrameAtTime(line->End.GetMS(),agi::vfr::END) >= frame;
} }
/// @brief Key press /// @brief Key press

View File

@ -46,7 +46,6 @@
#include "dialog_resample.h" #include "dialog_resample.h"
#include "help_button.h" #include "help_button.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "validators.h" #include "validators.h"
@ -323,7 +322,6 @@ void DialogResample::OnResample (wxCommandEvent &event) {
// Flag as modified // Flag as modified
subs->Commit(_("resolution resampling")); subs->Commit(_("resolution resampling"));
grid->CommitChanges(); grid->CommitChanges();
grid->editBox->Update();
EndModal(0); EndModal(0);
} }

View File

@ -51,6 +51,7 @@
#include "frame_main.h" #include "frame_main.h"
#include "main.h" #include "main.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "video_display.h" #include "video_display.h"
@ -545,7 +546,6 @@ void SearchReplaceEngine::ReplaceAll() {
if (count > 0) { if (count > 0) {
grid->ass->Commit(_("replace")); grid->ass->Commit(_("replace"));
grid->CommitChanges(); grid->CommitChanges();
grid->editBox->Update();
wxMessageBox(wxString::Format(_("%i matches were replaced."),count)); wxMessageBox(wxString::Format(_("%i matches were replaced."),count));
} }

View File

@ -57,7 +57,6 @@
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "main.h" #include "main.h"
#include "standard_paths.h" #include "standard_paths.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_context.h" #include "video_context.h"
@ -312,7 +311,6 @@ void DialogShiftTimes::OnOK(wxCommandEvent &event) {
// End dialog // End dialog
grid->ass->Commit(_("shifting")); grid->ass->Commit(_("shifting"));
grid->CommitChanges(); grid->CommitChanges();
grid->editBox->Update();
EndModal(0); EndModal(0);
} }

View File

@ -52,6 +52,7 @@
#include "main.h" #include "main.h"
#include "spellchecker_manager.h" #include "spellchecker_manager.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"

View File

@ -52,6 +52,7 @@
#include "hotkeys.h" #include "hotkeys.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_context.h" #include "video_context.h"

View File

@ -33,26 +33,17 @@
/// @see dialog_translation.cpp /// @see dialog_translation.cpp
/// @ingroup tools_ui/// /// @ingroup tools_ui///
///////////
// Headers
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/checkbox.h> #include <wx/checkbox.h>
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/stattext.h> #include <wx/stattext.h>
#endif #endif
#include "scintilla_text_ctrl.h"
//////////////
// Prototypes
class AssFile; class AssFile;
class AssDialogue; class AssDialogue;
class SubtitlesGrid;
class AudioDisplay; class AudioDisplay;
class ScintillaTextCtrl;
class SubtitlesGrid;
class VideoContext; class VideoContext;
@ -126,8 +117,6 @@ public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// DOCME /// DOCME
/// @class DialogTranslationEvent /// @class DialogTranslationEvent
/// @brief DOCME /// @brief DOCME
@ -147,23 +136,11 @@ public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// Event IDs
///////
// IDs
enum { enum {
/// DOCME
TEXT_ORIGINAL = 1100, TEXT_ORIGINAL = 1100,
/// DOCME
TEXT_TRANS, TEXT_TRANS,
/// DOCME
PREVIEW_CHECK, PREVIEW_CHECK,
/// DOCME
BUTTON_TRANS_PLAY_AUDIO, BUTTON_TRANS_PLAY_AUDIO,
/// DOCME
BUTTON_TRANS_PLAY_VIDEO BUTTON_TRANS_PLAY_VIDEO
}; };

View File

@ -73,6 +73,7 @@
#include "main.h" #include "main.h"
#include "standard_paths.h" #include "standard_paths.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "text_file_reader.h" #include "text_file_reader.h"
#include "text_file_writer.h" #include "text_file_writer.h"
@ -604,8 +605,7 @@ void FrameMain::InitContents() {
// Top sizer // Top sizer
StartupLog(_T("Create subtitle editing box")); StartupLog(_T("Create subtitle editing box"));
EditBox = new SubsEditBox(Panel,SubsGrid); EditBox = new SubsEditBox(Panel,SubsGrid, audioBox->audioDisplay);
EditBox->audio = audioBox->audioDisplay;
StartupLog(_T("Arrange controls in sizers")); StartupLog(_T("Arrange controls in sizers"));
ToolSizer = new wxBoxSizer(wxVERTICAL); ToolSizer = new wxBoxSizer(wxVERTICAL);
ToolSizer->Add(audioBox,0,wxEXPAND | wxBOTTOM,5); ToolSizer->Add(audioBox,0,wxEXPAND | wxBOTTOM,5);
@ -863,7 +863,6 @@ void FrameMain::SetDisplayMode(int video, int audio) {
// Update // Update
UpdateToolbar(); UpdateToolbar();
EditBox->SetSplitLineMode();
MainSizer->CalcMin(); MainSizer->CalcMin();
MainSizer->RecalcSizes(); MainSizer->RecalcSizes();
MainSizer->Layout(); MainSizer->Layout();
@ -1138,7 +1137,7 @@ void FrameMain::LoadVideo(wxString file,bool autoload) {
} }
} }
SubsGrid->CommitChanges(true); SubsGrid->CommitChanges();
SetDisplayMode(1,-1); SetDisplayMode(1,-1);
EditBox->UpdateFrameTiming(); EditBox->UpdateFrameTiming();
@ -1229,7 +1228,6 @@ void FrameMain::SetAccelerators() {
entry.push_back(Hotkeys.GetAccelerator(_T("Video global zoom in"),Menu_Video_Zoom_In)); entry.push_back(Hotkeys.GetAccelerator(_T("Video global zoom in"),Menu_Video_Zoom_In));
entry.push_back(Hotkeys.GetAccelerator(_T("Video global zoom out"),Menu_Video_Zoom_Out)); entry.push_back(Hotkeys.GetAccelerator(_T("Video global zoom out"),Menu_Video_Zoom_Out));
entry.push_back(Hotkeys.GetAccelerator(_T("Video global play"),Video_Frame_Play)); entry.push_back(Hotkeys.GetAccelerator(_T("Video global play"),Video_Frame_Play));
entry.push_back(Hotkeys.GetAccelerator(_T("Edit box commit"),Edit_Box_Commit));
// Medusa // Medusa
bool medusaPlay = OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool(); bool medusaPlay = OPT_GET("Audio/Medusa Timing Hotkeys")->GetBool();

View File

@ -266,7 +266,6 @@ private:
void OnSortStart (wxCommandEvent &event); void OnSortStart (wxCommandEvent &event);
void OnSortEnd (wxCommandEvent &event); void OnSortEnd (wxCommandEvent &event);
void OnSortStyle (wxCommandEvent &event); void OnSortStyle (wxCommandEvent &event);
void OnEditBoxCommit (wxCommandEvent &event);
void OnOpenProperties (wxCommandEvent &event); void OnOpenProperties (wxCommandEvent &event);
void OnOpenStylesManager (wxCommandEvent &event); void OnOpenStylesManager (wxCommandEvent &event);
void OnOpenAttachments (wxCommandEvent &event); void OnOpenAttachments (wxCommandEvent &event);
@ -508,7 +507,6 @@ enum {
Grid_Prev_Line, Grid_Prev_Line,
Grid_Toggle_Tags, Grid_Toggle_Tags,
Edit_Box_Commit,
Video_Frame_Play, Video_Frame_Play,

View File

@ -85,6 +85,7 @@
#include "preferences.h" #include "preferences.h"
#include "standard_paths.h" #include "standard_paths.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "toggle_bitmap.h" #include "toggle_bitmap.h"
#include "utils.h" #include "utils.h"
@ -223,7 +224,6 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Grid_Next_Line,FrameMain::OnNextLine) EVT_MENU(Grid_Next_Line,FrameMain::OnNextLine)
EVT_MENU(Grid_Prev_Line,FrameMain::OnPrevLine) EVT_MENU(Grid_Prev_Line,FrameMain::OnPrevLine)
EVT_MENU(Grid_Toggle_Tags,FrameMain::OnToggleTags) EVT_MENU(Grid_Toggle_Tags,FrameMain::OnToggleTags)
EVT_MENU(Edit_Box_Commit,FrameMain::OnEditBoxCommit)
EVT_MENU(Medusa_Play, FrameMain::OnMedusaPlay) EVT_MENU(Medusa_Play, FrameMain::OnMedusaPlay)
EVT_MENU(Medusa_Stop, FrameMain::OnMedusaStop) EVT_MENU(Medusa_Stop, FrameMain::OnMedusaStop)
@ -574,7 +574,6 @@ void FrameMain::OnLog(wxCommandEvent &) {
log->Show(1); log->Show(1);
} }
/// @brief Open check updates /// @brief Open check updates
void FrameMain::OnCheckUpdates(wxCommandEvent &) { void FrameMain::OnCheckUpdates(wxCommandEvent &) {
PerformVersionCheck(true); PerformVersionCheck(true);
@ -1056,7 +1055,7 @@ void FrameMain::OnAutomationMacro (wxCommandEvent &event) {
// Have the grid update its maps, this properly refreshes it to reflect the changed subs // Have the grid update its maps, this properly refreshes it to reflect the changed subs
SubsGrid->UpdateMaps(); SubsGrid->UpdateMaps();
SubsGrid->SetSelectionFromAbsolute(selected_lines); SubsGrid->SetSelectionFromAbsolute(selected_lines);
SubsGrid->CommitChanges(true, false); SubsGrid->CommitChanges();
SubsGrid->EndBatch(); SubsGrid->EndBatch();
#endif #endif
} }
@ -1155,8 +1154,8 @@ void FrameMain::OnShiftToFrame (wxCommandEvent &) {
// Commit // Commit
SubsGrid->ass->Commit(_("shift to frame")); SubsGrid->ass->Commit(_("shift to frame"));
SubsGrid->CommitChanges(); SubsGrid->CommitChanges(false);
SubsGrid->editBox->Update(true,false); SubsGrid->editBox->Update(true);
} }
/// @brief Undo /// @brief Undo
@ -1474,32 +1473,6 @@ void FrameMain::OnSetTags(wxCommandEvent &event) {
SubsGrid->Refresh(false); SubsGrid->Refresh(false);
} }
/// @brief Commit Edit Box's changes
/// @param event
void FrameMain::OnEditBoxCommit(wxCommandEvent &event) {
// Find focus
wxWindow *focus = FindFocus();
if (!focus) return;
// Is the text edit
if (focus == EditBox->TextEdit) {
EditBox->Commit(true);
EditBox->Update(true);
}
// Other window
else {
//wxKeyEvent keyevent;
//keyevent.m_keyCode = WXK_RETURN;
//keyevent.m_controlDown = true;
//keyevent.SetEventType(wxEVT_KEY_DOWN);
wxCommandEvent keyevent(wxEVT_COMMAND_TEXT_ENTER,focus->GetId());
focus->GetEventHandler()->AddPendingEvent(keyevent);
}
}
/// @brief Choose a different language /// @brief Choose a different language
void FrameMain::OnChooseLanguage (wxCommandEvent &) { void FrameMain::OnChooseLanguage (wxCommandEvent &) {
// Get language // Get language

View File

@ -1,127 +0,0 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from 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/
//
// $Id$
/// @file hilimod_textctrl.cpp
/// @brief Edit control that changes colour when its contents are modified
/// @ingroup custom_control
///
////////////
// Includes
#include "config.h"
#include "compat.h"
#include "hilimod_textctrl.h"
#include "main.h"
/// @brief Constructor
/// @param parent
/// @param id
/// @param value
/// @param pos
/// @param size
/// @param style
/// @param validator
/// @param name
///
HiliModTextCtrl::HiliModTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) :
wxTextCtrl(parent,id,value,pos,size,style,validator,name)
{
UpdateLocked = false;
isModified = false;
orig = GetValue();
Connect(wxEVT_COMMAND_TEXT_UPDATED,wxCommandEventHandler(HiliModTextCtrl::OnModified));
}
/// @brief Modified event
/// @param event
/// @return
///
void HiliModTextCtrl::OnModified(wxCommandEvent &event) {
if (UpdateLocked) return;
Modified();
event.Skip();
}
/// @brief Commited event
///
void HiliModTextCtrl::Commited() {
if (isModified) {
orig = GetValue();
SetBackgroundColour(wxNullColour);
Refresh(false);
isModified = false;
}
}
/// @brief Set value
/// @param value
///
void HiliModTextCtrl::SetValue(const wxString& value) {
UpdateLocked = true;
orig = value;
wxTextCtrl::SetValue(value);
Commited();
UpdateLocked = false;
}
/// @brief Was modified
///
void HiliModTextCtrl::Modified() {
bool match = GetValue() == orig;
// Different from original
if (!isModified && !match) {
isModified = true;
SetBackgroundColour(lagi_wxColour(OPT_GET("Colour/Background/Modified")->GetColour()));
Refresh(false);
}
// Same as original
if (isModified && match) {
SetBackgroundColour(wxNullColour);
Refresh(false);
isModified = false;
}
}

View File

@ -1,87 +0,0 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from 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/
//
// $Id$
/// @file hilimod_textctrl.h
/// @see hilimod_textctrl.cpp
/// @ingroup custom_control
///
#ifndef HILIMOD_TEXTCTRL
/// DOCME
#define HILIMOD_TEXTCTRL
////////////
// Includes
#ifndef AGI_PRE
#include <wx/textctrl.h>
#endif
/// DOCME
/// @class HiliModTextCtrl
/// @brief DOCME
///
/// DOCME
class HiliModTextCtrl : public wxTextCtrl {
private:
/// DOCME
bool UpdateLocked;
/// DOCME
bool isModified;
/// DOCME
wxString orig;
void OnModified(wxCommandEvent &event);
void OnKey(wxKeyEvent &event);
public:
HiliModTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
void Modified();
void Commited();
void SetValue(const wxString& value);
/// @brief DOCME
///
bool HasBeenModified() { return isModified; }
};
#endif

View File

@ -1,181 +0,0 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from 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/
//
// $Id$
/// @file idle_field_event.cpp
/// @brief Unused event, intended to be used for automatic update of other controls after some idle time from the user
/// @ingroup custom_control
///
///////////
// Headers
#include "config.h"
#ifndef AGI_PRE
#include <wx/event.h>
#include <wx/settings.h>
#endif
#include "idle_field_event.h"
/// @brief Constructor
/// @param _control
/// @param _name
///
IdleFieldHandler::IdleFieldHandler(wxWindow *_control,wxString _name) {
control = _control;
name = _name;
overriden = false;
locked = false;
text = NULL;
box = NULL;
// Set colours
original = control->GetForegroundColour();
grey = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
grey = wxColour((grey.Red() + bg.Red()) / 2,(grey.Green() + bg.Green()) / 2,(grey.Blue() + bg.Blue()) / 2);
// wxTextCtrl
if (control->IsKindOf(CLASSINFO(wxTextCtrl))) {
text = (wxTextCtrl*) control;
Connect(text->GetId(),wxEVT_COMMAND_TEXT_UPDATED,wxCommandEventHandler(IdleFieldHandler::OnChange));
}
// wxComboBox
else if (control->IsKindOf(CLASSINFO(wxComboBox))) {
box = (wxComboBox*) control;
Connect(box->GetId(),wxEVT_COMMAND_TEXT_UPDATED,wxCommandEventHandler(IdleFieldHandler::OnChange));
Connect(box->GetId(),wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEventHandler(IdleFieldHandler::OnChange));
}
KillFocus();
}
///////////////
// Event table
BEGIN_EVENT_TABLE(IdleFieldHandler,wxEvtHandler)
EVT_SET_FOCUS(IdleFieldHandler::OnSetFocus)
EVT_KILL_FOCUS(IdleFieldHandler::OnKillFocus)
END_EVENT_TABLE()
/// @brief Get Focus event
/// @param event
///
void IdleFieldHandler::OnSetFocus(wxFocusEvent &event) {
SetFocus();
event.Skip();
}
/// @brief Lose Focus event
/// @param event
///
void IdleFieldHandler::OnKillFocus(wxFocusEvent &event) {
KillFocus();
event.Skip();
}
/// @brief Get focus
///
void IdleFieldHandler::SetFocus() {
if (overriden) {
// Prepare
locked = true;
control->Freeze();
control->SetForegroundColour(original);
// Text
if (text) text->SetValue(_T(""));
// Box
if (box) box->SetValue(_T(""));
// Finish
overriden = false;
locked = false;
control->Thaw();
}
}
/// @brief Lose Focus
///
void IdleFieldHandler::KillFocus() {
bool modify = false;
if ((text && text->GetValue().IsEmpty()) || (box && box->GetValue().IsEmpty())) modify = true;
if (modify) {
// Prepare
locked = true;
control->Freeze();
control->SetForegroundColour(grey);
// Text
if (text) text->SetValue(name);
// Box
if (box) box->SetValue(name);
// Finish
overriden = true;
locked = false;
control->Thaw();
}
}
/// @brief Parent control changed
/// @param event
///
void IdleFieldHandler::OnChange(wxCommandEvent &event) {
if (locked) return;
overriden = false;
control->SetForegroundColour(original);
if (wxWindow::FindFocus() != control) {
wxFocusEvent focus(wxEVT_KILL_FOCUS,control->GetId());
focus.SetEventObject(control);
AddPendingEvent(focus);
}
event.Skip();
}

View File

@ -1,95 +0,0 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from 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/
//
// $Id$
/// @file idle_field_event.h
/// @see idle_field_event.cpp
/// @ingroup custom_control
///
///////////
// Headers
#ifndef AGI_PRE
#include <wx/combobox.h>
#include <wx/event.h>
#include <wx/textctrl.h>
#endif
/// DOCME
/// @class IdleFieldHandler
/// @brief DOCME
///
/// DOCME
class IdleFieldHandler : public wxEvtHandler {
private:
/// DOCME
wxComboBox *box;
/// DOCME
wxTextCtrl *text;
/// DOCME
bool overriden;
/// DOCME
bool locked;
/// DOCME
wxColour grey;
/// DOCME
wxColour original;
/// DOCME
wxWindow *control;
/// DOCME
wxString name;
void SetFocus();
void KillFocus();
void OnSetFocus(wxFocusEvent &event);
void OnKillFocus(wxFocusEvent &event);
void OnChange(wxCommandEvent &event);
public:
IdleFieldHandler(wxWindow *control,wxString name);
DECLARE_EVENT_TABLE()
};

View File

@ -34,17 +34,10 @@
/// @ingroup custom_control /// @ingroup custom_control
/// ///
#pragma once
////////////
// Includes
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/stc/stc.h> #include <wx/stc/stc.h>
#endif #endif
/// DOCME /// DOCME
/// @class ScintillaTextCtrl /// @class ScintillaTextCtrl
/// @brief DOCME /// @brief DOCME
@ -57,10 +50,6 @@ public:
int GetUnicodePosition(int pos); int GetUnicodePosition(int pos);
int GetReverseUnicodePosition(int pos); int GetReverseUnicodePosition(int pos);
/// @brief DOCME
///
wxString GetValue() { return GetText(); }
void StartUnicodeStyling(int start,int mask=31); void StartUnicodeStyling(int start,int mask=31);
void SetUnicodeStyling(int start,int length,int style); void SetUnicodeStyling(int start,int length,int style);
void SetSelectionU(int start,int end); void SetSelectionU(int start,int end);
@ -68,5 +57,3 @@ public:
ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr); ScintillaTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
virtual ~ScintillaTextCtrl(); virtual ~ScintillaTextCtrl();
}; };

File diff suppressed because it is too large Load Diff

View File

@ -34,335 +34,175 @@
/// @ingroup main_ui /// @ingroup main_ui
/// ///
////////////
// Includes
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/button.h> #include <vector>
#include <wx/checkbox.h>
#include <wx/combobox.h>
#include <wx/dcclient.h>
#include <wx/dcmemory.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <wx/radiobut.h>
#include <wx/spinctrl.h>
#endif #endif
#include "selection_controller.h" #include "selection_controller.h"
#include "subs_edit_ctrl.h"
class AudioDisplay;
//////////////
// Prototypes
class AssDialogue; class AssDialogue;
class SubtitlesGrid; class SubtitlesGrid;
class SubsTextEditCtrl;
class TimeEdit; class TimeEdit;
class SubsEditBox; class wxButton;
class AudioDisplay; class wxCheckBox;
class HiliModTextCtrl; class wxComboBox;
class wxRadioButton;
class wxSizer;
class wxSpinCtrl;
class wxStyledTextCtrl; class wxStyledTextCtrl;
class wxStyleTextEvent;
class wxTextCtrl;
/// DOCME /// DOCME
/// @class SubsEditBox /// @class SubsEditBox
/// @brief DOCME /// @brief Main subtitle edit box
/// ///
/// DOCME /// Controls the text edit and all surrounding controls
class SubsEditBox : public wxPanel, protected SelectionListener<AssDialogue> { class SubsEditBox : public wxPanel, protected SelectionListener<AssDialogue> {
friend class SubsTextEditHandler;
friend class SubsTextEditCtrl;
friend class AudioDisplay; friend class AudioDisplay;
private: enum TimeField {
TIME_START = 0,
TIME_END,
TIME_DURATION
};
/// DOCME /// Currently active dialogue line
AssDialogue *line;
/// Last seen grid selection
Selection sel;
/// Are the buttons currently split into two lines?
bool splitLineMode; bool splitLineMode;
/// Are the controls currently enabled?
/// DOCME
bool setupDone;
/// DOCME
bool enabled;
/// DOCME
bool textEditReady;
/// DOCME
bool controlState; bool controlState;
/// DOCME wxColour disabledBgColour;
wxColour origBgColour; wxColour origBgColour;
/// DOCME // Externally supplied controls
wxColour disabledBgColour; AudioDisplay *audio;
/// DOCME
SubtitlesGrid *grid; SubtitlesGrid *grid;
/// DOCME // Box controls
wxCheckBox *CommentBox; wxCheckBox *CommentBox;
/// DOCME
wxComboBox *StyleBox; wxComboBox *StyleBox;
/// DOCME
wxComboBox *ActorBox; wxComboBox *ActorBox;
/// DOCME
TimeEdit *StartTime; TimeEdit *StartTime;
/// DOCME
TimeEdit *EndTime; TimeEdit *EndTime;
/// DOCME
TimeEdit *Duration; TimeEdit *Duration;
/// DOCME
wxSpinCtrl *Layer; wxSpinCtrl *Layer;
wxTextCtrl *MarginL;
/// DOCME wxTextCtrl *MarginR;
HiliModTextCtrl *MarginL; wxTextCtrl *MarginV;
wxTextCtrl *Effect;
/// DOCME
HiliModTextCtrl *MarginR;
/// DOCME
HiliModTextCtrl *MarginV;
/// DOCME
HiliModTextCtrl *Effect;
/// DOCME
wxRadioButton *ByTime; wxRadioButton *ByTime;
/// DOCME
wxRadioButton *ByFrame; wxRadioButton *ByFrame;
/// DOCME /// Buttons which turn on or off with the control
wxCheckBox *SyntaxHighlight; std::vector<wxButton*> ToggableButtons;
/// DOCME
wxButton *Bold;
/// DOCME
wxButton *Italics;
/// DOCME
wxButton *Underline;
/// DOCME
wxButton *Strikeout;
/// DOCME
wxButton *FontName;
/// DOCME
wxButton *Color1;
/// DOCME
wxButton *Color2;
/// DOCME
wxButton *Color3;
/// DOCME
wxButton *Color4;
/// DOCME
wxButton *CommitButton;
/// DOCME
wxSizer *TopSizer; wxSizer *TopSizer;
/// DOCME
wxSizer *MiddleBotSizer; wxSizer *MiddleBotSizer;
/// DOCME
wxSizer *MiddleSizer; wxSizer *MiddleSizer;
/// DOCME
wxSizer *MainSizer; wxSizer *MainSizer;
/// DOCME
wxSizer *DummySizer;
/// DOCME
wxSizer *BottomSizer; wxSizer *BottomSizer;
void SetControlsState(bool state); void SetControlsState(bool state);
void CommitTimes(bool start,bool end,bool fromStart,bool commit=true); /// @brief Update times of selected lines
/// @param field Field which changed
void CommitTimes(TimeField field);
/// @brief Commits the current edit box contents
/// @param desc Undo description to use
void CommitText(wxString desc);
int BlockAtPos(int pos); /// Get block number at text position
int BlockAtPos(int pos) const;
/// @brief Refresh the video display and move to the next line
/// @param stay Only refresh the video
void Commit(bool stay);
int timeCommitId[3];
int commitId;
wxString lastCommitType;
void OnEditText(wxStyledTextEvent &event);
void OnNeedStyle(wxStyledTextEvent &event); void OnNeedStyle(wxStyledTextEvent &event);
void OnCharAdded(wxStyledTextEvent &event); void OnChange(wxStyledTextEvent &event);
void OnUpdateUI(wxStyledTextEvent &event); void OnKeyDown(wxKeyEvent &event);
void OnButtonColor1(wxCommandEvent &event); void OnActiveLineChanged(AssDialogue *new_line);
void OnButtonColor2(wxCommandEvent &event); void OnSelectedSetChanged(const Selection &, const Selection &);
void OnButtonColor3(wxCommandEvent &event);
void OnButtonColor4(wxCommandEvent &event);
void OnButtonFontFace(wxCommandEvent &event);
void OnButtonBold(wxCommandEvent &event);
void OnButtonItalics(wxCommandEvent &event);
void OnButtonUnderline(wxCommandEvent &event);
void OnButtonStrikeout(wxCommandEvent &event);
void OnButtonCommit(wxCommandEvent &event);
void OnSyntaxBox(wxCommandEvent &event); void OnFrameTimeRadio(wxCommandEvent &event);
void OnFrameRadio(wxCommandEvent &event);
void OnTimeRadio(wxCommandEvent &event);
void OnKeyDown(wxStyledTextEvent &event);
void OnStyleChange(wxCommandEvent &event); void OnStyleChange(wxCommandEvent &event);
void OnActorChange(wxCommandEvent &event); void OnActorChange(wxCommandEvent &event);
void OnLayerEnter(wxCommandEvent &event); void OnLayerEnter(wxCommandEvent &event);
void OnLayerChange(wxSpinEvent &event); void OnLayerChange(wxSpinEvent &event);
void OnStartTimeChange(wxCommandEvent &event); void OnStartTimeChange(wxCommandEvent &);
void OnEndTimeChange(wxCommandEvent &event); void OnEndTimeChange(wxCommandEvent &);
void OnDurationChange(wxCommandEvent &event); void OnDurationChange(wxCommandEvent &);
void OnMarginLChange(wxCommandEvent &event); void OnMarginLChange(wxCommandEvent &);
void OnMarginRChange(wxCommandEvent &event); void OnMarginRChange(wxCommandEvent &);
void OnMarginVChange(wxCommandEvent &event); void OnMarginVChange(wxCommandEvent &);
void OnCommentChange(wxCommandEvent &event); void OnCommentChange(wxCommandEvent &);
void OnEffectChange(wxCommandEvent &event); void OnEffectChange(wxCommandEvent &);
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
protected: void OnFlagButton(wxCommandEvent &event);
// SubtitleSelectionListener implementation void OnColorButton(wxCommandEvent &event);
virtual void OnActiveLineChanged(AssDialogue *new_line); void OnFontButton(wxCommandEvent &event);
virtual void OnSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed); void OnCommitButton(wxCommandEvent &);
/// @brief Set the value of a tag for the currently selected text
/// @param tag Tag to set
/// @param value New value of tag
/// @param atEnd Set the value at the end of the selection rather than beginning
void SetTag(wxString tag, wxString value, bool atEnd = false);
/// @brief Callback function for the color picker
/// @param newColor New color selected in the picker
void SetColorCallback(wxColor newColor);
/// Which color is currently being set
wxString colorTag;
/// @brief Set a field in each selected line to a specified value
/// @param set Callable which does the setting
/// @param value Value to pass to set
/// @param desc Undo description to use
/// @param amend Coalesce sequences of commits of the same type
template<class T, class setter>
void SetSelectedRows(setter set, T value, wxString desc, bool amend = false);
/// @brief Set a field in each selected line to a specified value
/// @param field Field to set
/// @param value Value to set the field to
/// @param desc Undo description to use
/// @param amend Coalesce sequences of commits of the same type
template<class T>
void SetSelectedRows(T AssDialogue::*field, T value, wxString desc, bool amend = false);
public: public:
/// DOCME
AudioDisplay *audio;
/// DOCME
SubsTextEditCtrl *TextEdit; SubsTextEditCtrl *TextEdit;
SubsEditBox(wxWindow *parent,SubtitlesGrid *gridp); /// @brief Constructor
/// @param parent Parent window
/// @param grid Associated grid
/// @param audio Associated audio display
SubsEditBox(wxWindow *parent, SubtitlesGrid *grid, AudioDisplay *audio);
~SubsEditBox(); ~SubsEditBox();
void SetOverride (wxString tag,wxString preValue=_T(""),int pos=-1,bool getFocus=true); /// @brief Reload the current line from the file
void SetStyleFlag (wxString tag,wxString preValue=_T(""),int pos=-1); /// @param timeOnly Only reload times
/// @param setAudio Also update the audio display
void SetSplitLineMode(wxSize size=wxSize(-1,-1)); void Update(bool timeOnly = false, bool setAudio = true);
void CommitText(bool weak=false); /// Reload non-line-specific things like styles from the file
void Update(bool timeOnly=false,bool weak=false);
void UpdateGlobals(); void UpdateGlobals();
/// @brief Enable or disable frame timing mode
void UpdateFrameTiming(); void UpdateFrameTiming();
void DoKeyPress(wxKeyEvent &event);
void Commit(bool stay);
DECLARE_EVENT_TABLE()
}; };
/// DOCME
/// @class SubsEditBoxEvent
/// @brief DOCME
///
/// DOCME
class SubsEditBoxEvent : public wxEvtHandler {
private:
/// DOCME
SubsEditBox *control;
void OnKeyPress(wxKeyEvent &event);
public:
SubsEditBoxEvent(SubsEditBox *control);
DECLARE_EVENT_TABLE()
};
///////
// IDs
enum {
/// DOCME
EDIT_BOX = 1300,
/// DOCME
SYNTAX_BOX,
/// DOCME
RADIO_TIME_BY_FRAME,
/// DOCME
RADIO_TIME_BY_TIME,
/// DOCME
STYLE_COMBOBOX,
/// DOCME
ACTOR_COMBOBOX,
/// DOCME
LAYER_BOX,
/// DOCME
STARTTIME_BOX,
/// DOCME
ENDTIME_BOX,
/// DOCME
DURATION_BOX,
/// DOCME
MARGINL_BOX,
/// DOCME
MARGINR_BOX,
/// DOCME
MARGINV_BOX,
/// DOCME
EFFECT_BOX,
/// DOCME
COMMENT_CHECKBOX,
/// DOCME
BUTTON_BOLD,
/// DOCME
BUTTON_ITALICS,
/// DOCME
BUTTON_UNDERLINE,
/// DOCME
BUTTON_STRIKEOUT,
/// DOCME
BUTTON_FONT_NAME,
/// DOCME
BUTTON_COLOR1,
/// DOCME
BUTTON_COLOR2,
/// DOCME
BUTTON_COLOR3,
/// DOCME
BUTTON_COLOR4,
/// DOCME
BUTTON_COMMIT
};

View File

@ -34,22 +34,46 @@
/// @ingroup main_ui /// @ingroup main_ui
/// ///
////////////
// Includes
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
#ifdef _WIN32
#include <functional>
#else
#include <tr1/functional>
#endif
#include <wx/intl.h> #include <wx/intl.h>
#endif #endif
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "compat.h" #include "compat.h"
#include "main.h" #include "main.h"
#include "spellchecker_manager.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "thesaurus.h"
#include "utils.h" #include "utils.h"
/// Event ids
enum {
EDIT_MENU_SPLIT_PRESERVE = 1400,
EDIT_MENU_SPLIT_ESTIMATE,
EDIT_MENU_CUT,
EDIT_MENU_COPY,
EDIT_MENU_PASTE,
EDIT_MENU_SELECT_ALL,
EDIT_MENU_ADD_TO_DICT,
EDIT_MENU_SUGGESTION,
EDIT_MENU_SUGGESTIONS,
EDIT_MENU_THESAURUS = 1450,
EDIT_MENU_THESAURUS_SUGS,
EDIT_MENU_DIC_LANGUAGE = 1600,
EDIT_MENU_DIC_LANGS,
EDIT_MENU_THES_LANGUAGE = 1700,
EDIT_MENU_THES_LANGS
};
/// @brief Edit box constructor /// @brief Edit box constructor
/// @param parent /// @param parent
@ -62,8 +86,11 @@
/// @param name /// @param name
/// @return /// @return
/// ///
SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& wsize, long style, const wxValidator& validator, const wxString& name) SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, SubtitlesGrid *grid)
: ScintillaTextCtrl(parent, id, value, pos, wsize, style, validator, name) : ScintillaTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, wsize, style)
, spellchecker(SpellCheckerFactoryManager::GetSpellChecker())
, thesaurus(Thesaurus::GetThesaurus())
, grid(grid)
{ {
// Set properties // Set properties
SetWrapMode(wxSTC_WRAP_WORD); SetWrapMode(wxSTC_WRAP_WORD);
@ -83,127 +110,104 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri
CmdKeyClear('T',wxSTC_SCMOD_CTRL | wxSTC_SCMOD_SHIFT); CmdKeyClear('T',wxSTC_SCMOD_CTRL | wxSTC_SCMOD_SHIFT);
CmdKeyClear('U',wxSTC_SCMOD_CTRL); CmdKeyClear('U',wxSTC_SCMOD_CTRL);
// Set spellchecker
spellchecker = SpellCheckerFactoryManager::GetSpellChecker();
// Set thesaurus
thesaurus = Thesaurus::GetThesaurus();
// Prototypes for call tips // Prototypes for call tips
tipProtoN = -1; tipProtoN = -1;
proto.Add(_T("move(x1,y1,x2,y2)")); proto.Add(L"move(x1,y1,x2,y2)");
proto.Add(_T("move(x1,y1,x2,y2,startTime,endTime)")); proto.Add(L"move(x1,y1,x2,y2,startTime,endTime)");
proto.Add(_T("fn;FontName")); proto.Add(L"fn;FontName");
proto.Add(_T("bord;Width")); proto.Add(L"bord;Width");
proto.Add(_T("xbord;Width")); proto.Add(L"xbord;Width");
proto.Add(_T("ybord;Width")); proto.Add(L"ybord;Width");
proto.Add(_T("shad;Depth")); proto.Add(L"shad;Depth");
proto.Add(_T("xshad;Depth")); proto.Add(L"xshad;Depth");
proto.Add(_T("yshad;Depth")); proto.Add(L"yshad;Depth");
proto.Add(_T("be;Strength")); proto.Add(L"be;Strength");
proto.Add(_T("blur;Strength")); proto.Add(L"blur;Strength");
proto.Add(_T("fscx;Scale")); proto.Add(L"fscx;Scale");
proto.Add(_T("fscy;Scale")); proto.Add(L"fscy;Scale");
proto.Add(_T("fsp;Spacing")); proto.Add(L"fsp;Spacing");
proto.Add(_T("fs;FontSize")); proto.Add(L"fs;FontSize");
proto.Add(_T("fe;Encoding")); proto.Add(L"fe;Encoding");
proto.Add(_T("frx;Angle")); proto.Add(L"frx;Angle");
proto.Add(_T("fry;Angle")); proto.Add(L"fry;Angle");
proto.Add(_T("frz;Angle")); proto.Add(L"frz;Angle");
proto.Add(_T("fr;Angle")); proto.Add(L"fr;Angle");
proto.Add(_T("pbo;Offset")); proto.Add(L"pbo;Offset");
proto.Add(_T("clip(command)")); proto.Add(L"clip(command)");
proto.Add(_T("clip(scale,command)")); proto.Add(L"clip(scale,command)");
proto.Add(_T("clip(x1,y1,x2,y2)")); proto.Add(L"clip(x1,y1,x2,y2)");
proto.Add(_T("iclip(command)")); proto.Add(L"iclip(command)");
proto.Add(_T("iclip(scale,command)")); proto.Add(L"iclip(scale,command)");
proto.Add(_T("iclip(x1,y1,x2,y2)")); proto.Add(L"iclip(x1,y1,x2,y2)");
proto.Add(_T("t(acceleration,tags)")); proto.Add(L"t(acceleration,tags)");
proto.Add(_T("t(startTime,endTime,tags)")); proto.Add(L"t(startTime,endTime,tags)");
proto.Add(_T("t(startTime,endTime,acceleration,tags)")); proto.Add(L"t(startTime,endTime,acceleration,tags)");
proto.Add(_T("pos(x,y)")); proto.Add(L"pos(x,y)");
proto.Add(_T("p;Exponent")); proto.Add(L"p;Exponent");
proto.Add(_T("org(x,y)")); proto.Add(L"org(x,y)");
proto.Add(_T("fade(startAlpha,middleAlpha,endAlpha,startIn,endIn,startOut,endOut)")); proto.Add(L"fade(startAlpha,middleAlpha,endAlpha,startIn,endIn,startOut,endOut)");
proto.Add(_T("fad(startTime,endTime)")); proto.Add(L"fad(startTime,endTime)");
proto.Add(_T("c;Colour")); proto.Add(L"c;Colour");
proto.Add(_T("1c;Colour")); proto.Add(L"1c;Colour");
proto.Add(_T("2c;Colour")); proto.Add(L"2c;Colour");
proto.Add(_T("3c;Colour")); proto.Add(L"3c;Colour");
proto.Add(_T("4c;Colour")); proto.Add(L"4c;Colour");
proto.Add(_T("alpha;Alpha")); proto.Add(L"alpha;Alpha");
proto.Add(_T("1a;Alpha")); proto.Add(L"1a;Alpha");
proto.Add(_T("2a;Alpha")); proto.Add(L"2a;Alpha");
proto.Add(_T("3a;Alpha")); proto.Add(L"3a;Alpha");
proto.Add(_T("4a;Alpha")); proto.Add(L"4a;Alpha");
proto.Add(_T("an;Alignment")); proto.Add(L"an;Alignment");
proto.Add(_T("a;Alignment")); proto.Add(L"a;Alignment");
proto.Add(_T("b;Weight")); proto.Add(L"b;Weight");
proto.Add(_T("i;1/0")); proto.Add(L"i;1/0");
proto.Add(_T("u;1/0")); proto.Add(L"u;1/0");
proto.Add(_T("s;1/0")); proto.Add(L"s;1/0");
proto.Add(_T("kf;Duration")); proto.Add(L"kf;Duration");
proto.Add(_T("ko;Duration")); proto.Add(L"ko;Duration");
proto.Add(_T("k;Duration")); proto.Add(L"k;Duration");
proto.Add(_T("K;Duration")); proto.Add(L"K;Duration");
proto.Add(_T("q;WrapStyle")); proto.Add(L"q;WrapStyle");
proto.Add(_T("r;Style")); proto.Add(L"r;Style");
proto.Add(_T("fax;Factor")); proto.Add(L"fax;Factor");
proto.Add(_T("fay;Factor")); proto.Add(L"fay;Factor");
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_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this);
} }
/// @brief Destructor
///
SubsTextEditCtrl::~SubsTextEditCtrl() { SubsTextEditCtrl::~SubsTextEditCtrl() {
delete spellchecker;
spellchecker = NULL;
delete thesaurus;
thesaurus = NULL;
} }
///////////////////////
// Control event table
BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl) BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl)
EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent) EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent)
EVT_KILL_FOCUS(SubsTextEditCtrl::OnLoseFocus) EVT_KILL_FOCUS(SubsTextEditCtrl::OnLoseFocus)
EVT_MENU(EDIT_MENU_SPLIT_PRESERVE,SubsTextEditCtrl::OnSplitLinePreserve) EVT_MENU(EDIT_MENU_SPLIT_PRESERVE,SubsTextEditCtrl::OnSplitLinePreserve)
EVT_MENU(EDIT_MENU_SPLIT_ESTIMATE,SubsTextEditCtrl::OnSplitLineEstimate) EVT_MENU(EDIT_MENU_SPLIT_ESTIMATE,SubsTextEditCtrl::OnSplitLineEstimate)
EVT_MENU(EDIT_MENU_CUT,SubsTextEditCtrl::OnCut)
EVT_MENU(EDIT_MENU_COPY,SubsTextEditCtrl::OnCopy)
EVT_MENU(EDIT_MENU_PASTE,SubsTextEditCtrl::OnPaste)
EVT_MENU(EDIT_MENU_UNDO,SubsTextEditCtrl::OnUndo)
EVT_MENU(EDIT_MENU_SELECT_ALL,SubsTextEditCtrl::OnSelectAll)
EVT_MENU(EDIT_MENU_ADD_TO_DICT,SubsTextEditCtrl::OnAddToDictionary) 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_SUGGESTIONS,EDIT_MENU_THESAURUS-1,SubsTextEditCtrl::OnUseSuggestion)
EVT_MENU_RANGE(EDIT_MENU_THESAURUS_SUGS,EDIT_MENU_DIC_LANGUAGE-1,SubsTextEditCtrl::OnUseThesaurusSuggestion) EVT_MENU_RANGE(EDIT_MENU_THESAURUS_SUGS,EDIT_MENU_DIC_LANGUAGE-1,SubsTextEditCtrl::OnUseSuggestion)
EVT_MENU_RANGE(EDIT_MENU_DIC_LANGS,EDIT_MENU_THES_LANGUAGE-1,SubsTextEditCtrl::OnSetDicLanguage) EVT_MENU_RANGE(EDIT_MENU_DIC_LANGS,EDIT_MENU_THES_LANGUAGE-1,SubsTextEditCtrl::OnSetDicLanguage)
EVT_MENU_RANGE(EDIT_MENU_THES_LANGS,EDIT_MENU_THES_LANGS+100,SubsTextEditCtrl::OnSetThesLanguage) EVT_MENU_RANGE(EDIT_MENU_THES_LANGS,EDIT_MENU_THES_LANGS+100,SubsTextEditCtrl::OnSetThesLanguage)
END_EVENT_TABLE() END_EVENT_TABLE()
/// @brief Lose focus
/// @param event
///
void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) { void SubsTextEditCtrl::OnLoseFocus(wxFocusEvent &event) {
CallTipCancel(); CallTipCancel();
event.Skip(); event.Skip();
} }
/// @brief Set styles
///
void SubsTextEditCtrl::SetStyles() { void SubsTextEditCtrl::SetStyles() {
// Styles
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
font.SetEncoding(wxFONTENCODING_DEFAULT); // this solves problems with some fonts not working properly font.SetEncoding(wxFONTENCODING_DEFAULT); // this solves problems with some fonts not working properly
wxString fontname = lagi_wxString(OPT_GET("Subtitle/Edit Box/Font Face")->GetString()); wxString fontname = lagi_wxString(OPT_GET("Subtitle/Edit Box/Font Face")->GetString());
if (fontname != _T("")) font.SetFaceName(fontname); if (!fontname.empty()) font.SetFaceName(fontname);
int size = OPT_GET("Subtitle/Edit Box/Font Size")->GetInt(); int size = OPT_GET("Subtitle/Edit Box/Font Size")->GetInt();
// Normal style // Normal style
@ -256,19 +260,11 @@ void SubsTextEditCtrl::SetStyles() {
IndicatorSetForeground(0,wxColour(255,0,0)); IndicatorSetForeground(0,wxColour(255,0,0));
} }
/// @brief Style a range
/// @param start
/// @param _length
/// @return
///
void SubsTextEditCtrl::UpdateStyle(int start, int _length) { void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
// Styling enabled?
if (OPT_GET("Subtitle/Highlight/Syntax")->GetBool() == 0) return; if (OPT_GET("Subtitle/Highlight/Syntax")->GetBool() == 0) return;
// Check if it's a template line // Check if it's a template line
AssDialogue *diag = control->grid->GetActiveLine(); AssDialogue *diag = grid->GetActiveLine();
bool templateLine = diag && diag->Comment && diag->Effect.Lower().StartsWith(_T("template")); bool templateLine = diag && diag->Comment && diag->Effect.Lower().StartsWith(_T("template"));
//bool templateCodeLine = diag && diag->Comment && diag->Effect.Lower().StartsWith(_T("code")); //bool templateCodeLine = diag && diag->Comment && diag->Effect.Lower().StartsWith(_T("code"));
@ -320,7 +316,7 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
} }
// Start override block // Start override block
if (curChar == _T('{') && depth >= 0) { if (curChar == '{' && depth >= 0) {
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
curPos += ran; curPos += ran;
ran = 0; ran = 0;
@ -331,7 +327,7 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
} }
// End override block // End override block
else if (curChar == _T('}') && depth <= 1) { else if (curChar == '}' && depth <= 1) {
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
curPos += ran; curPos += ran;
ran = 0; ran = 0;
@ -342,21 +338,21 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
} }
// Karaoke template block // Karaoke template block
else if (templateLine && curChar == _T('!')) { else if (templateLine && curChar == '!') {
// Apply previous style // Apply previous style
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
curPos += ran; curPos += ran;
ran = -1; // such that ran++ later on resets it to 0 ! ran = -1; // such that ran++ later on resets it to 0 !
// Eat entire template block // Eat entire template block
int endPos = i+1; int endPos = i+1;
while (endPos < end && text[endPos] != _T('!')) while (endPos < end && text[endPos] != '!')
endPos++; endPos++;
SetUnicodeStyling(curPos,endPos-curPos+1,7); SetUnicodeStyling(curPos,endPos-curPos+1,7);
curPos = endPos+1; curPos = endPos+1;
i = endPos+0; i = endPos+0;
} }
// Karaoke template variable // Karaoke template variable
else if (templateLine && curChar == _T('$')) { else if (templateLine && curChar == '$') {
// Apply previous style // Apply previous style
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
curPos += ran; curPos += ran;
@ -365,7 +361,7 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
int endPos = i+1; int endPos = i+1;
while (endPos < end) { while (endPos < end) {
wxChar ch = text[endPos]; wxChar ch = text[endPos];
if ((ch >= _T('A') && ch <= _T('Z')) || (ch >= _T('a') && ch <= _T('z')) || ch == _T('_')) if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == '_')
endPos++; endPos++;
else else
break; break;
@ -381,7 +377,7 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
numMode = false; numMode = false;
// Is \n, \N or \h? // Is \n, \N or \h?
if (curChar == _T('\\') && (nextChar == 'n' || nextChar == 'N' || nextChar == 'h')) { if (curChar == L'\\' && (nextChar == 'n' || nextChar == 'N' || nextChar == 'h')) {
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
curPos += ran; curPos += ran;
ran = 1; ran = 1;
@ -402,7 +398,7 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
// Inside // Inside
else if (depth == 1) { else if (depth == 1) {
// Special character // Special character
if (curChar == _T('\\') || curChar == _T('(') || curChar == _T(')') || curChar == _T(',')) { if (curChar == L'\\' || curChar == '(' || curChar == ')' || curChar == ',') {
if (curStyle != 2) { if (curStyle != 2) {
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
curPos += ran; curPos += ran;
@ -414,7 +410,7 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
else { else {
// Number // Number
if (prevChar != _T('\\') && (numMode || (curChar >= '0' && curChar <= '9') || curChar == '.' || curChar == '&' || curChar == '+' || curChar == '-' || (curChar == 'H' && prevChar == '&'))) { if (prevChar != L'\\' && (numMode || (curChar >= '0' && curChar <= '9') || curChar == '.' || curChar == '&' || curChar == '+' || curChar == '-' || (curChar == 'H' && prevChar == '&'))) {
if (curStyle != 5) { if (curStyle != 5) {
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
curPos += ran; curPos += ran;
@ -433,8 +429,8 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
// Set parameter if it's \fn or \r // Set parameter if it's \fn or \r
int tagLen = 0; int tagLen = 0;
if (text.Mid(curPos,2) == _T("fn")) tagLen = 2; if (text.Mid(curPos,2) == L"fn") tagLen = 2;
else if (text.Mid(curPos,1) == _T("r")) tagLen = 1; else if (text.Mid(curPos,1) == L"r") tagLen = 1;
if (tagLen) { if (tagLen) {
numMode = true; numMode = true;
ran = tagLen-1; ran = tagLen-1;
@ -442,21 +438,21 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
} }
// Set drawing mode if it's \p // Set drawing mode if it's \p
if (text.Mid(curPos,1) == _T("p")) { if (text.Mid(curPos,1) == L"p") {
if (curPos+2 < (signed) text.Length()) { if (curPos+2 < (signed) text.Length()) {
// Disable // Disable
wxChar nextNext = text[curPos+2]; wxChar nextNext = text[curPos+2];
if ((nextNext == _T('\\') || nextNext == _T('}')) && nextChar == _T('0')) drawingMode = false; if ((nextNext == L'\\' || nextNext == '}') && nextChar == '0') drawingMode = false;
// Enable // Enable
if (nextChar >= _T('1') && nextChar <= _T('9')) { if (nextChar >= '1' && nextChar <= '9') {
for(int testPos = curPos+2;testPos < (signed) text.Length();testPos++) { for(int testPos = curPos+2;testPos < (signed) text.Length();testPos++) {
nextNext = text[testPos]; nextNext = text[testPos];
if (nextNext == _T('\\') || nextNext == _T('}')) { if (nextNext == L'\\' || nextNext == '}') {
drawingMode = true; drawingMode = true;
break; break;
} }
if (nextNext < _T('0') || nextNext > _T('9')) break; if (nextNext < '0' || nextNext > '9') break;
} }
} }
} }
@ -469,21 +465,15 @@ void SubsTextEditCtrl::UpdateStyle(int start, int _length) {
ran++; ran++;
} }
SetUnicodeStyling(curPos,ran,curStyle); SetUnicodeStyling(curPos,ran,curStyle);
// Spell check
StyleSpellCheck(start,_length); StyleSpellCheck(start,_length);
wxStyledTextEvent evt;
// Call tip UpdateCallTip(evt);
UpdateCallTip();
} }
/// @brief Update call tip /// @brief Update call tip
/// @return void SubsTextEditCtrl::UpdateCallTip(wxStyledTextEvent &) {
///
void SubsTextEditCtrl::UpdateCallTip() {
// Enabled?
if (!OPT_GET("App/Call Tips")->GetBool()) return; if (!OPT_GET("App/Call Tips")->GetBool()) return;
// Get position and text // Get position and text
@ -503,11 +493,11 @@ void SubsTextEditCtrl::UpdateCallTip() {
else curChar = 0; else curChar = 0;
// Change depth // Change depth
if (curChar == _T('{')) { if (curChar == '{') {
depth++; depth++;
continue; continue;
} }
if (curChar == _T('}')) { if (curChar == '}') {
depth--; depth--;
if (i >= pos && depth == 0) { if (i >= pos && depth == 0) {
tagEnd = i-1; tagEnd = i-1;
@ -527,13 +517,13 @@ void SubsTextEditCtrl::UpdateCallTip() {
if (depth == 1) { if (depth == 1) {
// Inner depth // Inner depth
if (tagStart != -1) { if (tagStart != -1) {
if (curChar == _T('(')) inDepth++; if (curChar == '(') inDepth++;
else if (curChar == _T(')')) inDepth--; else if (curChar == ')') inDepth--;
} }
// Not inside parenthesis // Not inside parenthesis
if (inDepth == 0) { if (inDepth == 0) {
if (prevChar == _T('\\')) { if (prevChar == L'\\') {
// Found start // Found start
if (i <= pos) tagStart = i; if (i <= pos) tagStart = i;
@ -578,17 +568,17 @@ void SubsTextEditCtrl::UpdateCallTip() {
bool isEnd = false; bool isEnd = false;
// Commas // Commas
if (curChar == _T(',')) { if (curChar == ',') {
tagCommas++; tagCommas++;
parN++; parN++;
} }
// Parenthesis // Parenthesis
else if (curChar == _T('(')) { else if (curChar == '(') {
tagParenthesis++; tagParenthesis++;
parN++; parN++;
} }
else if (curChar == _T(')')) { else if (curChar == ')') {
tagParenthesis++; tagParenthesis++;
parN++; parN++;
isEnd = true; isEnd = true;
@ -603,7 +593,7 @@ void SubsTextEditCtrl::UpdateCallTip() {
// Parameter it's on // Parameter it's on
if (i == posInTag) { if (i == posInTag) {
parPos = parN; parPos = parN;
if (curChar == _T(',') || curChar == _T('(') || curChar == _T(')')) { if (curChar == ',' || curChar == '(' || curChar == ')') {
parPos--; parPos--;
} }
} }
@ -628,18 +618,18 @@ void SubsTextEditCtrl::UpdateCallTip() {
bool semiProto = false; bool semiProto = false;
for (unsigned int i=0;i<proto.Count();i++) { for (unsigned int i=0;i<proto.Count();i++) {
// Get prototype name // Get prototype name
int div = proto[i].Find(_T(';')); int div = proto[i].Find(';');
if (div != wxNOT_FOUND) protoName = proto[i].Left(div); if (div != wxNOT_FOUND) protoName = proto[i].Left(div);
else { else {
div = proto[i].Find(_T('(')); div = proto[i].Find('(');
protoName = proto[i].Left(div); protoName = proto[i].Left(div);
} }
// Fix name // Fix name
semiProto = false; semiProto = false;
cleanProto = proto[i]; cleanProto = proto[i];
if (cleanProto.Freq(_T(';')) > 0) { if (cleanProto.Freq(';') > 0) {
cleanProto.Replace(_T(";"),_T("")); cleanProto.Replace(L";","");
semiProto = true; semiProto = true;
} }
@ -649,7 +639,7 @@ void SubsTextEditCtrl::UpdateCallTip() {
else temp = tagName; else temp = tagName;
if (protoName == temp) { if (protoName == temp) {
// Parameter count match // Parameter count match
if (proto[i].Freq(_T(',')) >= tagCommas) { if (proto[i].Freq(',') >= tagCommas) {
// Found // Found
useProto = proto[i]; useProto = proto[i];
protoN = i; protoN = i;
@ -674,8 +664,8 @@ void SubsTextEditCtrl::UpdateCallTip() {
int delta = 0; int delta = 0;
for (unsigned int i=0;i<useProto.Length();i++) { for (unsigned int i=0;i<useProto.Length();i++) {
wxChar curChar = useProto[i]; wxChar curChar = useProto[i];
if (i == 0 || curChar == _T(',') || curChar == _T(';') || curChar == _T('(') || curChar == _T(')')) { if (i == 0 || curChar == ',' || curChar == ';' || curChar == '(' || curChar == ')') {
if (curChar == _T(';')) delta++; if (curChar == ';') delta++;
if (parN == parPos) highStart = i+1-delta; if (parN == parPos) highStart = i+1-delta;
else if (parN == parPos+1) highEnd = i; else if (parN == parPos+1) highEnd = i;
parN++; parN++;
@ -696,16 +686,8 @@ void SubsTextEditCtrl::UpdateCallTip() {
CallTipSetHighlight(highStart,highEnd); CallTipSetHighlight(highStart,highEnd);
} }
/// @brief Spell check
/// @param start
/// @param len
/// @return
///
void SubsTextEditCtrl::StyleSpellCheck(int start, int len) { void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
// See if it has a spellchecker if (!spellchecker.get()) return;
if (!spellchecker) return;
// Results // Results
wxString text = GetText(); wxString text = GetText();
@ -737,50 +719,31 @@ void SubsTextEditCtrl::StyleSpellCheck(int start, int len) {
SetUnicodeStyling(text.Length(), 0, 0); SetUnicodeStyling(text.Length(), 0, 0);
} }
void SubsTextEditCtrl::SetTextTo(wxString text) {
SetEvtHandlerEnabled(false);
/// @brief Set text to a new value
/// @param _text
///
void SubsTextEditCtrl::SetTextTo(const wxString _text) {
// Setup
control->textEditReady = false;
Freeze(); Freeze();
wxString text = _text;
text.Replace(_T("\r\n"),_T("\\N"));
//text.Replace(_T("\n\r"),_T("\\N")); // never a valid linebreak
text.Replace(_T("\r"),_T("\\N"));
text.Replace(_T("\n"),_T("\\N"));
// Prepare text.Replace(L"\r\n",L"\\N");
text.Replace(L"\r",L"\\N");
text.Replace(L"\n",L"\\N");
int from=0,to=0; int from=0,to=0;
GetSelection(&from,&to); GetSelection(&from,&to);
Clear(); Clear();
// Set text
SetText(text); SetText(text);
// Style
UpdateStyle(); UpdateStyle();
// Restore selection // Restore selection
SetSelectionU(GetReverseUnicodePosition(from),GetReverseUnicodePosition(to)); SetSelectionU(GetReverseUnicodePosition(from),GetReverseUnicodePosition(to));
// Finish SetEvtHandlerEnabled(true);
Thaw(); Thaw();
control->textEditReady = true;
} }
/// @brief Mouse event
/// @param event
/// @return
///
void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) { void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) {
// Right click
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) { if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) {
if (control->grid->GetActiveLine() != 0) { if (grid->GetActiveLine() != 0) {
int pos = PositionFromPoint(event.GetPosition()); int pos = PositionFromPoint(event.GetPosition());
ShowPopupMenu(pos); ShowPopupMenu(pos);
return; return;
@ -791,44 +754,30 @@ void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) {
GetParent()->GetEventHandler()->ProcessEvent(event); GetParent()->GetEventHandler()->ProcessEvent(event);
} }
/// @brief Show popup menu
/// @param activePos
///
void SubsTextEditCtrl::ShowPopupMenu(int activePos) { void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
// Menu
wxMenu menu; wxMenu menu;
// Position
if (activePos == -1) activePos = GetCurrentPos(); if (activePos == -1) activePos = GetCurrentPos();
activePos = GetReverseUnicodePosition(activePos); activePos = GetReverseUnicodePosition(activePos);
// Get current word under cursor
currentWord = GetWordAtPosition(activePos); currentWord = GetWordAtPosition(activePos);
currentWordPos = activePos; currentWordPos = activePos;
// Spell check if (spellchecker.get() && currentWord.Length()) {
//int style = GetStyleAt(activePos);
if (spellchecker && currentWord.Length()) {
// Spelled right?
bool rightSpelling = spellchecker->CheckWord(currentWord); bool rightSpelling = spellchecker->CheckWord(currentWord);
// Set font
wxFont font; wxFont font;
font.SetWeight(wxFONTWEIGHT_BOLD); font.SetWeight(wxFONTWEIGHT_BOLD);
// Get suggestions
sugs.Clear(); sugs.Clear();
sugs = spellchecker->GetSuggestions(currentWord); sugs = spellchecker->GetSuggestions(currentWord);
int nSugs = sugs.Count(); int nSugs = sugs.Count();
// Spelled wrong
if (!rightSpelling) { if (!rightSpelling) {
// No suggestions if (!nSugs) {
if (!nSugs) menu.Append(EDIT_MENU_SUGGESTION,_("No correction suggestions"))->Enable(false); menu.Append(EDIT_MENU_SUGGESTION,_("No correction suggestions"))->Enable(false);
}
// Build menu
for (int i=0;i<nSugs;i++) { for (int i=0;i<nSugs;i++) {
wxMenuItem *itm = new wxMenuItem(&menu, EDIT_MENU_SUGGESTIONS+i, sugs[i]); wxMenuItem *itm = new wxMenuItem(&menu, EDIT_MENU_SUGGESTIONS+i, sugs[i]);
#ifdef __WINDOWS__ #ifdef __WINDOWS__
@ -839,31 +788,23 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
// Append "add word" // Append "add word"
wxString add_to_dict_text(_("Add \"%s\" to dictionary")); wxString add_to_dict_text(_("Add \"%s\" to dictionary"));
add_to_dict_text.Replace(_T("%s"), currentWord); add_to_dict_text.Replace(L"%s", currentWord);
menu.Append(EDIT_MENU_ADD_TO_DICT,add_to_dict_text)->Enable(spellchecker->CanAddWord(currentWord)); menu.Append(EDIT_MENU_ADD_TO_DICT,add_to_dict_text)->Enable(spellchecker->CanAddWord(currentWord));
} }
// Spelled right // Spelled right
else { else {
// No suggestions if (!nSugs) {
if (!nSugs) menu.Append(EDIT_MENU_SUGGESTION,_("No spell checker suggestions"))->Enable(false); menu.Append(EDIT_MENU_SUGGESTION,_("No spell checker suggestions"))->Enable(false);
}
// Has suggestions
else { else {
// Build list // Build list
wxMenu *subMenu = new wxMenu(); wxMenu *subMenu = new wxMenu();
for (int i=0;i<nSugs;i++) subMenu->Append(EDIT_MENU_SUGGESTIONS+i,sugs[i]); for (int i=0;i<nSugs;i++) subMenu->Append(EDIT_MENU_SUGGESTIONS+i,sugs[i]);
menu.Append(-1,wxString::Format(_("Spell checker suggestions for \"%s\""),currentWord.c_str()), subMenu); menu.Append(-1,wxString::Format(_("Spell checker suggestions for \"%s\""),currentWord.c_str()), subMenu);
} }
// Separator
//if (!thesaurus) menu.AppendSeparator();
} }
// Language list
wxArrayString langs = spellchecker->GetLanguageList(); // This probably should be cached... wxArrayString langs = spellchecker->GetLanguageList(); // This probably should be cached...
// Current language
wxString curLang = lagi_wxString(OPT_GET("Tool/Spell Checker/Language")->GetString()); wxString curLang = lagi_wxString(OPT_GET("Tool/Spell Checker/Language")->GetString());
// Languages // Languages
@ -891,7 +832,7 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
} }
// Thesaurus // Thesaurus
if (thesaurus && currentWord.Length()) { if (thesaurus.get() && currentWord.Length()) {
// Get results // Get results
ThesaurusEntryArray result; ThesaurusEntryArray result;
thesaurus->Lookup(currentWord,result); thesaurus->Lookup(currentWord,result);
@ -904,9 +845,7 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
} }
} }
// Has suggestions
if (result.size()) { if (result.size()) {
// Set font
wxFont font; wxFont font;
font.SetStyle(wxFONTSTYLE_ITALIC); font.SetStyle(wxFONTSTYLE_ITALIC);
@ -938,18 +877,14 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
// Thesaurus menu // Thesaurus menu
wxString thes_suggestion_text(_("Thesaurus suggestions for \"%s\"")); wxString thes_suggestion_text(_("Thesaurus suggestions for \"%s\""));
thes_suggestion_text.Replace(_T("%s"), currentWord); thes_suggestion_text.Replace(L"%s", currentWord);
menu.Append(-1,thes_suggestion_text,thesMenu); menu.Append(-1,thes_suggestion_text,thesMenu);
} }
// No suggestions
if (!result.size()) menu.Append(EDIT_MENU_THESAURUS,_("No thesaurus suggestions"))->Enable(false); if (!result.size()) menu.Append(EDIT_MENU_THESAURUS,_("No thesaurus suggestions"))->Enable(false);
// Language list
wxArrayString langs = thesaurus->GetLanguageList(); // This probably should be cached... wxArrayString langs = thesaurus->GetLanguageList(); // This probably should be cached...
// Current language
wxString curLang = lagi_wxString(OPT_GET("Tool/Thesaurus/Language")->GetString()); wxString curLang = lagi_wxString(OPT_GET("Tool/Thesaurus/Language")->GetString());
// Languages // Languages
@ -977,8 +912,6 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
} }
// Standard actions // Standard actions
menu.Append(EDIT_MENU_UNDO,_("&Undo"))->Enable(CanUndo());
menu.AppendSeparator();
menu.Append(EDIT_MENU_CUT,_("Cu&t"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0); menu.Append(EDIT_MENU_CUT,_("Cu&t"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0);
menu.Append(EDIT_MENU_COPY,_("&Copy"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0); menu.Append(EDIT_MENU_COPY,_("&Copy"))->Enable(GetSelectionStart()-GetSelectionEnd() != 0);
menu.Append(EDIT_MENU_PASTE,_("&Paste"))->Enable(CanPaste()); menu.Append(EDIT_MENU_PASTE,_("&Paste"))->Enable(CanPaste());
@ -990,130 +923,41 @@ void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
menu.Append(EDIT_MENU_SPLIT_PRESERVE,_("Split at cursor (preserve times)")); menu.Append(EDIT_MENU_SPLIT_PRESERVE,_("Split at cursor (preserve times)"));
menu.Append(EDIT_MENU_SPLIT_ESTIMATE,_("Split at cursor (estimate times)")); menu.Append(EDIT_MENU_SPLIT_ESTIMATE,_("Split at cursor (estimate times)"));
// Pop the menu
PopupMenu(&menu); PopupMenu(&menu);
} }
void SubsTextEditCtrl::OnSplitLinePreserve (wxCommandEvent &) {
/// @brief Split line preserving times
/// @param event
///
void SubsTextEditCtrl::OnSplitLinePreserve (wxCommandEvent &event) {
int from,to; int from,to;
GetSelection(&from, &to); GetSelection(&from, &to);
from = GetReverseUnicodePosition(from); from = GetReverseUnicodePosition(from);
to = GetReverseUnicodePosition(to); grid->SplitLine(grid->GetActiveLine(),from,0);
// Call SplitLine() with the text currently in the editbox.
// This makes sure we split what the user sees, not the committed line.
control->grid->SplitLine(control->grid->GetDialogueIndex(control->grid->GetActiveLine()),from,0,GetText());
} }
void SubsTextEditCtrl::OnSplitLineEstimate (wxCommandEvent &) {
/// @brief Split line estimating times
/// @param event
///
void SubsTextEditCtrl::OnSplitLineEstimate (wxCommandEvent &event) {
int from,to; int from,to;
GetSelection(&from, &to); GetSelection(&from, &to);
from = GetReverseUnicodePosition(from); from = GetReverseUnicodePosition(from);
to = GetReverseUnicodePosition(to); grid->SplitLine(grid->GetActiveLine(),from,1);
// Call SplitLine() with the text currently in the editbox.
// This makes sure we split what the user sees, not the committed line.
control->grid->SplitLine(control->grid->GetDialogueIndex(control->grid->GetActiveLine()),from,1,GetText());
} }
void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &) {
if (spellchecker.get()) spellchecker->AddWord(currentWord);
/// @brief Cut
/// @param event
///
void SubsTextEditCtrl::OnCut(wxCommandEvent &event) {
Cut();
}
/// @brief Copy
/// @param event
///
void SubsTextEditCtrl::OnCopy(wxCommandEvent &event) {
Copy();
}
/// @brief Paste
/// @param event
///
void SubsTextEditCtrl::OnPaste(wxCommandEvent &event) {
Paste();
}
/// @brief Undo
/// @param event
///
void SubsTextEditCtrl::OnUndo(wxCommandEvent &event) {
Undo();
}
/// @brief Select All
/// @param event
///
void SubsTextEditCtrl::OnSelectAll(wxCommandEvent &event) {
SelectAll();
}
/// @brief Add word to dictionary
/// @param event
///
void SubsTextEditCtrl::OnAddToDictionary(wxCommandEvent &event) {
if (spellchecker) spellchecker->AddWord(currentWord);
UpdateStyle(); UpdateStyle();
SetFocus(); SetFocus();
} }
/// @brief Use suggestion
/// @param event
///
void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) { void SubsTextEditCtrl::OnUseSuggestion(wxCommandEvent &event) {
// Get suggestion wxString suggestion;
wxString suggestion = sugs[event.GetId()-EDIT_MENU_SUGGESTIONS]; int sugIdx = event.GetId() - EDIT_MENU_THESAURUS_SUGS;
if (sugIdx >= 0) {
// Get boundaries of text being replaced suggestion = thesSugs[sugIdx];
int start,end; }
GetBoundsOfWordAtPosition(currentWordPos,start,end); else {
suggestion = sugs[event.GetId() - EDIT_MENU_SUGGESTIONS];
// Replace }
wxString text = GetText();
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1));
// Set selection
SetSelectionU(start,start+suggestion.Length());
SetFocus();
}
/// @brief Use thesaurus suggestion
/// @param event
///
void SubsTextEditCtrl::OnUseThesaurusSuggestion(wxCommandEvent &event) {
// Get suggestion
wxString suggestion = thesSugs[event.GetId()-EDIT_MENU_THESAURUS_SUGS];
// Stripe suggestion of parenthesis // Stripe suggestion of parenthesis
int pos = suggestion.Find(_T("(")); int pos = suggestion.Find(L"(");
if (pos != wxNOT_FOUND) { if (pos != wxNOT_FOUND) {
suggestion = suggestion.Left(pos-1); suggestion = suggestion.Left(pos-1);
} }
@ -1122,7 +966,6 @@ void SubsTextEditCtrl::OnUseThesaurusSuggestion(wxCommandEvent &event) {
int start,end; int start,end;
GetBoundsOfWordAtPosition(currentWordPos,start,end); GetBoundsOfWordAtPosition(currentWordPos,start,end);
// Replace
wxString text = GetText(); wxString text = GetText();
SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1)); SetText(text.Left(MAX(0,start)) + suggestion + text.Mid(end+1));
@ -1131,13 +974,7 @@ void SubsTextEditCtrl::OnUseThesaurusSuggestion(wxCommandEvent &event) {
SetFocus(); SetFocus();
} }
/// @brief Set dictionary language
/// @param event
///
void SubsTextEditCtrl::OnSetDicLanguage(wxCommandEvent &event) { void SubsTextEditCtrl::OnSetDicLanguage(wxCommandEvent &event) {
// Get language list
wxArrayString langs = spellchecker->GetLanguageList(); wxArrayString langs = spellchecker->GetLanguageList();
// Set dictionary // Set dictionary
@ -1147,17 +984,10 @@ void SubsTextEditCtrl::OnSetDicLanguage(wxCommandEvent &event) {
spellchecker->SetLanguage(lang); spellchecker->SetLanguage(lang);
OPT_SET("Tool/Spell Checker/Language")->SetString(STD_STR(lang)); OPT_SET("Tool/Spell Checker/Language")->SetString(STD_STR(lang));
// Update styling
UpdateStyle(); UpdateStyle();
} }
/// @brief Set thesaurus language
/// @param event
///
void SubsTextEditCtrl::OnSetThesLanguage(wxCommandEvent &event) { void SubsTextEditCtrl::OnSetThesLanguage(wxCommandEvent &event) {
// Get language list
wxArrayString langs = thesaurus->GetLanguageList(); wxArrayString langs = thesaurus->GetLanguageList();
// Set language // Set language
@ -1167,8 +997,5 @@ void SubsTextEditCtrl::OnSetThesLanguage(wxCommandEvent &event) {
thesaurus->SetLanguage(lang); thesaurus->SetLanguage(lang);
OPT_SET("Tool/Thesaurus/Language")->SetString(STD_STR(lang)); OPT_SET("Tool/Thesaurus/Language")->SetString(STD_STR(lang));
// Update styling
UpdateStyle(); UpdateStyle();
} }

View File

@ -34,19 +34,16 @@
/// @ingroup main_ui /// @ingroup main_ui
/// ///
#ifndef AGI_PRE
#include <memory>
#endif
////////////
// Includes
#include "scintilla_text_ctrl.h" #include "scintilla_text_ctrl.h"
#include "spellchecker_manager.h"
#include "thesaurus.h"
class SpellChecker;
//////////////
// Prototypes
class SubsEditBox; class SubsEditBox;
class SubtitlesGrid;
class Thesaurus;
/// DOCME /// DOCME
/// @class SubsTextEditCtrl /// @class SubsTextEditCtrl
@ -54,13 +51,13 @@ class SubsEditBox;
/// ///
/// DOCME /// DOCME
class SubsTextEditCtrl : public ScintillaTextCtrl { class SubsTextEditCtrl : public ScintillaTextCtrl {
private: /// DOCME
std::auto_ptr<SpellChecker> spellchecker;
/// DOCME /// DOCME
SpellChecker *spellchecker; std::auto_ptr<Thesaurus> thesaurus;
/// DOCME SubtitlesGrid *grid;
Thesaurus *thesaurus;
/// DOCME /// DOCME
@ -87,87 +84,21 @@ private:
void OnMouseEvent(wxMouseEvent &event); void OnMouseEvent(wxMouseEvent &event);
void OnSplitLinePreserve(wxCommandEvent &event); void OnSplitLinePreserve(wxCommandEvent &event);
void OnSplitLineEstimate(wxCommandEvent &event); void OnSplitLineEstimate(wxCommandEvent &event);
void OnCut(wxCommandEvent &event);
void OnCopy(wxCommandEvent &event);
void OnPaste(wxCommandEvent &event);
void OnUndo(wxCommandEvent &event);
void OnSelectAll(wxCommandEvent &event);
void OnAddToDictionary(wxCommandEvent &event); void OnAddToDictionary(wxCommandEvent &event);
void OnUseSuggestion(wxCommandEvent &event); void OnUseSuggestion(wxCommandEvent &event);
void OnUseThesaurusSuggestion(wxCommandEvent &event);
void OnSetDicLanguage(wxCommandEvent &event); void OnSetDicLanguage(wxCommandEvent &event);
void OnSetThesLanguage(wxCommandEvent &event); void OnSetThesLanguage(wxCommandEvent &event);
void OnLoseFocus(wxFocusEvent &event); void OnLoseFocus(wxFocusEvent &event);
public: public:
SubsTextEditCtrl(wxWindow* parent, wxSize size, long style, SubtitlesGrid *grid);
/// DOCME
SubsEditBox *control;
SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
~SubsTextEditCtrl(); ~SubsTextEditCtrl();
void SetTextTo(const wxString text); void SetTextTo(wxString text);
void UpdateStyle(int start=0,int length=-1); void UpdateStyle(int start=0,int length=-1);
void StyleSpellCheck(int start=0,int length=-1); void StyleSpellCheck(int start=0,int length=-1);
void UpdateCallTip(); void UpdateCallTip(wxStyledTextEvent &);
void SetStyles(); void SetStyles();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
///////
// IDs
enum {
/// DOCME
EDIT_MENU_SPLIT_PRESERVE = 1400,
/// DOCME
EDIT_MENU_SPLIT_ESTIMATE,
/// DOCME
EDIT_MENU_CUT,
/// DOCME
EDIT_MENU_COPY,
/// DOCME
EDIT_MENU_PASTE,
/// DOCME
EDIT_MENU_UNDO,
/// DOCME
EDIT_MENU_SELECT_ALL,
/// DOCME
EDIT_MENU_ADD_TO_DICT,
/// DOCME
EDIT_MENU_SUGGESTION,
/// DOCME
EDIT_MENU_SUGGESTIONS,
/// DOCME
EDIT_MENU_THESAURUS = 1450,
/// DOCME
EDIT_MENU_THESAURUS_SUGS,
/// DOCME
EDIT_MENU_DIC_LANGUAGE = 1600,
/// DOCME
EDIT_MENU_DIC_LANGS,
/// DOCME
EDIT_MENU_THES_LANGUAGE = 1700,
/// DOCME
EDIT_MENU_THES_LANGS
};

View File

@ -88,8 +88,6 @@ BEGIN_EVENT_TABLE(SubtitlesGrid, BaseGrid)
EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,SubtitlesGrid::OnShowColMenu) EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,SubtitlesGrid::OnShowColMenu)
END_EVENT_TABLE() END_EVENT_TABLE()
/// @brief Constructor /// @brief Constructor
/// @param parentFr /// @param parentFr
/// @param parent /// @param parent
@ -98,31 +96,22 @@ END_EVENT_TABLE()
/// @param size /// @param size
/// @param style /// @param style
/// @param name /// @param name
///
SubtitlesGrid::SubtitlesGrid(FrameMain* parentFr, wxWindow *parent, wxWindowID id, AssFile *subs, const wxPoint& pos, const wxSize& size, long style, const wxString& name) SubtitlesGrid::SubtitlesGrid(FrameMain* parentFr, wxWindow *parent, wxWindowID id, AssFile *subs, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
: BaseGrid(parent,id,pos,size,style,name) : BaseGrid(parent,id,pos,size,style,name)
, ass(subs) , ass(subs)
{ {
// Vars
byFrame = false; byFrame = false;
editBox = NULL; editBox = NULL;
parentFrame = parentFr; parentFrame = parentFr;
} }
/// @brief Destructor /// @brief Destructor
///
SubtitlesGrid::~SubtitlesGrid() { SubtitlesGrid::~SubtitlesGrid() {
ClearMaps(); ClearMaps();
} }
/// @brief Popup menu /// @brief Popup menu
/// @param alternate /// @param alternate
/// @return
///
void SubtitlesGrid::OnPopupMenu(bool alternate) { void SubtitlesGrid::OnPopupMenu(bool alternate) {
// Alternate // Alternate
if (alternate) { if (alternate) {
@ -212,11 +201,8 @@ void SubtitlesGrid::OnPopupMenu(bool alternate) {
} }
} }
/// @brief Process a show/hide column event /// @brief Process a show/hide column event
/// @param event /// @param event
///
void SubtitlesGrid::OnShowColMenu(wxCommandEvent &event) { void SubtitlesGrid::OnShowColMenu(wxCommandEvent &event) {
int item = event.GetId()-MENU_SHOW_COL; int item = event.GetId()-MENU_SHOW_COL;
showCol[item] = !showCol[item]; showCol[item] = !showCol[item];
@ -229,12 +215,8 @@ void SubtitlesGrid::OnShowColMenu(wxCommandEvent &event) {
Refresh(false); Refresh(false);
} }
/// @brief Process keyboard events /// @brief Process keyboard events
/// @param event /// @param event
/// @return
///
void SubtitlesGrid::OnKeyDown(wxKeyEvent &event) { void SubtitlesGrid::OnKeyDown(wxKeyEvent &event) {
// Get key // Get key
#ifdef __APPLE__ #ifdef __APPLE__
@ -322,103 +304,70 @@ void SubtitlesGrid::OnKeyDown(wxKeyEvent &event) {
event.Skip(); event.Skip();
} }
void SubtitlesGrid::OnDuplicate (wxCommandEvent &) {
///////////////////////
// Duplicate selection
void SubtitlesGrid::OnDuplicate (wxCommandEvent &WXUNUSED(&event)) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
DuplicateLines(sels.front(),sels.back()); DuplicateLines(sels.front(),sels.back());
EndBatch(); EndBatch();
} }
void SubtitlesGrid::OnDuplicateNextFrame (wxCommandEvent &) {
//////////////////////////////////////////////
// Duplicate selection and shift by one frame
void SubtitlesGrid::OnDuplicateNextFrame (wxCommandEvent &WXUNUSED(&event)) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
DuplicateLines(sels.front(),sels.back(),true); DuplicateLines(sels.front(),sels.back(),true);
EndBatch(); EndBatch();
} }
/// @brief Call swap /// @brief Call swap
/// @param event void SubtitlesGrid::OnSwap (wxCommandEvent &) {
///
void SubtitlesGrid::OnSwap (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
SwapLines(sels.front(),sels.back()); SwapLines(sels.front(),sels.back());
EndBatch(); EndBatch();
} }
/// @brief Call join (concatenate) /// @brief Call join (concatenate)
/// @param event void SubtitlesGrid::OnJoinConcat (wxCommandEvent &) {
///
void SubtitlesGrid::OnJoinConcat (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
JoinLines(sels.front(),sels.back(),true); JoinLines(sels.front(),sels.back(),true);
EndBatch(); EndBatch();
} }
/// @brief Call join (replace) /// @brief Call join (replace)
/// @param event void SubtitlesGrid::OnJoinReplace (wxCommandEvent &) {
///
void SubtitlesGrid::OnJoinReplace (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
JoinLines(sels.front(),sels.back(),false); JoinLines(sels.front(),sels.back(),false);
EndBatch(); EndBatch();
} }
/// @brief Adjoin lines /// @brief Adjoin lines
/// @param event void SubtitlesGrid::OnAdjoin (wxCommandEvent &) {
///
void SubtitlesGrid::OnAdjoin (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
AdjoinLines(sels.front(),sels.back(),true); AdjoinLines(sels.front(),sels.back(),true);
EndBatch(); EndBatch();
} }
/// @brief DOCME /// @brief DOCME
/// @param event void SubtitlesGrid::OnAdjoin2 (wxCommandEvent &) {
///
void SubtitlesGrid::OnAdjoin2 (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
AdjoinLines(sels.front(),sels.back(),false); AdjoinLines(sels.front(),sels.back(),false);
EndBatch(); EndBatch();
} }
/// @brief Call join as karaoke /// @brief Call join as karaoke
/// @param event void SubtitlesGrid::OnJoinAsKaraoke (wxCommandEvent &) {
///
void SubtitlesGrid::OnJoinAsKaraoke (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
JoinAsKaraoke(sels.front(),sels.back()); JoinAsKaraoke(sels.front(),sels.back());
EndBatch(); EndBatch();
} }
/// @brief Call split by karaoke /// @brief Call split by karaoke
/// @param event void SubtitlesGrid::OnSplitByKaraoke (wxCommandEvent &) {
///
void SubtitlesGrid::OnSplitByKaraoke (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
wxArrayInt sels = GetSelection(); wxArrayInt sels = GetSelection();
bool didSplit = false; bool didSplit = false;
@ -432,12 +381,8 @@ void SubtitlesGrid::OnSplitByKaraoke (wxCommandEvent &event) {
EndBatch(); EndBatch();
} }
/// @brief Call insert before /// @brief Call insert before
/// @param event void SubtitlesGrid::OnInsertBefore (wxCommandEvent &) {
///
void SubtitlesGrid::OnInsertBefore (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
// Find line // Find line
int n = GetFirstSelRow(); int n = GetFirstSelRow();
@ -466,12 +411,8 @@ void SubtitlesGrid::OnInsertBefore (wxCommandEvent &event) {
EndBatch(); EndBatch();
} }
/// @brief Call insert after /// @brief Call insert after
/// @param event void SubtitlesGrid::OnInsertAfter (wxCommandEvent &) {
///
void SubtitlesGrid::OnInsertAfter (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
// Find line // Find line
int n = GetFirstSelRow(); int n = GetFirstSelRow();
@ -498,12 +439,8 @@ void SubtitlesGrid::OnInsertAfter (wxCommandEvent &event) {
EndBatch(); EndBatch();
} }
/// @brief Call insert before with video /// @brief Call insert before with video
/// @param event void SubtitlesGrid::OnInsertBeforeVideo (wxCommandEvent &) {
///
void SubtitlesGrid::OnInsertBeforeVideo (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
// Find line // Find line
int n = GetFirstSelRow(); int n = GetFirstSelRow();
@ -522,12 +459,8 @@ void SubtitlesGrid::OnInsertBeforeVideo (wxCommandEvent &event) {
EndBatch(); EndBatch();
} }
/// @brief Call insert after with video /// @brief Call insert after with video
/// @param event void SubtitlesGrid::OnInsertAfterVideo (wxCommandEvent &) {
///
void SubtitlesGrid::OnInsertAfterVideo (wxCommandEvent &event) {
BeginBatch(); BeginBatch();
// Find line // Find line
int n = GetFirstSelRow(); int n = GetFirstSelRow();
@ -546,75 +479,51 @@ void SubtitlesGrid::OnInsertAfterVideo (wxCommandEvent &event) {
EndBatch(); EndBatch();
} }
/// Copy selection to clipboard
/////////////////////////////// void SubtitlesGrid::OnCopyLines (wxCommandEvent &) {
// Copy selection to clipboard
void SubtitlesGrid::OnCopyLines (wxCommandEvent &WXUNUSED(&event)) {
CopyLines(GetSelection()); CopyLines(GetSelection());
} }
/// Cuts selection to clipboard
/////////////////////////////// void SubtitlesGrid::OnCutLines (wxCommandEvent &) {
// Cuts selection to clipboard
void SubtitlesGrid::OnCutLines (wxCommandEvent &WXUNUSED(&event)) {
CutLines(GetSelection()); CutLines(GetSelection());
} }
/// Paste from clipboard
//////////////////////// void SubtitlesGrid::OnPasteLines (wxCommandEvent &) {
// Paste from clipboard
void SubtitlesGrid::OnPasteLines (wxCommandEvent &WXUNUSED(&event)) {
PasteLines(GetFirstSelRow()); PasteLines(GetFirstSelRow());
} }
/// Copy selection to clipboard
/////////////////////////////// void SubtitlesGrid::OnDeleteLines (wxCommandEvent &) {
// Copy selection to clipboard
void SubtitlesGrid::OnDeleteLines (wxCommandEvent &WXUNUSED(&event)) {
BeginBatch(); BeginBatch();
DeleteLines(GetSelection()); DeleteLines(GetSelection());
EndBatch(); EndBatch();
} }
/// @brief Set start to video pos /// @brief Set start to video pos
/// @param event void SubtitlesGrid::OnSetStartToVideo(wxCommandEvent &) {
///
void SubtitlesGrid::OnSetStartToVideo(wxCommandEvent &event) {
BeginBatch(); BeginBatch();
SetSubsToVideo(true); SetSubsToVideo(true);
EndBatch(); EndBatch();
} }
/// @brief Set end to video pos /// @brief Set end to video pos
/// @param event void SubtitlesGrid::OnSetEndToVideo(wxCommandEvent &) {
///
void SubtitlesGrid::OnSetEndToVideo(wxCommandEvent &event) {
BeginBatch(); BeginBatch();
SetSubsToVideo(false); SetSubsToVideo(false);
EndBatch(); EndBatch();
} }
/// @brief Set video pos to start /// @brief Set video pos to start
/// @param event void SubtitlesGrid::OnSetVideoToStart(wxCommandEvent &) {
///
void SubtitlesGrid::OnSetVideoToStart(wxCommandEvent &event) {
BeginBatch(); BeginBatch();
SetVideoToSubs(true); SetVideoToSubs(true);
EndBatch(); EndBatch();
} }
/// @brief Set video pos to end /// @brief Set video pos to end
/// @param event void SubtitlesGrid::OnSetVideoToEnd(wxCommandEvent &) {
///
void SubtitlesGrid::OnSetVideoToEnd(wxCommandEvent &event) {
BeginBatch(); BeginBatch();
SetVideoToSubs(false); SetVideoToSubs(false);
EndBatch(); EndBatch();
@ -718,14 +627,8 @@ void SubtitlesGrid::OnRecombine(wxCommandEvent &) {
SetActiveLine(activeLine); SetActiveLine(activeLine);
} }
/// @brief Export audio clip of line /// @brief Export audio clip of line
/// @param event void SubtitlesGrid::OnAudioClip(wxCommandEvent &) {
/// @return
///
void SubtitlesGrid::OnAudioClip(wxCommandEvent &event) {
int64_t num_samples,start=0,end=0,temp; int64_t num_samples,start=0,end=0,temp;
AudioDisplay *audioDisplay = parentFrame->audioBox->audioDisplay; AudioDisplay *audioDisplay = parentFrame->audioBox->audioDisplay;
AudioProvider *provider = audioDisplay->provider; AudioProvider *provider = audioDisplay->provider;
@ -805,7 +708,6 @@ void SubtitlesGrid::OnAudioClip(wxCommandEvent &event) {
/// @brief Clears grid and sets it to default /// @brief Clears grid and sets it to default
/// @param _ass /// @param _ass
///
void SubtitlesGrid::LoadDefault () { void SubtitlesGrid::LoadDefault () {
ass->LoadDefault(); ass->LoadDefault();
ClearMaps(); ClearMaps();
@ -824,13 +726,9 @@ void SubtitlesGrid::UpdateMaps(bool preserve_selected_rows) {
} }
} }
/// @brief Swaps two lines /// @brief Swaps two lines
/// @param n1 /// @param n1
/// @param n2 /// @param n2
/// @return
///
void SubtitlesGrid::SwapLines(int n1,int n2) { void SubtitlesGrid::SwapLines(int n1,int n2) {
AssDialogue *dlg1 = GetDialogue(n1); AssDialogue *dlg1 = GetDialogue(n1);
AssDialogue *dlg2 = GetDialogue(n2); AssDialogue *dlg2 = GetDialogue(n2);
@ -842,14 +740,11 @@ void SubtitlesGrid::SwapLines(int n1,int n2) {
CommitChanges(); CommitChanges();
} }
/// @brief Insert a line /// @brief Insert a line
/// @param line /// @param line
/// @param n /// @param n
/// @param after /// @param after
/// @param update /// @param update
///
void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) { void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
AssDialogue *rel_line = GetDialogue(n + (after?1:0)); AssDialogue *rel_line = GetDialogue(n + (after?1:0));
entryIter pos = std::find(ass->Line.begin(), ass->Line.end(), rel_line); entryIter pos = std::find(ass->Line.begin(), ass->Line.end(), rel_line);
@ -864,11 +759,6 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
} }
} }
/// @brief Copy lines to clipboard
/// @param target
///
void SubtitlesGrid::CopyLines(wxArrayInt target) { void SubtitlesGrid::CopyLines(wxArrayInt target) {
// Prepare text // Prepare text
wxString data = _T(""); wxString data = _T("");
@ -889,11 +779,6 @@ void SubtitlesGrid::CopyLines(wxArrayInt target) {
} }
} }
/// @brief Cut to clipboard
/// @param target
///
void SubtitlesGrid::CutLines(wxArrayInt target) { void SubtitlesGrid::CutLines(wxArrayInt target) {
BeginBatch(); BeginBatch();
CopyLines(target); CopyLines(target);
@ -901,18 +786,14 @@ void SubtitlesGrid::CutLines(wxArrayInt target) {
EndBatch(); EndBatch();
} }
/// @brief Paste lines from clipboard /// @brief Paste lines from clipboard
/// @param n /// @param n
/// @param pasteOver /// @param pasteOver
/// @return
///
void SubtitlesGrid::PasteLines(int n,bool pasteOver) { void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
BeginBatch(); BeginBatch();
// Prepare text // Prepare text
wxString data = _T(""); wxString data;
// Read from clipboard // Read from clipboard
if (wxTheClipboard->Open()) { if (wxTheClipboard->Open()) {
@ -941,7 +822,7 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
curdiag = new AssDialogue(curdata); curdiag = new AssDialogue(curdata);
} }
catch (...) { catch (...) {
// Line didn't parse correcly, assume it's plain text that // Line didn't parse correctly, assume it's plain text that
// should be pasted in the Text field only // should be pasted in the Text field only
curdiag = new AssDialogue(); curdiag = new AssDialogue();
curdiag->Text = curdata; curdiag->Text = curdata;
@ -972,7 +853,6 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
if (pasteOverOptions[5]) target->Margin[0] = curdiag->Margin[0]; if (pasteOverOptions[5]) target->Margin[0] = curdiag->Margin[0];
if (pasteOverOptions[6]) target->Margin[1] = curdiag->Margin[1]; if (pasteOverOptions[6]) target->Margin[1] = curdiag->Margin[1];
if (pasteOverOptions[7]) target->Margin[2] = curdiag->Margin[2]; if (pasteOverOptions[7]) target->Margin[2] = curdiag->Margin[2];
//if (pasteOverOptions[8]) target->Margin[3] = curdiag->Margin[3];
if (pasteOverOptions[8]) target->Effect = curdiag->Effect; if (pasteOverOptions[8]) target->Effect = curdiag->Effect;
if (pasteOverOptions[9]) target->Text = curdiag->Text; if (pasteOverOptions[9]) target->Text = curdiag->Text;
} }
@ -1004,17 +884,9 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
} }
} }
} }
// Done
EndBatch(); EndBatch();
} }
/// @brief Delete selected lines
/// @param target
/// @param flagModified
///
void SubtitlesGrid::DeleteLines(wxArrayInt target, bool flagModified) { void SubtitlesGrid::DeleteLines(wxArrayInt target, bool flagModified) {
entryIter before_first = std::find_if(ass->Line.begin(), ass->Line.end(), cast<AssDialogue*>()); --before_first; entryIter before_first = std::find_if(ass->Line.begin(), ass->Line.end(), cast<AssDialogue*>()); --before_first;
int old_active_line_index = GetDialogueIndex(GetActiveLine()); int old_active_line_index = GetDialogueIndex(GetActiveLine());
@ -1048,18 +920,10 @@ void SubtitlesGrid::DeleteLines(wxArrayInt target, bool flagModified) {
} }
} }
/// @brief Joins selected lines
/// @param n1
/// @param n2
/// @param concat
///
void SubtitlesGrid::JoinLines(int n1,int n2,bool concat) { void SubtitlesGrid::JoinLines(int n1,int n2,bool concat) {
// Initialize int min_ms = INT_MAX;
int min_ms = 0x0FFFFFFF; int max_ms = INT_MIN;
int max_ms = -1; wxString finalText;
wxString finalText = _T("");
// Collect data // Collect data
AssDialogue *cur; AssDialogue *cur;
@ -1110,14 +974,6 @@ void SubtitlesGrid::JoinLines(int n1,int n2,bool concat) {
SelectRow(n1); SelectRow(n1);
} }
/// @brief Adjoins selected lines
/// @param n1
/// @param n2
/// @param setStart
/// @return
///
void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) { void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) {
// Set start // Set start
if (setStart) { if (setStart) {
@ -1143,19 +999,11 @@ void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) {
} }
} }
// Commit
ass->Commit(_("adjoin")); ass->Commit(_("adjoin"));
CommitChanges(); CommitChanges();
} }
/// @brief Joins selected lines as karaoke
/// @param n1
/// @param n2
///
void SubtitlesGrid::JoinAsKaraoke(int n1,int n2) { void SubtitlesGrid::JoinAsKaraoke(int n1,int n2) {
// Initialize
wxString finalText = _T(""); wxString finalText = _T("");
// Collect data // Collect data
@ -1202,13 +1050,6 @@ void SubtitlesGrid::JoinAsKaraoke(int n1,int n2) {
SelectRow(n1); SelectRow(n1);
} }
/// @brief Duplicate lines
/// @param n1
/// @param n2
/// @param nextFrame
///
void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) { void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) {
AssDialogue *cur; AssDialogue *cur;
bool update = false; bool update = false;
@ -1239,91 +1080,41 @@ void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) {
SetActiveLine(GetDialogue(n1+step)); SetActiveLine(GetDialogue(n1+step));
} }
/// @brief Shifts line by time
/// @param n
/// @param len
/// @param type
///
/// Where type =
/// - 0: Start + End
/// - 1: Start
/// - 2: End
void SubtitlesGrid::ShiftLineByTime(int n,int len,int type) { void SubtitlesGrid::ShiftLineByTime(int n,int len,int type) {
assert(type >= 0 && type <= 2);
AssDialogue *cur = GetDialogue(n); AssDialogue *cur = GetDialogue(n);
if (type != 2) cur->Start.SetMS(cur->Start.GetMS() + len); if (type != 2) cur->Start.SetMS(cur->Start.GetMS() + len);
if (type != 1) cur->End.SetMS(cur->End.GetMS() + len); if (type != 1) cur->End.SetMS(cur->End.GetMS() + len);
} }
/// @brief Shifts line by Frame
/// @param n
/// @param len
/// @param type
///
/// @see ShiftLineByTime()
void SubtitlesGrid::ShiftLineByFrames(int n,int len,int type) { void SubtitlesGrid::ShiftLineByFrames(int n,int len,int type) {
assert(type >= 0 && type <= 2);
AssDialogue *cur = GetDialogue(n); AssDialogue *cur = GetDialogue(n);
if (type != 2) cur->Start.SetMS(context->TimeAtFrame(len + context->FrameAtTime(cur->Start.GetMS(),agi::vfr::START),agi::vfr::START)); if (type != 2) cur->Start.SetMS(context->TimeAtFrame(len + context->FrameAtTime(cur->Start.GetMS(),agi::vfr::START),agi::vfr::START));
if (type != 1) cur->End.SetMS(context->TimeAtFrame(len + context->FrameAtTime(cur->End.GetMS(),agi::vfr::END),agi::vfr::END)); if (type != 1) cur->End.SetMS(context->TimeAtFrame(len + context->FrameAtTime(cur->End.GetMS(),agi::vfr::END),agi::vfr::END));
} }
void SubtitlesGrid::SplitLine(AssDialogue *n1,int pos,bool estimateTimes) {
AssDialogue *n2 = new AssDialogue(*n1);
InsertLine(n2,GetDialogueIndex(n1),true,false);
/// @brief Split line
/// @param n
/// @param pos
/// @param mode
/// @param textIn
/// @return
///
void SubtitlesGrid::SplitLine(int n,int pos,int mode,wxString textIn) {
// Split
AssDialogue *n1,*n2;
// No textIn? Get saved text
if (textIn.IsEmpty()) {
n1 = GetDialogue(n);
n2 = new AssDialogue(n1->GetEntryData());
}
// Otherwise use textIn
else {
n1 = GetDialogue(n);
n1->Text = textIn;
n2 = new AssDialogue(n1->GetEntryData());
}
InsertLine(n2,n,true,false);
// Modify text
wxString orig = n1->Text; wxString orig = n1->Text;
n1->Text = orig.Left(pos).Trim(true); // Trim off trailing whitespace n1->Text = orig.Left(pos).Trim(true); // Trim off trailing whitespace
n2->Text = orig.Mid(pos).Trim(false); // Trim off leading whitespace n2->Text = orig.Mid(pos).Trim(false); // Trim off leading whitespace
// Modify time if (estimateTimes) {
if (mode == 1) {
double splitPos = double(pos)/orig.Length(); double splitPos = double(pos)/orig.Length();
int splitTime = (int)((n1->End.GetMS() - n1->Start.GetMS())*splitPos) + n1->Start.GetMS(); int splitTime = (int)((n1->End.GetMS() - n1->Start.GetMS())*splitPos) + n1->Start.GetMS();
n1->End.SetMS(splitTime); n1->End.SetMS(splitTime);
n2->Start.SetMS(splitTime); n2->Start.SetMS(splitTime);
} }
// Update editbox and audio
//editBox->SetToLine(n);
// Commit
ass->Commit(_("split")); ass->Commit(_("split"));
CommitChanges(); CommitChanges(false);
} }
/// @brief Returns true if changes were made. DOES NOT FLAG AS MODIFIED OR COMMIT CHANGES timed as the syllables. Splits the line into as many new lines as there are karaoke syllables, --------------------- Split line by karaoke
/// @param lineNumber
/// @return
///
bool SubtitlesGrid::SplitLineByKaraoke(int lineNumber) { bool SubtitlesGrid::SplitLineByKaraoke(int lineNumber) {
AssDialogue *line = GetDialogue(lineNumber); AssDialogue *line = GetDialogue(lineNumber);
@ -1363,29 +1154,20 @@ bool SubtitlesGrid::SplitLineByKaraoke(int lineNumber) {
return true; return true;
} }
void SubtitlesGrid::CommitChanges(bool ebox, bool video, bool autosave) {
if (video && context->IsLoaded()) {
/// @brief This will save the work .ass and refresh it -------------- Commit changes
/// @param force
/// @param videoOnly
///
void SubtitlesGrid::CommitChanges(bool force,bool videoOnly) {
if (context->IsLoaded() || force) {
// Check if it's playing
bool playing = false; bool playing = false;
if (context->IsPlaying()) { if (context->IsPlaying()) {
playing = true; playing = true;
context->Stop(); context->Stop();
} }
// Update video context->Refresh();
if (context->IsLoaded()) context->Refresh();
// Resume play
if (playing) context->Play(); if (playing) context->Play();
} }
if (!videoOnly) { if (autosave) {
// Autosave if option is enabled // Autosave if option is enabled
if (OPT_GET("App/Auto/Save on Every Change")->GetBool()) { if (OPT_GET("App/Auto/Save on Every Change")->GetBool()) {
if (ass->IsModified() && !ass->filename.IsEmpty()) parentFrame->SaveSubtitles(false); if (ass->IsModified() && !ass->filename.IsEmpty()) parentFrame->SaveSubtitles(false);
@ -1396,12 +1178,11 @@ void SubtitlesGrid::CommitChanges(bool force,bool videoOnly) {
SetColumnWidths(); SetColumnWidths();
Refresh(false); Refresh(false);
} }
if (ebox) {
editBox->Update(false, false);
}
} }
/// @brief Set start to video pos
/// @param start
/// @return
///
void SubtitlesGrid::SetSubsToVideo(bool start) { void SubtitlesGrid::SetSubsToVideo(bool start) {
if (!context->IsLoaded()) return; if (!context->IsLoaded()) return;
@ -1410,18 +1191,16 @@ void SubtitlesGrid::SetSubsToVideo(bool start) {
// Update selection // Update selection
wxArrayInt sel = GetSelection(); wxArrayInt sel = GetSelection();
AssDialogue *cur; bool modified = false;
int modified =0;
for (size_t i=0;i<sel.Count();i++) { for (size_t i=0;i<sel.Count();i++) {
cur = GetDialogue(sel[i]); AssDialogue *cur = GetDialogue(sel[i]);
if (cur) { if (cur) {
modified++; modified = true;
if (start) cur->Start.SetMS(ms); if (start) cur->Start.SetMS(ms);
else cur->End.SetMS(ms); else cur->End.SetMS(ms);
} }
} }
// Commit
if (modified) { if (modified) {
ass->Commit(_("timing")); ass->Commit(_("timing"));
CommitChanges(); CommitChanges();
@ -1429,12 +1208,6 @@ void SubtitlesGrid::SetSubsToVideo(bool start) {
} }
} }
/// @brief Set video pos to start/end
/// @param start
/// @return
///
void SubtitlesGrid::SetVideoToSubs(bool start) { void SubtitlesGrid::SetVideoToSubs(bool start) {
wxArrayInt sel = GetSelection(); wxArrayInt sel = GetSelection();
if (sel.Count() == 0) return; if (sel.Count() == 0) return;
@ -1468,8 +1241,6 @@ std::vector<int> SubtitlesGrid::GetAbsoluteSelection() {
return result; return result;
} }
/// @brief Update list of selected lines from absolute selection /// @brief Update list of selected lines from absolute selection
/// @param selection /// @param selection
/// ///
@ -1490,5 +1261,3 @@ void SubtitlesGrid::SetSelectionFromAbsolute(std::vector<int> &selection) {
SetSelectedSet(newsel); SetSelectedSet(newsel);
} }

View File

@ -56,7 +56,6 @@ class SubsEditBox;
class FrameMain; class FrameMain;
class AudioDisplay; class AudioDisplay;
/// DOCME
typedef std::list<AssEntry*>::iterator entryIter; typedef std::list<AssEntry*>::iterator entryIter;
/// DOCME /// DOCME
@ -95,127 +94,120 @@ private:
void OnShowColMenu(wxCommandEvent &event); void OnShowColMenu(wxCommandEvent &event);
public: public:
/// Currently open file
/// DOCME
AssFile *ass; AssFile *ass;
SubtitlesGrid(FrameMain* parentFrame,wxWindow *parent, wxWindowID id, AssFile *subs, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr); SubtitlesGrid(FrameMain* parentFrame,wxWindow *parent, wxWindowID id, AssFile *subs, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);
~SubtitlesGrid(); ~SubtitlesGrid();
void LoadDefault(); void LoadDefault();
void CommitChanges(bool force=false,bool videoOnly=false); /// @brief Commit changes and update the current file
/// @param ebox Update the edit box
/// @param video Update the video display
/// @param complete Autosave (if enabled) and update other things which care about the file
void CommitChanges(bool ebox = true, bool video = true, bool complete = true);
void UpdateMaps(bool preserve_selected_rows = false); void UpdateMaps(bool preserve_selected_rows = false);
/// @brief Jump to the start/end time of the current subtitle line
/// @param start Start vs. End time
void SetVideoToSubs(bool start); void SetVideoToSubs(bool start);
/// @brief Set the start/end time of the current subtitle line to the current frame
/// @param start Start vs. End time
void SetSubsToVideo(bool start); void SetSubsToVideo(bool start);
/// @brief Join the selected lines
/// @param n1 First line to join
/// @param n2 Last line to join
/// @param concat Concatenate the lines rather than discarding all past the first
void JoinLines(int first,int last,bool concat=true); void JoinLines(int first,int last,bool concat=true);
/// @brief Join selected lines as karaoke, with their relative times used for syllable lengths
/// @param n1 First line to join
/// @param n2 Last line to join
void JoinAsKaraoke(int first,int last); void JoinAsKaraoke(int first,int last);
/// @brief Adjoins selected lines, setting each line's start time to the previous line's end time
/// @param n1 First line to adjoin
/// @param n2 Last line to adjoin
/// @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);
void SplitLine(int lineNumber,int splitPosition,int mode,wxString splitText = _T("")); /// @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 Split a line into as many new lines as there are karaoke syllables, timed as the syllables
/// @param lineNumber Line to split
/// @return Were changes made?
///
/// DOES NOT FLAG AS MODIFIED OR COMMIT CHANGES
bool SplitLineByKaraoke(int lineNumber); bool SplitLineByKaraoke(int lineNumber);
/// @brief Duplicate lines
/// @param n1 First frame to duplicate
/// @param n2 Last frame to duplicate
/// @param nextFrame Set the new lines to start and end on the next frame
void DuplicateLines(int first,int last,bool nextFrame=false); void DuplicateLines(int first,int last,bool nextFrame=false);
void SwapLines(int line1,int line2); void SwapLines(int line1,int line2);
/// @brief Shift line by time
/// @param n Line to shift
/// @param len ms to shift by
/// @param type 0: Start + End; 1: Start; 2: End
void ShiftLineByTime(int lineNumber,int len,int type); void ShiftLineByTime(int lineNumber,int len,int type);
/// @brief Shift line by frames
/// @param n Line to shift
/// @param len frames to shift by
/// @param type 0: Start + End; 1: Start; 2: End
void ShiftLineByFrames(int lineNumber,int len,int type); void ShiftLineByFrames(int lineNumber,int len,int type);
void InsertLine(AssDialogue *line,int position,bool insertAfter,bool update=true); void InsertLine(AssDialogue *line,int position,bool insertAfter,bool update=true);
/// @brief Delete selected lines
/// @param target Lines to delete
/// @param flagModified Commit the file afterwards
void DeleteLines(wxArrayInt lines, bool flagModified=true); void DeleteLines(wxArrayInt lines, bool flagModified=true);
/// @brief Copy to clipboard
/// @param target Lines to copy
void CopyLines(wxArrayInt lines); void CopyLines(wxArrayInt lines);
/// @brief Cut to clipboard
/// @param target Lines to cut
void CutLines(wxArrayInt lines); void CutLines(wxArrayInt lines);
void PasteLines(int pos,bool over=false); void PasteLines(int pos,bool over=false);
/// Retrieve a list of selected lines in the actual ASS file (i.e. not as displayed in the grid but as represented in the file)
std::vector<int> GetAbsoluteSelection(); std::vector<int> GetAbsoluteSelection();
/// @brief Update list of selected lines from absolute selection
/// @param selection Sorted list of selections
void SetSelectionFromAbsolute(std::vector<int> &selection); void SetSelectionFromAbsolute(std::vector<int> &selection);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/// Menu event IDs
///////
// IDs
enum { enum {
/// DOCME
MENU_GRID_START = 1200, MENU_GRID_START = 1200,
/// DOCME
MENU_INSERT_BEFORE, MENU_INSERT_BEFORE,
/// DOCME
MENU_INSERT_AFTER, MENU_INSERT_AFTER,
/// DOCME
MENU_INSERT_BEFORE_VIDEO, MENU_INSERT_BEFORE_VIDEO,
/// DOCME
MENU_INSERT_AFTER_VIDEO, MENU_INSERT_AFTER_VIDEO,
/// DOCME
MENU_SWAP, MENU_SWAP,
/// DOCME
MENU_DUPLICATE, MENU_DUPLICATE,
/// DOCME
MENU_DUPLICATE_NEXT_FRAME, MENU_DUPLICATE_NEXT_FRAME,
/// DOCME
MENU_SPLIT_BY_KARAOKE, MENU_SPLIT_BY_KARAOKE,
/// DOCME
MENU_COPY, MENU_COPY,
/// DOCME
MENU_PASTE, MENU_PASTE,
/// DOCME
MENU_CUT, MENU_CUT,
/// DOCME
MENU_DELETE, MENU_DELETE,
/// DOCME
MENU_JOIN_CONCAT, MENU_JOIN_CONCAT,
/// DOCME
MENU_JOIN_REPLACE, MENU_JOIN_REPLACE,
/// DOCME
MENU_ADJOIN, MENU_ADJOIN,
/// DOCME
MENU_ADJOIN2, MENU_ADJOIN2,
/// DOCME
MENU_JOIN_AS_KARAOKE, MENU_JOIN_AS_KARAOKE,
/// DOCME
MENU_RECOMBINE, MENU_RECOMBINE,
/// DOCME
MENU_SET_START_TO_VIDEO, MENU_SET_START_TO_VIDEO,
/// DOCME
MENU_SET_END_TO_VIDEO, MENU_SET_END_TO_VIDEO,
/// DOCME
MENU_SET_VIDEO_TO_START, MENU_SET_VIDEO_TO_START,
/// DOCME
MENU_SET_VIDEO_TO_END, MENU_SET_VIDEO_TO_END,
/// DOCME
MENU_GRID_END, MENU_GRID_END,
/// DOCME
MENU_AUDIOCLIP, MENU_AUDIOCLIP,
/// DOCME
MENU_SHOW_COL = 1250 // Don't put anything after this MENU_SHOW_COL = 1250 // Don't put anything after this
}; };

View File

@ -102,10 +102,8 @@ wxTextCtrl(parent,id,value,pos,size,TimeEditWindowStyle | style,validator,name)
ready = true; ready = true;
byFrame = false; byFrame = false;
isEnd = false; isEnd = false;
modified = false;
showModified = false; Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this);
Connect(wxEVT_COMMAND_TEXT_UPDATED,wxCommandEventHandler(TimeEdit::OnModified));
Connect(wxEVT_KILL_FOCUS,wxFocusEventHandler(TimeEdit::OnKillFocus));
} }
BEGIN_EVENT_TABLE(TimeEdit, wxTextCtrl) BEGIN_EVENT_TABLE(TimeEdit, wxTextCtrl)
@ -119,52 +117,41 @@ END_EVENT_TABLE()
/// @param event /// @param event
void TimeEdit::OnModified(wxCommandEvent &event) { void TimeEdit::OnModified(wxCommandEvent &event) {
event.Skip(); event.Skip();
if (!ready) return;
Modified(); Modified();
} }
/// @brief Modified function /// @brief Modified function
/// @param byUser void TimeEdit::Modified() {
void TimeEdit::Modified(bool byUser) {
if (!ready) return; if (!ready) return;
ready = false; ready = false;
if (byFrame) Update(); if (byFrame) Update();
else UpdateTime(byUser); else UpdateTime(true);
// Colour
if (showModified && !modified) {
SetBackgroundColour(lagi_wxColour(OPT_GET("Colour/Background/Modified")->GetColour()));
}
modified = true;
ready = true; ready = true;
} }
/// @brief Set time and update stuff /// @brief Set time and update stuff
/// @param ms /// @param ms
/// @param setModified /// @param setModified
/// void TimeEdit::SetTime(AssTime newTime) {
void TimeEdit::SetTime(int ms,bool setModified) { if (newTime != time) {
int oldMs = time.GetMS(); time = newTime;
time.SetMS(ms);
UpdateText(); UpdateText();
if (setModified && oldMs != ms) Modified(false); }
} }
/// @brief Toggles between set by frame and time /// @brief Toggles between set by frame and time
/// @param enable /// @param enable
void TimeEdit::SetByFrame(bool enable) { void TimeEdit::SetByFrame(bool enableByFrame) {
if (enable == byFrame) return; if (enableByFrame == byFrame) return;
// By frames if (enableByFrame) {
if (enable) {
if (VideoContext::Get()->IsLoaded()) { if (VideoContext::Get()->IsLoaded()) {
byFrame = true; byFrame = true;
UpdateText(); UpdateText();
} }
} }
// By actual time
else { else {
byFrame = false; byFrame = false;
UpdateText(); UpdateText();
@ -172,44 +159,32 @@ void TimeEdit::SetByFrame(bool enable) {
} }
/// @brief Update text to reflect time value /// @brief Update text to reflect time value
///
void TimeEdit::UpdateText() { void TimeEdit::UpdateText() {
ready = false; ready = false;
if (byFrame) { if (byFrame) {
int frame_n = VideoContext::Get()->FrameAtTime(time.GetMS(),isEnd ? agi::vfr::END : agi::vfr::START); int frame_n = VideoContext::Get()->FrameAtTime(time.GetMS(),isEnd ? agi::vfr::END : agi::vfr::START);
SetValue(wxString::Format(_T("%i"),frame_n)); ChangeValue(wxString::Format("%i", frame_n));
} }
else SetValue(time.GetASSFormated()); else ChangeValue(time.GetASSFormated());
ready = true; ready = true;
} }
/// @brief Update /// @brief Update
///
void TimeEdit::Update() { void TimeEdit::Update() {
// Update frame
if (byFrame) { if (byFrame) {
long temp; long temp;
GetValue().ToLong(&temp); GetValue().ToLong(&temp);
time.SetMS(VideoContext::Get()->TimeAtFrame(temp,isEnd ? agi::vfr::END : agi::vfr::START)); SetTime(VideoContext::Get()->TimeAtFrame(temp,isEnd ? agi::vfr::END : agi::vfr::START));
} }
// Update time if not on insertion mode // Update time if not on insertion mode
else if (!OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool()) { else if (!OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool()) {
UpdateTime(); UpdateTime();
SetValue(time.GetASSFormated());
} }
// Update modified status
if (modified && showModified) {
SetBackgroundColour(wxNullColour);
Refresh();
}
modified = false;
} }
/// @brief Reads value from a text control and update it /// @brief Reads value from a text control and update it
/// @param byUser /// @param byUser
///
void TimeEdit::UpdateTime(bool byUser) { void TimeEdit::UpdateTime(bool byUser) {
bool insertion = OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool(); bool insertion = OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool();
wxString text = GetValue(); wxString text = GetValue();
@ -235,14 +210,13 @@ void TimeEdit::UpdateTime(bool byUser) {
// Update time // Update time
time.ParseASS(text); time.ParseASS(text);
if (insertion) { if (insertion) {
SetValue(time.GetASSFormated()); ChangeValue(time.GetASSFormated());
SetSelection(start,end); SetSelection(start,end);
} }
} }
/// @brief Key pressed /// @brief Key pressed
/// @param event /// @param event
///
void TimeEdit::OnKeyDown(wxKeyEvent &event) { void TimeEdit::OnKeyDown(wxKeyEvent &event) {
// Get key ID // Get key ID
int key = event.GetKeyCode(); int key = event.GetKeyCode();
@ -281,19 +255,6 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) {
} }
} }
/// @brief Focus lost
/// @param event
///
void TimeEdit::OnKillFocus(wxFocusEvent &event) {
if (!byFrame && !OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool()) {
if (time.GetASSFormated() != GetValue()) {
UpdateTime();
SetValue(time.GetASSFormated());
}
}
event.Skip();
}
///// Mouse/copy/paste events down here ///// ///// Mouse/copy/paste events down here /////
/// @brief Mouse event /// @brief Mouse event
@ -315,9 +276,7 @@ void TimeEdit::OnMouseEvent(wxMouseEvent &event) {
} }
/// @brief Menu Copy /// @brief Menu Copy
/// @param event void TimeEdit::OnCopy(wxCommandEvent &) {
///
void TimeEdit::OnCopy(wxCommandEvent &event) {
SetFocus(); SetFocus();
SetSelection(0,GetValue().Length()); SetSelection(0,GetValue().Length());
CopyTime(); CopyTime();
@ -325,18 +284,14 @@ void TimeEdit::OnCopy(wxCommandEvent &event) {
} }
/// @brief Menu Paste /// @brief Menu Paste
/// @param event void TimeEdit::OnPaste(wxCommandEvent &) {
///
void TimeEdit::OnPaste(wxCommandEvent &event) {
SetFocus(); SetFocus();
PasteTime(); PasteTime();
Refresh(); Refresh();
} }
/// @brief Copy to clipboard /// @brief Copy to clipboard
///
void TimeEdit::CopyTime() { void TimeEdit::CopyTime() {
// Frame
if (byFrame) { if (byFrame) {
Copy(); Copy();
return; return;
@ -350,9 +305,7 @@ void TimeEdit::CopyTime() {
} }
/// @brief Paste from clipboard /// @brief Paste from clipboard
///
void TimeEdit::PasteTime() { void TimeEdit::PasteTime() {
// Frame
if (byFrame) { if (byFrame) {
Paste(); Paste();
return; return;

View File

@ -52,17 +52,12 @@
/// ///
class TimeEdit : public wxTextCtrl { class TimeEdit : public wxTextCtrl {
private: private:
/// DOCME /// DOCME
bool byFrame; bool byFrame;
/// DOCME /// DOCME
bool ready; bool ready;
/// DOCME
bool modified;
void Modified(bool byUser=true);
void UpdateText(); void UpdateText();
void CopyTime(); void CopyTime();
void PasteTime(); void PasteTime();
@ -70,20 +65,14 @@ private:
/// DOCME /// DOCME
void UpdateTime(bool byUser=true); void UpdateTime(bool byUser=true);
/// DOCME
/// DOCME /// DOCME
void OnModified(wxCommandEvent &event); void OnModified(wxCommandEvent &event);
void OnMouseEvent(wxMouseEvent &event); void OnMouseEvent(wxMouseEvent &event);
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void OnCopy(wxCommandEvent &event); void OnCopy(wxCommandEvent &event);
void OnPaste(wxCommandEvent &event); void OnPaste(wxCommandEvent &event);
void OnKillFocus(wxFocusEvent &event);
/// @brief DOCME
///
void Modified();
public: public:
/// DOCME /// DOCME
@ -94,34 +83,16 @@ public:
/// DOCME /// DOCME
/// DOCME
bool showModified;
TimeEdit(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr); TimeEdit(wxWindow* parent, wxWindowID id, const wxString& value = _T(""), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);
void SetByFrame(bool enable); void SetByFrame(bool enable);
void SetTime(int ms,bool setModified=false); void SetTime(AssTime time);
void Update(); void Update();
/// @brief DOCME
/// @return
///
bool HasBeenModified() { return modified; }
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
///////
// IDs
enum { enum {
/// DOCME
Time_Edit_Copy = 1320, Time_Edit_Copy = 1320,
/// DOCME
Time_Edit_Paste Time_Edit_Paste
}; };

View File

@ -60,6 +60,7 @@
#include "ass_time.h" #include "ass_time.h"
#include "audio_display.h" #include "audio_display.h"
#include "compat.h" #include "compat.h"
#include "export_visible_lines.h"
#include "keyframe.h" #include "keyframe.h"
#include <libaegisub/access.h> #include <libaegisub/access.h>
#include "main.h" #include "main.h"
@ -98,6 +99,7 @@ VideoContext::VideoContext()
, arType(0) , arType(0)
, hasSubtitles(false) , hasSubtitles(false)
, playAudioOnStep(OPT_GET("Audio/Plays When Stepping Video")) , playAudioOnStep(OPT_GET("Audio/Plays When Stepping Video"))
, singleFrame(false)
, grid(NULL) , grid(NULL)
, audio(NULL) , audio(NULL)
, VFR_Input(videoFPS) , VFR_Input(videoFPS)
@ -245,8 +247,17 @@ void VideoContext::UpdateDisplays(bool full, bool seek) {
} }
} }
void VideoContext::Refresh () { void VideoContext::Refresh(bool full) {
if (subsProvider.get()) { if (subsProvider.get()) {
if (full) {
AssLimitToVisibleFilter::SetFrame(-1);
singleFrame = false;
}
else {
AssLimitToVisibleFilter::SetFrame(frame_n);
singleFrame = true;
}
AssExporter exporter(grid->ass); AssExporter exporter(grid->ass);
exporter.AddAutoFilters(); exporter.AddAutoFilters();
try { try {
@ -267,6 +278,10 @@ void VideoContext::JumpToFrame(int n) {
frame_n = n; frame_n = n;
if (singleFrame) {
Refresh(true);
}
UpdateDisplays(false, true); UpdateDisplays(false, true);
static agi::OptionValue* highlight = OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"); static agi::OptionValue* highlight = OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame");
@ -401,8 +416,8 @@ void VideoContext::PlayLine() {
// Set variables // Set variables
isPlaying = true; isPlaying = true;
startFrame = FrameAtTime(curline->Start.GetMS(),agi::vfr::START); startFrame = FrameAtTime(grid->GetActiveLine()->Start.GetMS(),agi::vfr::START);
endFrame = FrameAtTime(curline->End.GetMS(),agi::vfr::END); endFrame = FrameAtTime(grid->GetActiveLine()->End.GetMS(),agi::vfr::END);
// Jump to start // Jump to start
playNextFrame = startFrame; playNextFrame = startFrame;

View File

@ -151,6 +151,8 @@ private:
agi::vfr::Framerate videoFPS; agi::vfr::Framerate videoFPS;
agi::vfr::Framerate ovrFPS; agi::vfr::Framerate ovrFPS;
bool singleFrame;
public: public:
/// DOCME /// DOCME
SubtitlesGrid *grid; SubtitlesGrid *grid;
@ -231,7 +233,9 @@ public:
void JumpToTime(int ms, agi::vfr::Time end = agi::vfr::START); void JumpToTime(int ms, agi::vfr::Time end = agi::vfr::START);
/// @brief Refresh the subtitle provider /// @brief Refresh the subtitle provider
void Refresh(); /// @param full Send the entire subtitle file to the renderer rather than
/// just the lines visible on the current frame
void Refresh(bool full = false);
/// @brief Update the video display /// @brief Update the video display
/// @param full Recalculate size and slider lengths /// @param full Recalculate size and slider lengths

View File

@ -51,7 +51,6 @@
#include "ass_override.h" #include "ass_override.h"
#include "ass_style.h" #include "ass_style.h"
#include "ass_time.h" #include "ass_time.h"
#include "export_visible_lines.h"
#include "main.h" #include "main.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
@ -155,8 +154,6 @@ void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
} }
// end drag // end drag
else { else {
if (realTime) AssLimitToVisibleFilter::SetFrame(-1);
dragging = false; dragging = false;
// mouse didn't move, fiddle with selection // mouse didn't move, fiddle with selection
@ -197,8 +194,6 @@ void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
} }
// end hold // end hold
else { else {
if (realTime) AssLimitToVisibleFilter::SetFrame(-1);
holding = false; holding = false;
CommitHold(); CommitHold();
Commit(true); Commit(true);
@ -234,7 +229,6 @@ void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
dragging = true; dragging = true;
parent->CaptureMouse(); parent->CaptureMouse();
if (realTime) AssLimitToVisibleFilter::SetFrame(frameNumber);
} }
} }
// start hold // start hold
@ -249,7 +243,6 @@ void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
if (curDiag && InitializeHold()) { if (curDiag && InitializeHold()) {
holding = true; holding = true;
parent->CaptureMouse(); parent->CaptureMouse();
if (realTime) AssLimitToVisibleFilter::SetFrame(frameNumber);
} }
} }
} }
@ -267,9 +260,7 @@ void VisualTool<FeatureType>::Commit(bool full, wxString message) {
} }
grid->ass->Commit(message); grid->ass->Commit(message);
} }
grid->CommitChanges(false,!full); grid->CommitChanges(full);
if (full)
grid->editBox->Update(false, true);
externalChange = true; externalChange = true;
} }

View File

@ -47,6 +47,7 @@
#include "base_grid.h" #include "base_grid.h"
#include "gl_wrap.h" #include "gl_wrap.h"
#include "selection_controller.h"
class VideoDisplay; class VideoDisplay;
class AssDialogue; class AssDialogue;

View File

@ -41,7 +41,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_display.h" #include "video_display.h"

View File

@ -37,7 +37,6 @@
#include "ass_file.h" #include "ass_file.h"
#include "gl_text.h" #include "gl_text.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "video_context.h" #include "video_context.h"
#include "video_display.h" #include "video_display.h"

View File

@ -38,7 +38,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_context.h" #include "video_context.h"

View File

@ -41,7 +41,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_context.h" #include "video_context.h"

View File

@ -41,7 +41,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_context.h" #include "video_context.h"

View File

@ -41,7 +41,6 @@
#include "ass_dialogue.h" #include "ass_dialogue.h"
#include "ass_file.h" #include "ass_file.h"
#include "subs_edit_box.h"
#include "subs_grid.h" #include "subs_grid.h"
#include "utils.h" #include "utils.h"
#include "video_context.h" #include "video_context.h"