| Online Eiffel Documentation

EiffelStudio

# EiffelVision Pick and Drop

Pick and drop is a mechanism which allows data to be transported from a source object to a target. Any Vision2 object inheriting EV_PICK_AND_DROPABLE can be used to transport or receive data.

## A simple pick and drop example

Two necessary components for a pick and drop transport are a source and a target, both of which must conform to EV_PICK_AND_DROPABLE. The data that is to be transported is known as a pebble.

The following steps need to be undertaken to set up a simple pick and drop:

- Set the source by calling set_pebble.
- Set one or more targets by adding a function to their drop_actions. The arguments of the function must match the type of the pebble to be transported for the source otherwise the transport will not be permitted.

A simple example of this is demonstrated here:

    	button1.set_pebble ("A PND transport has occured%N")
    	button2.drop_actions.extend (agent print (?))

As print takes an argument of type STRING_8, button2 becomes a valid target for the pebble contained in button1. Right clicking the mouse pointer over the source will start the transport, and right clicking with the mouse pointer over a valid target will end the transport. The transport can be canceled anytime with a simple left click, just as you would do in EiffelStudio.

Note: When a transport completes, the pebble that was transported is passed as an argument to all features in the targetsdrop_actions whose argument type matches the pebble

## Three different modes of transport

There are three different modes of transport available for pick and drop. They are listed below with details of their use:

- Pick and Drop mode.
  This is the default mode for pick and drop, but can be set with set_pick_and_drop_mode. Right clicking on a source starts the transport and right clicking on a valid target completes the transport. During execution, a band is drawn from the screen position where the pick started to the current mouse position. Pressing the left mouse button or the escape key during execution will end the transport.
- Drag and drop mode
  This mode can be set with set_drag_and_drop_mode. Left clicking on a source starts the transport and releasing the left mouse button over a valid target completes the transport. During execution, a band is drawn from the screen position where the pick started to the current mouse position. Releasing the left mouse button or pressing the escape key during execution will end the transport.
- Target menu mode
  This mode can be set with set_target_menu_mode. Right clicking on a source brings up a menu of all the valid drop targets in the system. Selecting one of these targets completes the transport.

## Accept and deny cursors

When mode_is_pick_and_drop or mode_is_drag_and_drop then the shape of the mouse cursor changes to reflect whether the current GUI component below the mouse accepts the pebble or not. Calling set_accept_cursor allows you to customize this cursor used to represent a valid target while calling set_deny_cursor allows you to customize the cursor used for non valid targets.