Preserve linked cels between documents when Copy/Paste is used in the Timeline

Fix #734
This commit is contained in:
David Capello 2015-08-07 17:09:03 -03:00
parent 55477ce0d5
commit a73d0cf846

View File

@ -314,15 +314,16 @@ void clipboard::paste()
case DocumentRange::kCels: { case DocumentRange::kCels: {
// Do nothing case: pasting in the same document. // Do nothing case: pasting in the same document.
if (srcDoc == dstDoc) if (srcDoc == dstDoc)
return; return; // TODO paste clipboard content in new location
Transaction transaction(UIContext::instance(), "Paste Cels"); Transaction transaction(UIContext::instance(), "Paste Cels");
DocumentApi api = dstDoc->getApi(transaction); DocumentApi api = dstDoc->getApi(transaction);
frame_t dstFrame = editor->frame(); frame_t dstFrameBegin = editor->frame();
for (frame_t frame = srcRange.frameBegin(); frame <= srcRange.frameEnd(); ++frame) {
if (dstFrame == dstSpr->totalFrames()) // Add extra frames if needed
api.addFrame(dstSpr, dstFrame); while (dstFrameBegin+srcRange.frames() > dstSpr->totalFrames())
api.addFrame(dstSpr, dstSpr->totalFrames());
for (LayerIndex for (LayerIndex
i = srcRange.layerEnd(), i = srcRange.layerEnd(),
@ -330,12 +331,48 @@ void clipboard::paste()
i >= srcRange.layerBegin() && i >= srcRange.layerBegin() &&
i >= LayerIndex(0) && i >= LayerIndex(0) &&
j >= LayerIndex(0); --i, --j) { j >= LayerIndex(0); --i, --j) {
Cel* cel = srcLayers[i]->cel(frame); // Maps a linked Cel in the original sprite with its
// corresponding copy in the new sprite. In this way
// we can.
std::map<Cel*, Cel*> relatedCels;
if (cel && cel->image()) { for (frame_t frame = srcRange.frameBegin(),
dstFrame = dstFrameBegin;
frame <= srcRange.frameEnd();
++frame, ++dstFrame) {
Cel* srcCel = srcLayers[i]->cel(frame);
Cel* srcLink = nullptr;
if (srcCel && srcCel->image()) {
bool createCopy = true;
if (dstLayers[j]->isContinuous() &&
srcCel->links()) {
srcLink = srcCel->link();
if (!srcLink)
srcLink = srcCel;
if (srcLink) {
Cel* dstRelated = relatedCels[srcLink];
if (dstRelated) {
createCopy = false;
// Create a link from dstRelated
api.copyCel(
static_cast<LayerImage*>(dstLayers[j]), dstRelated->frame(),
static_cast<LayerImage*>(dstLayers[j]), dstFrame);
}
}
}
if (createCopy) {
api.copyCel( api.copyCel(
static_cast<LayerImage*>(srcLayers[i]), frame, static_cast<LayerImage*>(srcLayers[i]), frame,
static_cast<LayerImage*>(dstLayers[j]), dstFrame); static_cast<LayerImage*>(dstLayers[j]), dstFrame);
if (srcLink)
relatedCels[srcLink] = dstLayers[j]->cel(dstFrame);
}
} }
else { else {
Cel* dstCel = dstLayers[j]->cel(dstFrame); Cel* dstCel = dstLayers[j]->cel(dstFrame);
@ -344,7 +381,6 @@ void clipboard::paste()
} }
} }
++dstFrame;
} }
transaction.commit(); transaction.commit();