-
Notifications
You must be signed in to change notification settings - Fork 263
Drag and Drop and Instancing
You also use instancing with drag and drop editing, as well as with editing using menu items. Drag events are in the context of a control, so you define drag event handlers for the control.
Create handlers for the DragOver
and DragDrop
events on the control in which items can be dropped. DragOver
occurs when the the cursor is dragged over the control. DragDrop
occurs when the mouse is released over the control after dragging.
This handling is well illustrated in the ATF Simple DOM Editor Sample, from which the subsequent code examples are taken. This editor creates lists of sequences. Sequences can have resources added to them by dragging a resource icon from a palette onto the Resources window's ListView
control. The ResourceListEditor
component creates this ListView
control. This component also defines handlers on the ListView
for the dragging events in its IInitializable.Initialize()
method. For other programming details of instance handling in that sample, see IInstancingContext Interface.
The drag over event indicates whether an insertion is possible:
private void resourcesListView_DragOver(object sender, DragEventArgs e)
{
if (m_event != null)
{
EventContext context = m_event.Cast<EventContext>();
e.Effect = DragDropEffects.None;
if (context.CanInsert(e.Data))
{
e.Effect = DragDropEffects.Move;
((Control)sender).Focus(); // Focus the list view; this will cause its context to become active
}
}
}
The event argument is an instance of the EventContext
class, which implements IInstancingContext
. If IInstancingContext.CanInsert()
indicates that insertion is possible, the cursor changes to show where the resource can be dropped. The ListView
control is also activated.
The drag over event performs the resource insertion:
private void resourcesListView_DragDrop(object sender, DragEventArgs e)
{
if (m_event != null)
{
IInstancingContext context = m_event.Cast<IInstancingContext>();
if (context.CanInsert(e.Data))
{
ITransactionContext transactionContext = context as ITransactionContext;
TransactionContexts.DoTransaction(transactionContext,
delegate
{
context.Insert(e.Data);
},
Localizer.Localize("Drag and Drop"));
if (m_statusService != null)
m_statusService.ShowStatus(Localizer.Localize("Drag and Drop"));
}
}
}
Similarly to the drag over event, this handler first checks that the insertion is possible. It adapts the event parameter to both an IInstancingContext
and an ITransactionContext
. EventContext
derives from EditingContext
, which ultimately implements ITransactionContext
in one of its derived classes, TransactionContext
. Similarly to the paste operation from a menu item, the insertion is done by calling IInstancingContext.Insert()
inside a transaction using an ITransactionContext
object.
- What is Instancing: Generally describes instancing, which also requires instances to be selectable.
-
IInstancingContext and IHierarchicalInsertionContext Interfaces: Discuss the
IInstancingContext
interface and its editing methods. -
StandardEditCommands and Instancing: Show how the
StandardEditCommands
component works with instancing. - Drag and Drop and Instancing: Explain how drag and drop is used with instancing.
- Implementing Instancing: Point to examples of implementing instancing in the ATF Simple DOM Editor Sample.
- Home
- Getting Started
- Features & Benefits
- Requirements & Dependencies
- Gallery
- Technology & Samples
- Adoption
- News
- Release Notes
- ATF Community
- Searching Documentation
- Using Documentation
- Videos
- Tutorials
- How To
- Programmer's Guide
- Reference
- Code Samples
- Documentation Files
© 2014-2015, Sony Computer Entertainment America LLC