Add support to copy/paste cels in the same sprite

This commit is contained in:
David Capello 2015-08-07 18:27:48 -03:00
parent a73d0cf846
commit 892d36f93c
2 changed files with 17 additions and 9 deletions

View File

@ -1009,8 +1009,6 @@ void Timeline::onRemoveFrame(doc::DocumentEvent& ev)
void Timeline::onSelectionChanged(doc::DocumentEvent& ev)
{
m_range.disableRange();
clearClipboardRange();
invalidate();
}
@ -1027,7 +1025,6 @@ void Timeline::onAfterFrameChanged(Editor* editor)
m_range.disableRange();
showCurrentCel();
clearClipboardRange();
invalidate();
}
@ -1039,7 +1036,6 @@ void Timeline::onAfterLayerChanged(Editor* editor)
m_range.disableRange();
showCurrentCel();
clearClipboardRange();
invalidate();
}

View File

@ -17,6 +17,7 @@
#include "app/document.h"
#include "app/document_api.h"
#include "app/document_range.h"
#include "app/document_range_ops.h"
#include "app/modules/editors.h"
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
@ -312,16 +313,27 @@ void clipboard::paste()
switch (srcRange.type()) {
case DocumentRange::kCels: {
// Do nothing case: pasting in the same document.
if (srcDoc == dstDoc)
return; // TODO paste clipboard content in new location
// We can use a document range op (copy_range) to copy/paste
// cels in the same document.
if (srcDoc == dstDoc) {
DocumentRange dstRange;
LayerIndex dstLayer = srcSpr->layerToIndex(editor->layer());
frame_t dstFrame = editor->frame();
dstRange.startRange(dstLayer, dstFrame,
DocumentRange::kCels);
dstRange.endRange(dstLayer + LayerIndex(- srcRange.layers() + 1),
dstFrame + srcRange.frames() - 1);
copy_range(srcDoc, srcRange, dstRange, kDocumentRangeBefore);
return;
}
Transaction transaction(UIContext::instance(), "Paste Cels");
DocumentApi api = dstDoc->getApi(transaction);
frame_t dstFrameBegin = editor->frame();
// Add extra frames if needed
frame_t dstFrameBegin = editor->frame();
while (dstFrameBegin+srcRange.frames() > dstSpr->totalFrames())
api.addFrame(dstSpr, dstSpr->totalFrames());