fix (some) copy & paste bugs in edits

This commit is contained in:
rolux 2013-08-08 17:04:21 +00:00
parent 83dbe50894
commit 086682548f
2 changed files with 36 additions and 26 deletions

View file

@ -27,6 +27,15 @@ pandora.ui.editPanel = function() {
); );
} }
function getClips(ids) {
return ids.map(function(id) {
var clip = Ox.getObjectById(edit.clips, id);
return (
clip.annotation || clip.item + '/' + clip['in'] + '-' + clip.out
) + '/' + id;
});
}
function getSmallTimelineURL() { function getSmallTimelineURL() {
var fps = 25, var fps = 25,
width = Math.floor(edit.duration * fps), width = Math.floor(edit.duration * fps),
@ -109,44 +118,38 @@ pandora.ui.editPanel = function() {
}) })
.bindEvent({ .bindEvent({
copy: function(data) { copy: function(data) {
pandora.clipboard.copy(data.ids.map(function(id) { pandora.clipboard.copy(getClips(data.ids), 'clip');
var clip = Ox.getObjectById(edit.clips, id);
return clip.annotation || clip.item + '/' + clip['in'] + '-' + clip.out;
}), 'clip');
}, },
copyadd: function(data) { copyadd: function(data) {
pandora.clipboard.add(data.ids.map(function(id) { pandora.clipboard.add(getClips(data.ids), 'clip');
var clip = Ox.getObjectById(edit.clips, id);
return clip.annotation || clip.item + '/' + clip['in'] + '-' + clip.out;
}), 'clip');
}, },
cut: function(data) { cut: function(data) {
var clips;
if (edit.editable) { if (edit.editable) {
pandora.clipboard.copy(data.ids.map(function(id) { clips = getClips(data.ids);
var clip = Ox.getObjectById(edit.clips, id); pandora.clipboard.copy(clips, 'clip');
return clip.annotation || clip.item + '/' + clip['in'] + '-' + clip.out; pandora.doHistory('cut', clips, ui.edit, function(result) {
}), 'clip');
pandora.doHistory('cut', data.ids, ui.edit, function(result) {
Ox.Request.clearCache('getEdit'); Ox.Request.clearCache('getEdit');
updateClips(result.data.clips); updateClips(result.data.clips);
}); });
} }
}, },
cutadd: function(data) { cutadd: function(data) {
var clips;
if (edit.editable) { if (edit.editable) {
pandora.clipboard.add(data.ids.map(function(id) { clips = getClips(data.ids);
var clip = Ox.getObjectById(edit.clips, id); pandora.clipboard.add(clips, 'clip');
return clip.annotation || clip.item + '/' + clip['in'] + '-' + clip.out; pandora.doHistory('cut', clips, ui.edit, function(result) {
}), 'clip');
pandora.doHistory('cut', data.ids, ui.edit, function(result) {
Ox.Request.clearCache('getEdit'); Ox.Request.clearCache('getEdit');
updateClips(result.data.clips); updateClips(result.data.clips);
}); });
} }
}, },
'delete': function(data) { 'delete': function(data) {
var clips;
if (edit.editable) { if (edit.editable) {
pandora.doHistory('delete', data.ids, ui.edit, function(result) { clips = getClips(data.ids);
pandora.doHistory('delete', clips, ui.edit, function(result) {
Ox.Request.clearCache('getEdit'); Ox.Request.clearCache('getEdit');
updateClips(result.data.clips); updateClips(result.data.clips);
}); });

View file

@ -316,6 +316,7 @@ pandora.createLinks = function($element) {
items: action == 'cut' || action == 'delete' ? [items] items: action == 'cut' || action == 'delete' ? [items]
: action == 'copy' || action == 'paste' ? [addedItems] : action == 'copy' || action == 'paste' ? [addedItems]
: [items, addedItems], : [items, addedItems],
positions: [],
targets: targets, targets: targets,
text: text text: text
}); });
@ -382,7 +383,7 @@ pandora.createLinks = function($element) {
} }
}); });
} else { } else {
pandora.api.addClips({clips: parseClips(items), edit: target, index: 0}, callback); pandora.api.addClips({clips: getClipData(items), edit: target, index: -1}, callback);
} }
} }
@ -417,11 +418,7 @@ pandora.createLinks = function($element) {
callback && callback(); callback && callback();
} }
function getType(items) { function getClipData(items) {
return items[0] && Ox.contains(items[0], '/') ? 'clip' : 'item';
}
function parseClips(items) {
return items.map(function(clip) { return items.map(function(clip) {
var split = clip.split('/'), var split = clip.split('/'),
item = split[0], item = split[0],
@ -437,12 +434,22 @@ pandora.createLinks = function($element) {
}); });
} }
function getClipIds(items) {
return items.map(function(clip) {
return clip.split('/').pop();
});
}
function getType(items) {
return items[0] && Ox.contains(items[0], '/') ? 'clip' : 'item';
}
function removeItems(items, target, callback) { function removeItems(items, target, callback) {
var type = getType(items); var type = getType(items);
if (type == 'item') { if (type == 'item') {
pandora.api.removeListItems({items: items, list: target}, callback); pandora.api.removeListItems({items: items, list: target}, callback);
} else { } else {
pandora.api.removeClips({clips: parseClips(items), edit: target}, callback); pandora.api.removeClips({ids: getClipIds(items), edit: target}, callback);
} }
} }