コード例 #1
0
ファイル: action.cpp プロジェクト: Aegisub/Athenasub
void ActionModifyBatch::Execute()
{
	// Find the section to modify
	size_t len = selection->GetCount();
	String sectionName = section;
	if (sectionName.IsEmpty()) sectionName = entries[0]->GetDefaultGroup();
	Section sect = GetSection(sectionName);

	// For each line...
	for (size_t i=0;i<len;i++) {
		if (i < deltas.size() && deltas[i]) {
			Entry &ref = sect->GetEntryRef(selection->GetLine(i));
			ref->GetDeltaCoder()->ApplyDelta(deltas[i],ref);
		}
		else sect->GetEntryRef(selection->GetLine(i)) = entries[i];
	}
}
コード例 #2
0
ファイル: action.cpp プロジェクト: Aegisub/Athenasub
/////////////////////
// Execute insertion
void ActionModify::Execute()
{
	// Find the section to modify
	String sectionName = section;
	if (sectionName.IsEmpty()) sectionName = entry->GetDefaultGroup();
	Section sect = GetSection(sectionName);

	// Modify the line
	if (delta) {
		Entry ref = sect->GetEntry(lineNumber);
		ref->GetDeltaCoder()->ApplyDelta(delta,ref);
	}
	else sect->GetEntryRef(lineNumber) = entry;
}
コード例 #3
0
ファイル: action.cpp プロジェクト: Aegisub/Athenasub
Action ActionModifyBatch::GetAntiAction() const
{
	// Old, slow method
	if (false) {
		// Get section
		Section sect = GetSection(section);
		size_t len = selection->GetCount();
		std::vector<VoidPtr> _deltas(len);
		std::vector<Entry> oldEntries(len);

		// For each line...
		for (size_t i=0;i<len;i++) {
			// Get old entry
			Entry& oldEntry = sect->GetEntryRef(selection->GetLine(i));

			// Try to get a delta
			DeltaCoder deltaCoder = oldEntry->GetDeltaCoder();
			if (deltaCoder) {
				if (i < deltas.size() && deltas[i]) _deltas[i] = deltaCoder->EncodeReverseDelta(deltas[i],oldEntry);
				_deltas[i] = deltaCoder->EncodeDelta(entries[i],oldEntry,!noTextFields);
			}

			// Store the whole original line
			else oldEntries[i] = oldEntry;
		}

		return Action(new ActionModifyBatch(GetModel(),oldEntries,_deltas,selection,section,noTextFields));
	}

	else {
		// Get section
		Section sect = GetSection(section);
		size_t len = selection->GetCount();

		// OK, this block warrants some explanation:
		// Copying smart pointers around all the time is quite slow, so I just create them once and
		// access the final copies.
		ActionModifyBatch* antiPtr = new ActionModifyBatch(GetModel(),selection,section,noTextFields);
		Action anti = Action(antiPtr);
		std::vector<VoidPtr>& _deltas = antiPtr->deltas;
		std::vector<Entry>& oldEntries = antiPtr->entries;
		_deltas.resize(len);
		oldEntries.resize(len);

		// For each line...
		for (size_t i=0;i<len;i++) {
			// Get old entry
			Entry& oldEntry = sect->GetEntryRef(selection->GetLine(i));

			// Try to get a delta
			DeltaCoder deltaCoder = oldEntry->GetDeltaCoder();
			if (deltaCoder) {
				if (i < deltas.size() && deltas[i]) _deltas[i] = deltaCoder->EncodeReverseDelta(deltas[i],oldEntry);
				_deltas[i] = deltaCoder->EncodeDelta(entries[i],oldEntry,!noTextFields);
			}

			// Store the whole original line
			else oldEntries[i] = oldEntry;
		}

		return anti;
	}
}