From 67ab06e830cb11f794221551598fe9362ff1ce3d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 28 Sep 2011 19:44:24 +0000 Subject: [PATCH] Add an optional argument to AssFile::Commit which indicates that only a single line was changed. Currently used only to cut down on file copies when coalescing. Originally committed to SVN as r5614. --- aegisub/src/ass_file.cpp | 13 ++++++++++++- aegisub/src/ass_file.h | 9 +++++---- aegisub/src/audio_timing_dialogue.cpp | 2 +- aegisub/src/audio_timing_karaoke.cpp | 2 +- aegisub/src/subs_edit_box.cpp | 4 ++-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/aegisub/src/ass_file.cpp b/aegisub/src/ass_file.cpp index cf904c8e3..26e1c5a05 100644 --- a/aegisub/src/ass_file.cpp +++ b/aegisub/src/ass_file.cpp @@ -760,12 +760,23 @@ wxString AssFile::GetWildcardList(int mode) { else return ""; } -int AssFile::Commit(wxString desc, int type, int amendId) { +int AssFile::Commit(wxString desc, int type, int amendId, AssEntry *single_line) { ++commitId; // Allow coalescing only if it's the last change and the file has not been // saved since the last change if (commitId == amendId+1 && RedoStack.empty() && savedCommitId != commitId) { + // If only one line changed just modify it instead of copying the file + if (single_line) { + entryIter this_it = Line.begin(), undo_it = UndoStack.back().Line.begin(); + while (*this_it != single_line) { + ++this_it; + ++undo_it; + } + **undo_it = *single_line; + } + else { UndoStack.back() = *this; + } AnnounceCommit(type); return commitId; } diff --git a/aegisub/src/ass_file.h b/aegisub/src/ass_file.h index 844809c67..9c50bd289 100644 --- a/aegisub/src/ass_file.h +++ b/aegisub/src/ass_file.h @@ -197,11 +197,12 @@ public: DEFINE_SIGNAL_ADDERS(FileSave, AddFileSaveListener) /// @brief Flag the file as modified and push a copy onto the undo stack - /// @param desc Undo description - /// @param type Type of changes made to the file in this commit - /// @param commitId Commit to amend rather than pushing a new commit + /// @param desc Undo description + /// @param type Type of changes made to the file in this commit + /// @param commitId Commit to amend rather than pushing a new commit + /// @param single_line Line which was changed, if only one line was /// @return Unique identifier for the new undo group - int Commit(wxString desc, int type, int commitId = -1); + int Commit(wxString desc, int type, int commitId = -1, AssEntry *single_line = 0); /// @brief Undo the last set of changes to the file void Undo(); /// @brief Redo the last undone changes diff --git a/aegisub/src/audio_timing_dialogue.cpp b/aegisub/src/audio_timing_dialogue.cpp index f8515fc73..5700aecb4 100644 --- a/aegisub/src/audio_timing_dialogue.cpp +++ b/aegisub/src/audio_timing_dialogue.cpp @@ -392,7 +392,7 @@ void AudioTimingControllerDialogue::Commit() commit_id = -1; // never coalesce with a manually triggered commit } else - commit_id = ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME, commit_id); + commit_id = context->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME, commit_id, selection_controller->GetActiveLine()); commit_slot.Unblock(); timing_modified = false; diff --git a/aegisub/src/audio_timing_karaoke.cpp b/aegisub/src/audio_timing_karaoke.cpp index 389b41de9..3c79bbfdd 100644 --- a/aegisub/src/audio_timing_karaoke.cpp +++ b/aegisub/src/audio_timing_karaoke.cpp @@ -226,7 +226,7 @@ void AudioTimingControllerKaraoke::GetMarkers(SampleRange const& range, AudioMar void AudioTimingControllerKaraoke::DoCommit() { active_line->Text = kara->GetText(); file_changed_slot.Block(); - commit_id = c->ass->Commit(_("karaoke timing"), AssFile::COMMIT_TEXT, commit_id); + commit_id = c->ass->Commit(_("karaoke timing"), AssFile::COMMIT_DIAG_TEXT, commit_id, active_line); file_changed_slot.Unblock(); } diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index 8a3fb41a0..971307466 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -485,7 +485,7 @@ void SubsEditBox::SetSelectedRows(setter set, T value, wxString desc, int type, for_each(sel.begin(), sel.end(), std::tr1::bind(set, _1, value)); - commitId = c->ass->Commit(desc, type, (amend && desc == lastCommitType) ? commitId : -1); + commitId = c->ass->Commit(desc, type, (amend && desc == lastCommitType) ? commitId : -1, sel.size() == 1 ? *sel.begin() : 0); lastCommitType = desc; } @@ -518,7 +518,7 @@ void SubsEditBox::CommitTimes(TimeField field) { } } - timeCommitId[field] = c->ass->Commit(_("modify times"), AssFile::COMMIT_DIAG_TIME, timeCommitId[field]); + timeCommitId[field] = c->ass->Commit(_("modify times"), AssFile::COMMIT_DIAG_TIME, timeCommitId[field], sel.size() == 1 ? *sel.begin() : 0); } void SubsEditBox::OnSize(wxSizeEvent &evt) {