Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for copy functionallity #164

Merged
merged 5 commits into from
Apr 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions GongSolutions.Wpf.DragDrop/DefaultDropHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ public class DefaultDropHandler : IDropTarget
public virtual void DragOver(IDropInfo dropInfo)
{
if (CanAcceptData(dropInfo)) {
// when source is the same as the target set the move effect otherwise set the copy effect
var moveData = dropInfo.DragInfo.VisualSource == dropInfo.VisualTarget
|| !dropInfo.KeyStates.HasFlag(dropInfo.DragInfo.DragDropCopyKeyState)
|| dropInfo.DragInfo.VisualSourceItem is TabItem
|| dropInfo.DragInfo.VisualSourceItem is TreeViewItem
|| dropInfo.DragInfo.VisualSourceItem is MenuItem
|| dropInfo.DragInfo.VisualSourceItem is ListBoxItem;
dropInfo.Effects = moveData ? DragDropEffects.Move : DragDropEffects.Copy;
// default should always the move action/effect
var copyData = (dropInfo.DragInfo.DragDropCopyKeyState != default(DragDropKeyStates)) && dropInfo.KeyStates.HasFlag(dropInfo.DragInfo.DragDropCopyKeyState)
//&& (dropInfo.DragInfo.VisualSource != dropInfo.VisualTarget)
&& !(dropInfo.DragInfo.SourceItem is HeaderedContentControl)
&& !(dropInfo.DragInfo.SourceItem is HeaderedItemsControl)
&& !(dropInfo.DragInfo.SourceItem is ListBoxItem);
dropInfo.Effects = copyData ? DragDropEffects.Copy : DragDropEffects.Move;
var isTreeViewItem = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) && dropInfo.VisualTargetItem is TreeViewItem;
dropInfo.DropTargetAdorner = isTreeViewItem ? DropTargetAdorners.Highlight : DropTargetAdorners.Insert;
}
Expand All @@ -53,14 +52,13 @@ public virtual void Drop(IDropInfo dropInfo)
var destinationList = dropInfo.TargetCollection.TryGetList();
var data = ExtractData(dropInfo.Data);

// when source is the same as the target remove the data from source and fix the insertion index
var moveData = dropInfo.DragInfo.VisualSource == dropInfo.VisualTarget
|| !dropInfo.KeyStates.HasFlag(dropInfo.DragInfo.DragDropCopyKeyState)
|| dropInfo.DragInfo.VisualSourceItem is TabItem
|| dropInfo.DragInfo.VisualSourceItem is TreeViewItem
|| dropInfo.DragInfo.VisualSourceItem is MenuItem
|| dropInfo.DragInfo.VisualSourceItem is ListBoxItem;
if (moveData)
// default should always the move action/effect
var copyData = (dropInfo.DragInfo.DragDropCopyKeyState != default(DragDropKeyStates)) && dropInfo.KeyStates.HasFlag(dropInfo.DragInfo.DragDropCopyKeyState)
//&& (dropInfo.DragInfo.VisualSource != dropInfo.VisualTarget)
&& !(dropInfo.DragInfo.SourceItem is HeaderedContentControl)
&& !(dropInfo.DragInfo.SourceItem is HeaderedItemsControl)
&& !(dropInfo.DragInfo.SourceItem is ListBoxItem);
if (!copyData)
{
var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();

Expand Down