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
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