Refine the commit types

Switch to a bitmask with much more finely-grained information about what
changed in the commit, fixing a few potential correctness problems and
significantly improving the performance of several scenarios where commits
are spammed very frequently.

Originally committed to SVN as r5590.
This commit is contained in:
Thomas Goyne 2011-09-15 05:16:32 +00:00
parent 3f05fe6b3e
commit 934a5b24eb
26 changed files with 141 additions and 103 deletions

View file

@ -165,7 +165,7 @@ void AssFile::Load(const wxString &_filename,wxString charset,bool addToRecent)
undoDescription.clear();
commitId = -1;
savedCommitId = 0;
Commit("");
Commit("", COMMIT_NEW);
// Add to recent
if (addToRecent) AddToRecent(filename);
@ -468,7 +468,7 @@ void AssFile::LoadDefault(bool defline) {
AddLine(def.GetEntryData(),_T("[Events]"),version);
}
Commit("");
Commit("", COMMIT_NEW);
savedCommitId = commitId;
loaded = true;
StandardPaths::SetPathValue("?script", "");
@ -760,14 +760,12 @@ wxString AssFile::GetWildcardList(int mode) {
else return "";
}
int AssFile::Commit(wxString desc, CommitType type, int amendId) {
assert(type != COMMIT_UNDO);
int AssFile::Commit(wxString desc, int type, int amendId) {
++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) {
UndoStack.back() = *this;
UndoStack.back() = *this;
AnnounceCommit(type);
return commitId;
}
@ -801,7 +799,7 @@ void AssFile::Undo() {
UndoStack.pop_back();
*this = UndoStack.back();
AnnounceCommit(COMMIT_UNDO);
AnnounceCommit(COMMIT_NEW);
}
void AssFile::Redo() {
@ -811,7 +809,7 @@ void AssFile::Redo() {
UndoStack.push_back(*this);
RedoStack.pop_back();
AnnounceCommit(COMMIT_UNDO);
AnnounceCommit(COMMIT_NEW);
}
wxString AssFile::GetUndoDescription() const {

View file

@ -164,16 +164,32 @@ public:
/// Type of changes made in a commit
enum CommitType {
/// Entire file has been swapped for a different version of the same file
COMMIT_UNDO,
/// Potentially the entire file has been changed; any saved information
/// should be discarded
COMMIT_FULL,
/// The contents of lines have changed, but the number or order of lines
/// has not
COMMIT_TEXT,
/// Only the start and end times of lines has changed
COMMIT_TIMES
/// should be discarded. Note that the active line and selected set
/// should not be touched in handlers for this, as they may not have
/// been updated yet
/// Note that it is intentional that this cannot be combined with
/// other commit types
COMMIT_NEW = 0,
/// The order of lines in the file has changed
COMMIT_ORDER = 0x1,
/// The script info section has changed in some way
COMMIT_SCRIPTINFO = 0x2,
/// The styles have changed in some way
COMMIT_STYLES = 0x4,
/// The attachments have changed in some way
COMMIT_ATTACHMENT = 0x8,
/// Dialogue lines have been added or removed
/// Note that if the active dialogue line was removed, the active line
/// should be updated BEFORE committing
COMMIT_DIAG_ADDREM = 0x10,
/// The metadata fields of existing dialogue lines have changed
COMMIT_DIAG_META = 0x20,
/// The start and/or end times of existing dialogue lines have changed
COMMIT_DIAG_TIME = 0x40,
/// The text of existing dialogue lines have changed
COMMIT_DIAG_TEXT = 0x80,
COMMIT_DIAG_FULL = COMMIT_DIAG_META | COMMIT_DIAG_TIME | COMMIT_DIAG_TEXT,
};
DEFINE_SIGNAL_ADDERS(AnnounceCommit, AddCommitListener)
@ -185,7 +201,7 @@ public:
/// @param type Type of changes made to the file in this commit
/// @param commitId Commit to amend rather than pushing a new commit
/// @return Unique identifier for the new undo group
int Commit(wxString desc, CommitType type = COMMIT_FULL, int commitId = -1);
int Commit(wxString desc, int type, int commitId = -1);
/// @brief Undo the last set of changes to the file
void Undo();
/// @brief Redo the last undone changes

View file

@ -319,9 +319,10 @@ void AudioTimingControllerDialogue::OnSelectedSetChanged(const Selection &lines_
}
void AudioTimingControllerDialogue::OnFileChanged(int type) {
if (type == AssFile::COMMIT_UNDO || type == AssFile::COMMIT_FULL) return;
Revert();
if (type & AssFile::COMMIT_DIAG_TIME)
{
Revert();
}
}
@ -387,11 +388,11 @@ void AudioTimingControllerDialogue::Commit()
commit_slot.Block();
if (user_triggered)
{
ass->Commit(_("timing"), AssFile::COMMIT_TIMES);
ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME);
commit_id = -1; // never coalesce with a manually triggered commit
}
else
commit_id = ass->Commit(_("timing"), AssFile::COMMIT_TIMES, commit_id);
commit_id = ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME, commit_id);
commit_slot.Unblock();
timing_modified = false;

View file

@ -898,6 +898,11 @@ void BaseGrid::SetColumnWidths() {
int total = 0;
for (int i=0;i<10;i++) total += colWidth[i];
colWidth[10] = w-total;
time_cols_x = labelLen + layerLen;
time_cols_w = startLen + endLen;
text_col_x = total;
text_col_w = colWidth[10];
}
/// @brief Get dialogue by index

View file

@ -108,6 +108,11 @@ protected:
int colWidth[16]; ///< Width in pixels of each column
agi::Context *context; ///< Current project context
int time_cols_x; ///< Left edge of the times columns
int time_cols_w; ///< Width of the two times columns
int text_col_x; ///< Left edge of the text column
int text_col_w; ///< Width of the text column
static const int columns = 10; ///< Total number of columns
bool showCol[columns]; ///< Column visibility mask

View file

@ -181,7 +181,7 @@ static void combine_lines(agi::Context *c, void (*combiner)(AssDialogue *, AssDi
sel.insert(first);
c->selectionController->SetActiveLine(first);
c->selectionController->SetSelectedSet(sel);
c->ass->Commit(message);
c->ass->Commit(message, AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
}
static void combine_karaoke(AssDialogue *first, AssDialogue *second) {
@ -311,7 +311,7 @@ struct edit_line_split_by_karaoke : public validate_sel_nonempty {
didSplit |= c->subsGrid->SplitLineByKaraoke(sels[i]);
}
if (didSplit) {
c->ass->Commit(_("splitting"));
c->ass->Commit(_("splitting"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
}
c->subsGrid->EndBatch();
}
@ -338,7 +338,7 @@ struct edit_line_swap : public Command {
using std::swap;
swap(*a, *b);
c->ass->Commit(_("swap lines"));
c->ass->Commit(_("swap lines"), AssFile::COMMIT_ORDER);
}
}
};

View file

@ -190,10 +190,7 @@ struct grid_swap_up : public Command {
void operator()(agi::Context *c) {
if (AssDialogue *line = c->selectionController->GetActiveLine()) {
if (move_one(c->ass->Line.rbegin(), c->ass->Line.rend(), line))
/// @todo Maybe add COMMIT_ORDER, as the grid is the only thing
/// that needs to care about this
/// Probably not worth it
c->ass->Commit(_("swap lines"), AssFile::COMMIT_FULL);
c->ass->Commit(_("swap lines"), AssFile::COMMIT_ORDER);
}
}
};
@ -213,7 +210,7 @@ struct grid_swap_down : public Command {
void operator()(agi::Context *c) {
if (AssDialogue *line = c->selectionController->GetActiveLine()) {
if (move_one(c->ass->Line.begin(), c->ass->Line.end(), line))
c->ass->Commit(_("swap lines"), AssFile::COMMIT_FULL);
c->ass->Commit(_("swap lines"), AssFile::COMMIT_ORDER);
}
}
};

View file

@ -147,7 +147,7 @@ struct time_frame_current : public validate_video_loaded {
}
// Commit
c->ass->Commit(_("shift to frame"), AssFile::COMMIT_TIMES);
c->ass->Commit(_("shift to frame"), AssFile::COMMIT_DIAG_TIME);
}
};
@ -204,7 +204,7 @@ struct time_snap_frame : public validate_video_loaded {
}
}
c->ass->Commit(_("shift to frame"));
c->ass->Commit(_("shift to frame"), AssFile::COMMIT_DIAG_TIME);
}
};
@ -259,7 +259,7 @@ struct time_snap_scene : public validate_video_loaded {
}
// Commit
c->ass->Commit(_("snap to scene"), AssFile::COMMIT_TIMES);
c->ass->Commit(_("snap to scene"), AssFile::COMMIT_DIAG_TIME);
}
};
@ -271,7 +271,7 @@ struct time_add_lead_in : public Command {
void operator()(agi::Context *c) {
if (AssDialogue *line = c->selectionController->GetActiveLine()) {
line->Start.SetMS(line->Start.GetMS() - OPT_GET("Audio/Lead/IN")->GetInt());
c->ass->Commit(_("add lead in"), AssFile::COMMIT_TIMES);
c->ass->Commit(_("add lead in"), AssFile::COMMIT_DIAG_TIME);
}
}
};
@ -284,7 +284,7 @@ struct time_add_lead_out : public Command {
void operator()(agi::Context *c) {
if (AssDialogue *line = c->selectionController->GetActiveLine()) {
line->End.SetMS(line->End.GetMS() + OPT_GET("Audio/Lead/OUT")->GetInt());
c->ass->Commit(_("add lead out"), AssFile::COMMIT_TIMES);
c->ass->Commit(_("add lead out"), AssFile::COMMIT_DIAG_TIME);
}
}
};
@ -312,7 +312,7 @@ struct time_sort_end : public Command {
void operator()(agi::Context *c) {
c->ass->Sort(AssFile::CompEnd);
c->ass->Commit(_("sort"));
c->ass->Commit(_("sort"), AssFile::COMMIT_ORDER);
}
};
@ -326,7 +326,7 @@ struct time_sort_start : public Command {
void operator()(agi::Context *c) {
c->ass->Sort();
c->ass->Commit(_("sort"));
c->ass->Commit(_("sort"), AssFile::COMMIT_ORDER);
}
};
@ -340,7 +340,7 @@ struct time_sort_style : public Command {
void operator()(agi::Context *c) {
c->ass->Sort(AssFile::CompStyle);
c->ass->Commit(_("sort"));
c->ass->Commit(_("sort"), AssFile::COMMIT_ORDER);
}
};

View file

@ -174,7 +174,7 @@ DialogAttachments::~DialogAttachments() {
}
if (removed_any) {
ass->Commit(_("remove empty attachments sections"));
ass->Commit(_("remove empty attachments sections"), AssFile::COMMIT_ATTACHMENT);
}
}
@ -223,7 +223,7 @@ void DialogAttachments::OnAttachFont(wxCommandEvent &event) {
ass->InsertAttachment(newAttach);
}
ass->Commit(_("attach font file"));
ass->Commit(_("attach font file"), AssFile::COMMIT_ATTACHMENT);
// Update
UpdateList();
@ -261,7 +261,7 @@ void DialogAttachments::OnAttachGraphics(wxCommandEvent &event) {
ass->InsertAttachment(newAttach);
}
ass->Commit(_("attach graphics file"));
ass->Commit(_("attach graphics file"), AssFile::COMMIT_ATTACHMENT);
// Update
UpdateList();
@ -316,7 +316,7 @@ void DialogAttachments::OnDelete(wxCommandEvent &event) {
i = listView->GetNextSelected(i);
}
ass->Commit(_("remove attachment"));
ass->Commit(_("remove attachment"), AssFile::COMMIT_ATTACHMENT);
// Update list
UpdateList();

View file

@ -514,7 +514,7 @@ void FontsCollectorThread::Collect() {
// Modify file if it was attaching
if (oper == 3 && someOk) {
wxMutexGuiEnter();
subs->Commit(_("font attachment"));
subs->Commit(_("font attachment"), AssFile::COMMIT_ATTACHMENT);
wxMutexGuiLeave();
}
}

View file

@ -947,7 +947,7 @@ void DialogKanjiTimer::OnClose(wxCommandEvent &event) {
line->Text = p.second;
}
if (modified) {
subs->Commit(_("kanji timing"));
subs->Commit(_("kanji timing"), AssFile::COMMIT_DIAG_TEXT);
LinesToChange.clear();
}
Close();

View file

@ -185,7 +185,7 @@ void DialogProperties::OnOK(wxCommandEvent &event) {
count += SetInfoIfDifferent("Collisions",col[collision->GetSelection()]);
count += SetInfoIfDifferent("ScaledBorderAndShadow",ScaleBorder->GetValue()? "yes" : "no");
if (count) c->ass->Commit(_("property changes"));
if (count) c->ass->Commit(_("property changes"), AssFile::COMMIT_SCRIPTINFO);
EndModal(!!count);
}

View file

@ -322,7 +322,7 @@ void DialogResample::OnResample (wxCommandEvent &event) {
c->ass->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),y2));
// Flag as modified
c->ass->Commit(_("resolution resampling"), AssFile::COMMIT_TEXT);
c->ass->Commit(_("resolution resampling"), AssFile::COMMIT_SCRIPTINFO | AssFile::COMMIT_DIAG_FULL);
EndModal(0);
}

View file

@ -442,7 +442,7 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
}
// Commit
context->ass->Commit(_("replace"), AssFile::COMMIT_TEXT);
context->ass->Commit(_("replace"), AssFile::COMMIT_DIAG_TEXT);
}
else {
@ -546,7 +546,7 @@ void SearchReplaceEngine::ReplaceAll() {
// Commit
if (count > 0) {
context->ass->Commit(_("replace"), AssFile::COMMIT_TEXT);
context->ass->Commit(_("replace"), AssFile::COMMIT_DIAG_TEXT);
wxMessageBox(wxString::Format(_("%i matches were replaced."),count));
}

View file

@ -318,7 +318,7 @@ void DialogShiftTimes::OnOK(wxCommandEvent &event) {
OPT_SET("Tool/Shift Times/Direction")->SetBool(backward);
// End dialog
context->ass->Commit(_("shifting"), AssFile::COMMIT_TIMES);
context->ass->Commit(_("shifting"), AssFile::COMMIT_DIAG_TIME);
EndModal(0);
}

View file

@ -470,6 +470,7 @@ void DialogStyleEditor::Apply (bool apply,bool close) {
}
// Style name change
bool did_rename = false;
if (work->name != newStyleName) {
if (!isNew && isLocal) {
// See if user wants to update style name through script
@ -481,6 +482,7 @@ void DialogStyleEditor::Apply (bool apply,bool close) {
// Update
if (answer == wxYES) {
did_rename = true;
int n = c->subsGrid->GetRows();
wxArrayString strings;
strings.Add(work->name);
@ -507,7 +509,7 @@ void DialogStyleEditor::Apply (bool apply,bool close) {
*style = *work;
style->UpdateData();
if (isLocal) {
c->ass->Commit(_("style change"), AssFile::COMMIT_TEXT);
c->ass->Commit(_("style change"), AssFile::COMMIT_STYLES | (did_rename ? AssFile::COMMIT_DIAG_FULL : 0));
}
// Exit

View file

@ -595,7 +595,7 @@ void DialogStyleManager::OnCopyToCurrent (wxCommandEvent &) {
for (list<wxString>::iterator name = copied.begin(); name != copied.end(); ++name) {
CurrentList->SetStringSelection(*name, true);
}
c->ass->Commit(_("style copy"));
c->ass->Commit(_("style copy"), AssFile::COMMIT_STYLES);
wxCommandEvent dummy;
OnCurrentChange(dummy);
}
@ -643,7 +643,7 @@ void DialogStyleManager::OnCurrentCopy (wxCommandEvent &) {
}
else delete temp;
c->ass->Commit(_("style copy"));
c->ass->Commit(_("style copy"), AssFile::COMMIT_STYLES);
UpdateMoveButtons();
}
@ -695,7 +695,7 @@ void DialogStyleManager::PasteToCurrent() {
c->ass->InsertStyle(s);
LoadCurrentStyles(c->ass);
c->ass->Commit(_("style paste"));
c->ass->Commit(_("style paste"), AssFile::COMMIT_STYLES);
}
else
wxMessageBox(_("Could not parse style"), _("Could not parse style"), wxOK | wxICON_EXCLAMATION , this);
@ -840,7 +840,7 @@ void DialogStyleManager::OnCurrentDelete (wxCommandEvent &) {
CurrentCopy->Enable(false);
CurrentDelete->Enable(false);
c->ass->Commit(_("style delete"));
c->ass->Commit(_("style delete"), AssFile::COMMIT_STYLES);
}
UpdateMoveButtons();
}
@ -901,7 +901,7 @@ void DialogStyleManager::OnCurrentImport(wxCommandEvent &) {
// Update
if (modified) {
LoadCurrentStyles(c->ass);
c->ass->Commit(_("style import"));
c->ass->Commit(_("style import"), AssFile::COMMIT_STYLES);
}
}
catch (...) {
@ -1095,7 +1095,7 @@ void DialogStyleManager::MoveStyles(bool storage, int type) {
}
// Flag as modified
c->ass->Commit(_("style move"));
c->ass->Commit(_("style move"), AssFile::COMMIT_STYLES);
}
// Update

View file

@ -187,7 +187,7 @@ void DialogStyling::Commit(bool next) {
if (!c->ass->GetStyle(style_name->GetValue())) return;
active_line->Style = style_name->GetValue();
c->ass->Commit(_("styling assistant"), AssFile::COMMIT_TEXT);
c->ass->Commit(_("styling assistant"), AssFile::COMMIT_DIAG_META);
if (next) cmd::call("grid/line/next", c);
}

View file

@ -466,5 +466,5 @@ void DialogTimingProcessor::Process() {
}
// Update grid
c->ass->Commit(_("timing processor"), AssFile::COMMIT_TIMES);
c->ass->Commit(_("timing processor"), AssFile::COMMIT_DIAG_TIME);
}

View file

@ -235,7 +235,7 @@ void DialogTranslation::UpdateDisplay() {
void DialogTranslation::Commit(bool next) {
active_line->Blocks[cur_block]->text = translated_text->GetValue();
active_line->UpdateText();
c->ass->Commit(_("translation assistant"), AssFile::COMMIT_TEXT);
c->ass->Commit(_("translation assistant"), AssFile::COMMIT_DIAG_TEXT);
if (next) {
if (!NextBlock()) {

View file

@ -449,7 +449,7 @@ void FrameMain::OnVideoOpen() {
// Always change script res
context->ass->SetScriptInfo("PlayResX", wxString::Format("%d", vidx));
context->ass->SetScriptInfo("PlayResY", wxString::Format("%d", vidy));
context->ass->Commit(_("Change script resolution"));
context->ass->Commit(_("Change script resolution"), AssFile::COMMIT_SCRIPTINFO);
break;
case 0:
default:

View file

@ -338,11 +338,14 @@ SubsEditBox::~SubsEditBox() {
void SubsEditBox::Update(int type) {
SetEvtHandlerEnabled(false);
if (type == AssFile::COMMIT_FULL || type == AssFile::COMMIT_UNDO) {
/// @todo maybe preserve selection over undo?
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_STYLES) {
StyleBox->Clear();
StyleBox->Append(c->ass->GetStyles());
}
if (type == AssFile::COMMIT_NEW) {
/// @todo maybe preserve selection over undo?
ActorBox->Freeze();
ActorBox->Clear();
int nrows = c->subsGrid->GetRows();
@ -360,6 +363,7 @@ void SubsEditBox::Update(int type) {
SetEvtHandlerEnabled(true);
return;
}
if (!(type ^ AssFile::COMMIT_ORDER)) return;
SetControlsState(!!line);
if (!line) {
@ -367,11 +371,17 @@ void SubsEditBox::Update(int type) {
return;
}
StartTime->SetTime(line->Start);
EndTime->SetTime(line->End);
Duration->SetTime(line->End-line->Start);
if (type != AssFile::COMMIT_TIMES) {
if (type & AssFile::COMMIT_DIAG_TIME) {
StartTime->SetTime(line->Start);
EndTime->SetTime(line->End);
Duration->SetTime(line->End-line->Start);
}
if (type & AssFile::COMMIT_DIAG_TEXT) {
TextEdit->SetTextTo(line->Text);
}
if (type & AssFile::COMMIT_DIAG_META) {
Layer->SetValue(line->Layer);
MarginL->ChangeValue(line->GetMarginString(0,false));
MarginR->ChangeValue(line->GetMarginString(1,false));
@ -390,7 +400,7 @@ void SubsEditBox::OnActiveLineChanged(AssDialogue *new_line) {
SetEvtHandlerEnabled(false);
line = new_line;
Update(AssFile::COMMIT_TEXT);
Update(AssFile::COMMIT_DIAG_FULL);
/// @todo VideoContext should be doing this
if (c->videoController->IsLoaded()) {
@ -465,22 +475,22 @@ void SubsEditBox::OnChange(wxStyledTextEvent &event) {
}
template<class T, class setter>
void SubsEditBox::SetSelectedRows(setter set, T value, wxString desc, bool amend) {
void SubsEditBox::SetSelectedRows(setter set, T value, wxString desc, int type, bool amend) {
using namespace std::tr1::placeholders;
for_each(sel.begin(), sel.end(), std::tr1::bind(set, _1, value));
commitId = c->ass->Commit(desc, AssFile::COMMIT_TEXT, (amend && desc == lastCommitType) ? commitId : -1);
commitId = c->ass->Commit(desc, type, (amend && desc == lastCommitType) ? commitId : -1);
lastCommitType = desc;
}
template<class T>
void SubsEditBox::SetSelectedRows(T AssDialogue::*field, T value, wxString desc, bool amend) {
SetSelectedRows(field_setter<T>(field), value, desc, amend);
void SubsEditBox::SetSelectedRows(T AssDialogue::*field, T value, wxString desc, int type, bool amend) {
SetSelectedRows(field_setter<T>(field), value, desc, type, amend);
}
void SubsEditBox::CommitText(wxString desc) {
SetSelectedRows(&AssDialogue::Text, TextEdit->GetText(), desc, true);
SetSelectedRows(&AssDialogue::Text, TextEdit->GetText(), desc, AssFile::COMMIT_DIAG_TEXT, true);
}
void SubsEditBox::CommitTimes(TimeField field) {
@ -503,7 +513,7 @@ void SubsEditBox::CommitTimes(TimeField field) {
}
}
timeCommitId[field] = c->ass->Commit(_("modify times"), AssFile::COMMIT_TIMES, timeCommitId[field]);
timeCommitId[field] = c->ass->Commit(_("modify times"), AssFile::COMMIT_DIAG_TIME, timeCommitId[field]);
}
void SubsEditBox::OnSize(wxSizeEvent &evt) {
@ -591,12 +601,12 @@ void SubsEditBox::SetControlsState(bool state) {
void SubsEditBox::OnStyleChange(wxCommandEvent &) {
SetSelectedRows(&AssDialogue::Style, StyleBox->GetValue(), _("style change"));
SetSelectedRows(&AssDialogue::Style, StyleBox->GetValue(), _("style change"), AssFile::COMMIT_DIAG_META);
}
void SubsEditBox::OnActorChange(wxCommandEvent &) {
wxString actor = ActorBox->GetValue();
SetSelectedRows(&AssDialogue::Actor, actor, _("actor change"));
SetSelectedRows(&AssDialogue::Actor, actor, _("actor change"), AssFile::COMMIT_DIAG_META);
// Add actor to list
if (!actor.empty() && ActorBox->GetCount() && ActorBox->GetString(0).empty()) {
@ -612,7 +622,7 @@ void SubsEditBox::OnLayerChange(wxSpinEvent &event) {
}
void SubsEditBox::OnLayerEnter(wxCommandEvent &) {
SetSelectedRows(&AssDialogue::Layer, Layer->GetValue(), _("layer change"));
SetSelectedRows(&AssDialogue::Layer, Layer->GetValue(), _("layer change"), AssFile::COMMIT_DIAG_META);
}
void SubsEditBox::OnStartTimeChange(wxCommandEvent &) {
@ -630,12 +640,12 @@ void SubsEditBox::OnDurationChange(wxCommandEvent &) {
CommitTimes(TIME_DURATION);
}
void SubsEditBox::OnMarginLChange(wxCommandEvent &) {
SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<0>), MarginL->GetValue(), _("MarginL change"));
SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<0>), MarginL->GetValue(), _("MarginL change"), AssFile::COMMIT_DIAG_META);
if (line) MarginL->ChangeValue(line->GetMarginString(0, false));
}
void SubsEditBox::OnMarginRChange(wxCommandEvent &) {
SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<1>), MarginR->GetValue(), _("MarginR change"));
SetSelectedRows(std::mem_fun(&AssDialogue::SetMarginString<1>), MarginR->GetValue(), _("MarginR change"), AssFile::COMMIT_DIAG_META);
if (line) MarginR->ChangeValue(line->GetMarginString(1, false));
}
@ -645,16 +655,16 @@ static void set_margin_v(AssDialogue* diag, wxString value) {
}
void SubsEditBox::OnMarginVChange(wxCommandEvent &) {
SetSelectedRows(set_margin_v, MarginV->GetValue(), _("MarginV change"));
SetSelectedRows(set_margin_v, MarginV->GetValue(), _("MarginV change"), AssFile::COMMIT_DIAG_META);
if (line) MarginV->ChangeValue(line->GetMarginString(2, false));
}
void SubsEditBox::OnEffectChange(wxCommandEvent &) {
SetSelectedRows(&AssDialogue::Effect, Effect->GetValue(), _("effect change"));
SetSelectedRows(&AssDialogue::Effect, Effect->GetValue(), _("effect change"), AssFile::COMMIT_DIAG_META);
}
void SubsEditBox::OnCommentChange(wxCommandEvent &event) {
SetSelectedRows(&AssDialogue::Comment, CommentBox->GetValue(), _("comment change"));
SetSelectedRows(&AssDialogue::Comment, CommentBox->GetValue(), _("comment change"), AssFile::COMMIT_DIAG_META);
}
int SubsEditBox::BlockAtPos(int pos) const {

View file

@ -171,17 +171,19 @@ class SubsEditBox : public wxPanel, protected SelectionListener<AssDialogue> {
/// @param set Callable which does the setting
/// @param value Value to pass to set
/// @param desc Undo description to use
/// @param type Commit type 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);
void SetSelectedRows(setter set, T value, wxString desc, int type, 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 type Commit type 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);
void SetSelectedRows(T AssDialogue::*field, T value, wxString desc, int type, bool amend = false);
/// @brief Reload the current line from the file
/// @param type AssFile::CommitType

View file

@ -87,19 +87,20 @@ SubtitlesGrid::~SubtitlesGrid() {
}
void SubtitlesGrid::OnSubtitlesCommit(int type) {
if (type == AssFile::COMMIT_FULL)
UpdateMaps();
else if (type == AssFile::COMMIT_UNDO)
if (type == AssFile::COMMIT_NEW)
UpdateMaps(true);
else if (type & AssFile::COMMIT_ORDER || type & AssFile::COMMIT_DIAG_ADDREM)
UpdateMaps(false);
if (type == AssFile::COMMIT_TIMES) {
// Refresh just the audio times columns
RefreshRect(wxRect(colWidth[0] + colWidth[1], 0, colWidth[2] + colWidth[3], GetClientSize().GetHeight()), false);
}
else {
if (type & AssFile::COMMIT_DIAG_META) {
SetColumnWidths();
Refresh(false);
return;
}
if (type & AssFile::COMMIT_DIAG_TIME)
RefreshRect(wxRect(time_cols_x, 0, time_cols_w, GetClientSize().GetHeight()), false);
if (type & AssFile::COMMIT_DIAG_TEXT)
RefreshRect(wxRect(text_col_x, 0, text_col_w, GetClientSize().GetHeight()), false);
}
void SubtitlesGrid::OnSubtitlesOpen() {
@ -232,15 +233,14 @@ void SubtitlesGrid::RecombineLines() {
}
}
context->ass->Commit(_("combining"));
// Remove now non-existent lines from the selection
Selection lines;
transform(context->ass->Line.begin(), context->ass->Line.end(), inserter(lines, lines.begin()), cast<AssDialogue*>());
Selection newSel;
set_intersection(lines.begin(), lines.end(), selectedSet.begin(), selectedSet.end(), inserter(newSel, newSel.begin()));
if (newSel.empty()) return;
if (newSel.empty())
newSel.insert(*lines.begin());
// Restore selection
SetSelectedSet(newSel);
@ -248,6 +248,8 @@ void SubtitlesGrid::RecombineLines() {
activeLine = *newSel.begin();
}
SetActiveLine(activeLine);
context->ass->Commit(_("combining"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
}
/// @brief Insert a line
@ -264,7 +266,7 @@ void SubtitlesGrid::InsertLine(AssDialogue *line,int n,bool after,bool update) {
// Update
if (update) {
context->ass->Commit(_("line insertion"));
context->ass->Commit(_("line insertion"), AssFile::COMMIT_DIAG_ADDREM);
}
else {
UpdateMaps();
@ -380,7 +382,7 @@ void SubtitlesGrid::PasteLines(int n,bool pasteOver) {
// Update data post-insertion
if (inserted > 0) {
context->ass->Commit(_("paste"), pasteOver ? AssFile::COMMIT_TEXT : AssFile::COMMIT_FULL);
context->ass->Commit(_("paste"), pasteOver ? AssFile::COMMIT_DIAG_FULL : AssFile::COMMIT_DIAG_ADDREM);
// Set selection
if (!pasteOver) {
@ -422,7 +424,7 @@ void SubtitlesGrid::DeleteLines(wxArrayInt target, bool flagModified) {
}
if (flagModified) {
context->ass->Commit(_("delete"));
context->ass->Commit(_("delete"), AssFile::COMMIT_DIAG_ADDREM);
}
else {
UpdateMaps();
@ -462,7 +464,7 @@ void SubtitlesGrid::AdjoinLines(int n1,int n2,bool setStart) {
}
}
context->ass->Commit(_("adjoin"));
context->ass->Commit(_("adjoin"), AssFile::COMMIT_DIAG_TIME);
}
void SubtitlesGrid::DuplicateLines(int n1,int n2,bool nextFrame) {
@ -526,7 +528,7 @@ void SubtitlesGrid::SplitLine(AssDialogue *n1,int pos,bool estimateTimes) {
n2->Start.SetMS(splitTime);
}
context->ass->Commit(_("split"));
context->ass->Commit(_("split"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
}
bool SubtitlesGrid::SplitLineByKaraoke(int lineNumber) {
@ -587,7 +589,7 @@ void SubtitlesGrid::SetSubsToVideo(bool start) {
}
if (modified) {
context->ass->Commit(_("timing"), AssFile::COMMIT_TIMES);
context->ass->Commit(_("timing"), AssFile::COMMIT_DIAG_TIME);
}
}

View file

@ -212,7 +212,7 @@ void VideoDisplay::OnVideoOpen() {
}
void VideoDisplay::OnCommit(int type) {
if (type == AssFile::COMMIT_FULL || type == AssFile::COMMIT_UNDO)
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_SCRIPTINFO)
con->videoController->GetScriptSize(scriptW, scriptH);
if (tool.get()) tool->Refresh();
}

View file

@ -247,7 +247,7 @@ void VisualTool<FeatureType>::Commit(wxString message) {
if (message.empty()) {
message = _("visual typesetting");
}
commitId = c->ass->Commit(message, AssFile::COMMIT_TEXT, commitId);
commitId = c->ass->Commit(message, AssFile::COMMIT_DIAG_TEXT, commitId);
externalChange = true;
}