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.
This commit is contained in:
Thomas Goyne 2011-09-28 19:44:24 +00:00
parent c936306593
commit 67ab06e830
5 changed files with 21 additions and 9 deletions

View file

@ -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;
}

View file

@ -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

View file

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

View file

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

View file

@ -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) {