@Override
public void execute() {
//duplicate the selection
final List<SNode> dupes = new ArrayList<SNode>();
SketchDocument doc = (SketchDocument) context.getDocument();
for(SNode node : context.getSelection().sortedItems(doc)) {
SNode dupe = node.duplicate(null);
if(offset) {
dupe.setTranslateX(dupe.getTranslateX()+100);
dupe.setTranslateY(dupe.getTranslateY()+100);
}
dupes.add(dupe);
}
//make it undoable
context.getUndoManager().pushAction(new UndoManager.UndoableAction(){
public void executeUndo() {
SketchDocument doc = (SketchDocument) context.getDocument();
for(SNode dupe : dupes) {
doc.getCurrentPage().remove(dupe);
}
context.getSelection().clear();
}
public void executeRedo() {
SketchDocument doc = (SketchDocument) context.getDocument();
for(SNode dupe : dupes) {
doc.getCurrentPage().add(dupe);
doc.setDirty(true);
}
}
public String getName() {
return "duplicate";
}
});
//clear selection
context.getSelection().clear();
//add to the doc
for(SNode dupe : dupes) {
doc.getCurrentPage().add(dupe);
doc.setDirty(true);
context.getSelection().addSelectedNode(dupe);
}
}