archi-scripting-plugin icon indicating copy to clipboard operation
archi-scripting-plugin copied to clipboard

Add function to duplicate a view

Open ghost opened this issue 7 years ago • 3 comments
trafficstars

Please, as this can be done with the Gui.

ghost avatar Aug 21 '18 13:08 ghost

I just looked at the underlying Java code that does this. It's quite complicated and creates a few actions for the Undo/Redo Command Stack. This code can't be used "as is" because jArchi uses a different approach for the Undo/Redo stack.

So this code would need to be more or less duplicated for jArchi. The problem with this is that more and more features might also require underlying duplicated Java code.

An alternate approach is to implement these types of features in JavaScript as part of a jArchi library. jArchi should supply the basic building blocks but not attempt to duplicate every feature in Archi itself.

I'll try to start a library of these types of functions over the coming weeks...

Phillipus avatar Aug 21 '18 14:08 Phillipus

Having said all that, an object.duplicate() or object.copy() method might be a useful core method.

Phillipus avatar Aug 21 '18 14:08 Phillipus

Hi,

I know this is a bit old topic but I had recently the same need to duplicate objects from javascript. So I made a quick workaround by adding this code to 'EObjectProxy' class and redeploying JArchi on my Archi instance:

public void duplicate() {   
	Object[] objects = new Object[1];    
	objects[0] = getEObject();    
	DuplicateCommandHandler handler = new DuplicateCommandHandler(objects);    
	handler.duplicate();   
}

This allowed me to duplicate views and objects from scripts (my test script is $(selection).first().duplicate();)
As I am far from knowing all about Undo/Redo command stacks in both Archi and JArchi this may be a very bad implementation but at least that was enough for my small (and quick) need.

The main drawback of this is that it is not possible to get an handle on the newly created object as DuplicateCommandHandler keeps newly created objects private. This means that this duplicate method can only return void without implementation changes in Archi...

cedepz avatar Nov 25 '19 08:11 cedepz