PDA

View Full Version : Arrgh!



Foen
April 23rd, 2008, 12:55
I am trying to implement drag-and-drop functionality for complex objects, and have hit a bit of a brick wall.

The objects have rich text fields and windowlists in them, and that seems to be the source of the problem.

Rich Text

Rich text database nodes and window controls do not expose setValue and getValue methods, making them difficult to copy from within script. Luckily, the built-in <acceptdrop> element for windowlists overcomes this problem, and happily copies the rich text for you.

Window Lists

Window lists, or database nodes with sub-nodes, are not copied by <acceptdrop>, or at least not by my efforts to date. Luckily, an onDrop handler in the list can copy them programmatically.

The Rub

The sequence of events when dropping an object on to a windowlist seems to be as follows:

The windowlist onDrop handler is called. If it returns true, the process halts. If it returns nil the following two steps are executed. If it returns false, the object drops onto the desktop. The onDrop handler can 'see' the source data, embedded in the draginfo parameter.
The windowclass is created in the list, with its database node, and the windowclass onInit handler is called. The onInit handler cannot see any dropped data, because it hasn't been populated yet.
The acceptdrop automation occurs, and copies the field contents from the source database node to the target database node.

In the example of an NPC, with a rich text description and a list of skills (say), I can try to copy the skill list in step 1 but the target database node isn't created until step 2. If I create a new node, a second one is added in step 2. If I prevent step 2 from happening, to avoid the duplicate, then the rich text won't be copied for me in step 3.

I cannot copy the skill list in step 2, because the source node isn't visible to the onInit handler, and step 3 refuses to copy the skill list.

Has anyone found a way around this problem?

Cheers

Stuart

Foen
April 23rd, 2008, 13:15
Well, I have solved this one with a clunky work-around, posted here so others might learn and laugh at my inellegance :)

In the onDrop handler, I save a copy of the source database node in a local variable of the windowlist. I provide a method (getSource) which returns the saved node and then clears the local variable.

In the onInit handler, I call the getSource method and programmatically copy the sub-nodes into the newly created instance. In the example above, the NPC onInit would check getSource and copy across the skills. I rely on the <acceptdrop> processing to instantiate the database node, create the window class and copy the rich text and other nodes across.

Messy, but it seems to work.

Stuart

joshuha
April 23rd, 2008, 14:00
The formatted text get/set thing is definitely one scheduled to get fixed. When that is fixed the manual method will still be the better when dealing with lists as you get more control that way.