user940016
user940016

Reputation: 2948

Move-only with drag & drop in a Flex tree

I have a tree (in Flex 3.5), and I want to use the drag & drop functionality, but I want to let the user only move nodes, not copy them. I tried listening for the dragOver event and change the drag event's action property if it indicates a copy operation, and also listening for the keyDown event and changing the feedback using the DragManager if the pressed key was ctrl, but to no avail.

Does anybody have another idea? Thanks.

Upvotes: 1

Views: 797

Answers (4)

Esha Wali
Esha Wali

Reputation: 19

You have to extend the class. In the answer by Sab Than, the base class handlers will be invoked and hence, overriding the action will become useless. SO before base class handler is invoked, we need to override the action type.

Upvotes: 0

Sab Than
Sab Than

Reputation: 171

Instead of extending Tree class (unnecessarily), we can implement the same logic as in the above answers by adding our own event handlers for dragOver, dragDrop. Our event handlers execute before the default ones and can therefore modify the event attributes like action. So one example would be

<mx:DataGrid id="datagrid" dragEnabled="true" dropEnabled="true" 
    dragMoveEnabled="true" dragEnter="datagrid_dragEnterHandler(event)"
    dragDrop="datagrid_dragDropHandler(event)" 
    dragOver="datagrid_dragOverHandler(event)"/>
....
protected function datagrid_dragDropHandler(event:DragEvent):void {
    event.action = DragManager.MOVE;
}
protected function datagrid_dragOverHandler(event:DragEvent):void {
    event.action = DragManager.MOVE;
}

Upvotes: 0

Esha Wali
Esha Wali

Reputation: 21

Overide all drag handlers and add event.action = DragManager.MOVE See below:

    override protected function dragEnterHandler(event:DragEvent):void{
        if(event.action == DragManager.COPY)
            event.action=DragManager.MOVE;
        super.dragEnterHandler(event);
    }

    override protected function dragCompleteHandler(event:DragEvent):void{
        if(event.action == DragManager.COPY)
            event.action=DragManager.MOVE;
        super.dragCompleteHandler(event);
    }

    override protected function dragDropHandler(event:DragEvent):void{
        if(event.action == DragManager.COPY)
            event.action=DragManager.MOVE;
        super.dragDropHandler(event);
    }

    override protected function dragExitHandler(event:DragEvent):void{
        if(event.action == DragManager.COPY)
            event.action=DragManager.MOVE;
        super.dragExitHandler(event);
    }

    override protected function dragOverHandler(event:DragEvent):void{
        if(event.action == DragManager.COPY)
            event.action=DragManager.MOVE;
        super.dragOverHandler(event);
    }

    override protected function dragStartHandler(event:DragEvent):void{
        if(event.action == DragManager.COPY)
            event.action=DragManager.MOVE;
        super.dragStartHandler(event);
    }

This will make the list move only.. and wudnot support copy.

Upvotes: 2

moropus
moropus

Reputation: 3782

You can override dragEnterHandler, dragOverHandler and dragDropHandler functions in Tree, since all are protected and quite simple, in order not to show copy feedback and not to allow user to copy via drag:

override protected function dragEnterHandler(event:DragEvent):void
{
    // ...
}

override protected function dragOverHandler(event:DragEvent):void
{
    // ...
}

Upvotes: 0

Related Questions