public void Drop(IDropInfo dropInfo)
{
var source = dropInfo.Data as LayerModel;
var target = dropInfo.TargetItem as LayerModel;
if (source == null || target == null || source == target)
return;
// Don't allow a folder to become it's own child, that's just weird
if (target.Parent == source)
return;
// Remove the source from it's old profile/parent
if (source.Parent == null)
{
var profile = source.Profile;
source.Profile.Layers.Remove(source);
profile.FixOrder();
}
else
{
var parent = source.Parent;
source.Parent.Children.Remove(source);
parent.FixOrder();
}
if (dropInfo.InsertPosition == RelativeInsertPosition.TargetItemCenter &&
target.LayerType is FolderType)
{
// Insert into folder
source.Order = -1;
target.Children.Add(source);
target.FixOrder();
target.Expanded = true;
}
else
{
// Insert the source into it's new profile/parent and update the order
if (dropInfo.InsertPosition == RelativeInsertPosition.AfterTargetItem ||
dropInfo.InsertPosition ==
(RelativeInsertPosition.TargetItemCenter | RelativeInsertPosition.AfterTargetItem))
target.InsertAfter(source);
else
target.InsertBefore(source);
}
UpdateLayerList(source);
}