Originally committed to SVN as r893.

This commit is contained in:
Dan Donovan 2007-01-26 00:47:42 +00:00
parent a29fcb2d47
commit 4565a18369
21 changed files with 93 additions and 61 deletions

View File

@ -809,7 +809,7 @@ bool AssFile::IsModified() {
/////////////////////////
// Flag file as modified
void AssFile::FlagAsModified() {
void AssFile::FlagAsModified(wxString desc) {
// Clear redo
if (!RedoStack.empty()) {
//StackPush();
@ -821,16 +821,17 @@ void AssFile::FlagAsModified() {
}
Modified = true;
StackPush();
StackPush(desc);
}
//////////////
// Stack push
void AssFile::StackPush() {
void AssFile::StackPush(wxString desc) {
// Places copy on stack
AssFile *curcopy = new AssFile(*top);
curcopy->CompressForStack(true);
curcopy->undodescription = desc;
UndoStack.push_back(curcopy);
StackModified = true;
@ -852,7 +853,11 @@ void AssFile::StackPush() {
// Stack pop
void AssFile::StackPop() {
bool addcopy = false;
wxString undodesc=_T("");
if (StackModified) {
undodesc=UndoStack.back()->undodescription;
UndoStack.pop_back();
StackModified = false;
addcopy = true;
@ -860,16 +865,18 @@ void AssFile::StackPop() {
if (!UndoStack.empty()) {
//delete top;
AssFile *undo = UndoStack.back();
top->CompressForStack(true);
top->undodescription = undodesc;
RedoStack.push_back(top);
top = UndoStack.back();
top = undo;
top->CompressForStack(false);
UndoStack.pop_back();
Popping = true;
}
if (addcopy) {
StackPush();
StackPush(top->undodescription);
}
}
@ -896,7 +903,7 @@ void AssFile::StackRedo() {
}
if (addcopy) {
StackPush();
StackPush(top->undodescription);
}
}
@ -944,6 +951,14 @@ bool AssFile::IsRedoStackEmpty() {
return RedoStack.empty();
}
wxString AssFile::GetUndoDescription() {
return (IsUndoStackEmpty())?_T(""):(UndoStack.back())->undodescription;
}
wxString AssFile::GetRedoDescription() {
return (IsRedoStackEmpty())?_T(""):(RedoStack.back())->undodescription;
}
//////////
// Global

View File

@ -72,6 +72,7 @@ public:
std::list<AssEntry*> Line;
wxString filename;
wxString undodescription;
bool loaded;
AssFile();
@ -79,7 +80,7 @@ public:
~AssFile();
bool IsModified(); // Returns if file has unmodified changes
void FlagAsModified(); // Flag file as being modified, will automatically put a copy on stack
void FlagAsModified(wxString desc); // Flag file as being modified, will automatically put a copy on stack
void Clear(); // Wipes file
void CompressForStack(bool compress); // Compress/decompress for storage on stack
void LoadDefault(bool defline=true); // Loads default file. Pass false to prevent it from adding a default line too
@ -104,14 +105,16 @@ public:
void AddComment(const wxString comment); // Adds a ";" comment under [Script Info].
int AddLine(wxString data,wxString group,int lasttime,int &version,wxString *outGroup=NULL);
static void StackPop(); // Pop subs from stack and sets 'top' to it
static void StackRedo(); // Redoes action on stack
static void StackPush(); // Puts a copy of 'top' on the stack
static void StackReset(); // Resets stack. Do this before loading new subtitles.
static bool IsUndoStackEmpty(); // Checks if undo stack is empty
static bool IsRedoStackEmpty(); // Checks if undo stack is empty
static bool Popping; // Flags the stack as popping. You must unset this after popping
static AssFile *top; // Current script file. It is "above" the stack.
static void StackPop(); // Pop subs from stack and sets 'top' to it
static void StackRedo(); // Redoes action on stack
static void StackPush(wxString desc); // Puts a copy of 'top' on the stack
static void StackReset(); // Resets stack. Do this before loading new subtitles.
static bool IsUndoStackEmpty(); // Checks if undo stack is empty
static bool IsRedoStackEmpty(); // Checks if undo stack is empty
static wxString GetUndoDescription(); // Gets field undodescription from back of UndoStack
static wxString GetRedoDescription(); // Gets field undodescription from back of RedoStack
static bool Popping; // Flags the stack as popping. You must unset this after popping
static AssFile *top; // Current script file. It is "above" the stack.
};

View File

@ -1041,7 +1041,7 @@ void AudioDisplay::CommitChanges (bool nextLine) {
// Update grid
grid->editBox->Update(!karaoke->enabled);
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_T(""));
grid->CommitChanges();
karaoke->curSyllable = karSyl;
blockUpdate = false;

View File

@ -888,7 +888,7 @@ namespace Automation4 {
description = wxString(lua_tostring(L, 1), wxConvUTF8);
lua_pop(L, 1);
}
AssFile::top->FlagAsModified(); // TODO: make undo system support description of action undone
AssFile::top->FlagAsModified(_T(""));
laf->ass = AssFile::top; // make sure we're still working on the most recent undo point
return 0;

View File

@ -578,7 +578,7 @@ void FontsCollectorThread::Collect() {
// Flag file as modified
if (fileModified) {
subs->FlagAsModified();
subs->FlagAsModified(_("font attachment"));
collector->main->SubsBox->CommitChanges();
}
}

View File

@ -178,7 +178,7 @@ void DialogKanjiTimer::OnClose(wxCommandEvent &event) {
line->Text = p.second;
}
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("kanji timing"));
grid->CommitChanges();
LinesToChange.clear();
Close();

View File

@ -184,7 +184,7 @@ void DialogProperties::OnOK(wxCommandEvent &event) {
wxString col[2] = { _T("Normal"), _T("Reverse")};
count += SetInfoIfDifferent(_T("Collisions"),col[collision->GetSelection()]);
if (count) AssFile::top->FlagAsModified();
if (count) AssFile::top->FlagAsModified(_("property changes"));
EndModal(count?1:0);
}

View File

@ -233,7 +233,7 @@ void DialogResample::OnResample (wxCommandEvent &event) {
subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),y2));
// Flag as modified
subs->FlagAsModified();
subs->FlagAsModified(_("resolution resampling"));
grid->CommitChanges();;
EndModal(0);
}

View File

@ -416,7 +416,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
cur->UpdateData();
// Commit
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("replace"));
}
else {
@ -507,7 +507,7 @@ void SearchReplaceEngine::ReplaceAll() {
// Commit
if (count > 0) {
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("replace"));
grid->CommitChanges();
wxMessageBox(wxString::Format(_("%i matches were replaced."),count));
}

View File

@ -292,7 +292,7 @@ void DialogShiftTimes::OnOK(wxCommandEvent &event) {
Options.Save();
// End dialog
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("shifting"));
grid->CommitChanges();
grid->UpdateMaps();
grid->editBox->Update();

View File

@ -449,7 +449,7 @@ void DialogStyleEditor::Apply (bool apply,bool close) {
// Copy
*style = *work;
style->UpdateData();
AssFile::top->FlagAsModified();
AssFile::top->FlagAsModified(_("style change"));
grid->CommitChanges();
// Exit

View File

@ -558,7 +558,7 @@ void DialogStyleManager::OnCopyToCurrent (wxCommandEvent &event) {
else return;
}
LoadCurrentStyles(AssFile::top);
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("style copy"));
grid->CommitChanges();
UpdateMoveButtons();
}
@ -607,7 +607,7 @@ void DialogStyleManager::OnCurrentCopy (wxCommandEvent &event) {
}
else delete temp;
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("style copy"));
grid->CommitChanges();
UpdateMoveButtons();
}
@ -711,7 +711,7 @@ void DialogStyleManager::OnCurrentDelete (wxCommandEvent &event) {
CurrentCopy->Enable(false);
CurrentDelete->Enable(false);
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("style delete"));
grid->CommitChanges();
}
UpdateMoveButtons();
@ -768,7 +768,7 @@ void DialogStyleManager::OnCurrentImport(wxCommandEvent &event) {
// Update
if (modified) {
LoadCurrentStyles(grid->ass);
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("style import"));
grid->CommitChanges();
}
}
@ -978,7 +978,7 @@ void DialogStyleManager::MoveStyles(bool storage, int type) {
}
// Flag as modified
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("style move"));
grid->CommitChanges();
}

View File

@ -147,7 +147,7 @@ wxDialog (parent, -1, _("Styling assistant"), wxDefaultPosition, wxDefaultSize,
DialogStyling::~DialogStyling () {
GetPosition(&lastx, &lasty);
if (needCommit) {
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("style changes"));
grid->CommitChanges();
}
}
@ -198,7 +198,7 @@ void DialogStyling::SetStyle (wxString curName, bool jump) {
// Update grid/subs
grid->Refresh(false);
if (PreviewCheck->IsChecked()) {
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("styling assistant"));
grid->CommitChanges();
}
else needCommit = true;

View File

@ -564,6 +564,6 @@ void DialogTimingProcessor::Process() {
}
// Update grid
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("timing processor"));
grid->CommitChanges();
}

View File

@ -314,7 +314,7 @@ void DialogTranslation::OnTransBoxKey(wxKeyEvent &event) {
cur->UpdateText();
cur->UpdateData();
cur->ClearBlocks();
subs->FlagAsModified();
subs->FlagAsModified(_("translation assistant"));
grid->CommitChanges();
((FrameMain*)main)->UpdateTitle();
UpdatePreview();

View File

@ -1348,3 +1348,12 @@ bool FrameMain::LoadList(wxArrayString list) {
// Result
return ((subs != _T("")) || (audio != _T("")) || (video != _T("")));
}
//////////////////////
// Sets the descriptions for undo/redo
void FrameMain::SetUndoRedoDesc() {
editMenu->SetHelpString(0,_T("Undo ")+AssFile::GetUndoDescription());
editMenu->SetHelpString(1,_T("Redo ")+AssFile::GetRedoDescription());
}

View File

@ -263,6 +263,8 @@ public:
void InitMenu();
void UpdateToolbar();
void SetDisplayMode(int showVid,int showAudio);
void SetUndoRedoDesc();
DECLARE_EVENT_TABLE()
};

View File

@ -453,9 +453,12 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
// Edit menu
else if (curMenu == editMenu) {
// Undo state
curMenu->FindItemByPosition(0)->SetText(_("Undo ")+AssFile::GetUndoDescription()+_T("\t")+Hotkeys.GetText(_T("Undo")));
curMenu->FindItemByPosition(1)->SetText(_("Redo ")+AssFile::GetRedoDescription()+_T("\t")+Hotkeys.GetText(_T("Redo")));
RebuildMenuItem(editMenu,Menu_Edit_Undo,wxBITMAP(undo_button),wxBITMAP(undo_disable_button),!AssFile::IsUndoStackEmpty());
RebuildMenuItem(editMenu,Menu_Edit_Redo,wxBITMAP(redo_button),wxBITMAP(redo_disable_button),!AssFile::IsRedoStackEmpty());
// Copy/cut/paste
wxArrayInt sels = SubsBox->GetSelection();
bool state = (sels.Count() > 0);
@ -1103,7 +1106,7 @@ void FrameMain::OnSnapToScene (wxCommandEvent &event) {
}
// Commit
SubsBox->ass->FlagAsModified();
SubsBox->ass->FlagAsModified(_("snap to scene"));
SubsBox->CommitChanges();
}
}
@ -1134,7 +1137,7 @@ void FrameMain::OnShiftToFrame (wxCommandEvent &event) {
}
// Commit
SubsBox->ass->FlagAsModified();
SubsBox->ass->FlagAsModified(_("shift to frame"));
SubsBox->CommitChanges();
}
}
@ -1366,7 +1369,7 @@ void FrameMain::OnSort (wxCommandEvent &event) {
// Sort
AssFile::top->Line.sort(LessByPointedToValue<AssEntry>());
AssFile::top->FlagAsModified();
AssFile::top->FlagAsModified(_("sort"));
SubsBox->UpdateMaps();
SubsBox->CommitChanges();
}
@ -1521,7 +1524,7 @@ void FrameMain::OnEditBoxCommit(wxCommandEvent &event) {
// Is the text edit
if (focus == EditBox->TextEdit) {
EditBox->CommitText();
SubsBox->ass->FlagAsModified();
SubsBox->ass->FlagAsModified(_("editing"));
SubsBox->CommitChanges();
}

View File

@ -551,7 +551,7 @@ void SubsEditBox::OnStyleChange(wxCommandEvent &event) {
cur->UpdateData();
}
}
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("style change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -582,7 +582,7 @@ void SubsEditBox::OnActorChange(wxCommandEvent &event) {
}
// Update grid
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("actor change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -615,7 +615,7 @@ void SubsEditBox::OnLayerChange(wxCommandEvent &event) {
// Done
Layer->SetValue(wxString::Format(_("%i"),temp));
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("layer change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -684,7 +684,7 @@ void SubsEditBox::CommitTimes(bool start,bool end,bool fromStart) {
}
// Commit
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("commit times"));
grid->CommitChanges();
grid->EndBatch();
audio->SetDialogue(grid,grid->GetDialogue(sel[0]),sel[0]);
@ -708,7 +708,7 @@ void SubsEditBox::OnMarginLChange(wxCommandEvent &event) {
}
}
MarginL->SetValue(cur->GetMarginString(0,false));
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("MarginL change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -730,7 +730,7 @@ void SubsEditBox::OnMarginRChange(wxCommandEvent &event) {
}
}
MarginR->SetValue(cur->GetMarginString(1,false));
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("MarginR change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -752,7 +752,7 @@ void SubsEditBox::OnMarginVChange(wxCommandEvent &event) {
}
}
MarginV->SetValue(cur->GetMarginString(2,false));
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("MarginV change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -773,7 +773,7 @@ void SubsEditBox::OnEffectChange(wxCommandEvent &event) {
cur->UpdateData();
}
}
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("effect change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -793,7 +793,7 @@ void SubsEditBox::OnCommentChange(wxCommandEvent &event) {
cur->UpdateData();
}
}
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("comment change"));
grid->CommitChanges();
grid->EndBatch();
}
@ -847,7 +847,7 @@ void SubsEditBox::DoKeyPress(wxKeyEvent &event) {
// Update file
if (!updated) {
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("editing"));
grid->CommitChanges();
}
return;

View File

@ -393,7 +393,7 @@ void SubtitlesGrid::OnSplitByKaraoke (wxCommandEvent &event) {
for (int i = sels.size()-1; i >= 0; i--) {
SplitLineByKaraoke(sels[i]);
}
ass->FlagAsModified();
ass->FlagAsModified(_("splitting"));
CommitChanges();
EndBatch();
}
@ -627,7 +627,7 @@ void SubtitlesGrid::OnRecombine(wxCommandEvent &event) {
// Commit
n1->UpdateData();
n2->UpdateData();
ass->FlagAsModified();
ass->FlagAsModified(_("combining"));
CommitChanges();
}
@ -761,8 +761,8 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif
// Commit
if (!AssFile::Popping) {
if (dontModify) AssFile::StackPush();
else ass->FlagAsModified();
if (dontModify) AssFile::StackPush(_("load"));
else ass->FlagAsModified(_("load"));
}
CommitChanges();
@ -803,7 +803,7 @@ void SubtitlesGrid::SwapLines(int n1,int n2) {
diagPtrMap[n1] = (AssDialogue*) *src1;
diagMap[n2] = src2;
diagPtrMap[n2] = (AssDialogue*) *src2;
ass->FlagAsModified();
ass->FlagAsModified(_("swap lines"));
CommitChanges();
}
@ -829,7 +829,7 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
// Update
if (update) {
ass->FlagAsModified();
ass->FlagAsModified(_("line insertion"));
CommitChanges();
}
}
@ -950,7 +950,7 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
// Commit
UpdateMaps();
AdjustScrollbar();
ass->FlagAsModified();
ass->FlagAsModified(_("paste"));
CommitChanges();
// Set selection
@ -992,7 +992,7 @@ void SubtitlesGrid::DeleteLines(wxArrayInt target) {
// Update
UpdateMaps();
AdjustScrollbar();
ass->FlagAsModified();
ass->FlagAsModified(_("delete"));
CommitChanges();
// Update editbox
@ -1071,7 +1071,7 @@ void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) {
}
// Commit
AssFile::top->FlagAsModified();
AssFile::top->FlagAsModified(_("adjoin"));
CommitChanges();
}
@ -1232,7 +1232,7 @@ void SubtitlesGrid::SplitLine(int n,int pos,int mode) {
editBox->SetToLine(n);
// Commit
ass->FlagAsModified();
ass->FlagAsModified(_("split"));
CommitChanges();
}
@ -1393,7 +1393,7 @@ void SubtitlesGrid::SetSubsToVideo(bool start) {
// Commit
if (modified) {
ass->FlagAsModified();
ass->FlagAsModified(_("timing"));
CommitChanges();
editBox->Update();
}

View File

@ -1057,7 +1057,7 @@ void VideoDisplayVisual::OnMouseEvent (wxMouseEvent &event) {
// Commit
grid->editBox->CommitText();
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("visual typesetting"));
grid->CommitChanges(false,true);
// Set flags
@ -1075,7 +1075,7 @@ void VideoDisplayVisual::OnMouseEvent (wxMouseEvent &event) {
if (mode == 0 && event.LeftDClick()) {
grid->editBox->SetOverride(_T("\\pos"),wxString::Format(_T("(%i,%i)"),vx,vy),0,false);
grid->editBox->CommitText();
grid->ass->FlagAsModified();
grid->ass->FlagAsModified(_("positioning"));
grid->CommitChanges(false,true);
parent->SetFocus();
}