Browse Source

Add back drag'n'drop to SharpTreeView.

pull/10/head
Daniel Grunwald 14 years ago
parent
commit
0cb55f64a0
  1. 2
      ILSpy/TextView/DecompilerTextView.cs
  2. 26
      ILSpy/TreeNodes/AssemblyListTreeNode.cs
  3. 9
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  4. 15
      SharpTreeView/DropEffect.cs
  5. 1
      SharpTreeView/ICSharpCode.TreeView.csproj
  6. 125
      SharpTreeView/SharpTreeNode.cs
  7. 26
      SharpTreeView/SharpTreeView.cs
  8. 31
      SharpTreeView/SharpTreeViewItem.cs

2
ILSpy/TextView/DecompilerTextView.cs

@ -271,6 +271,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -271,6 +271,8 @@ namespace ICSharpCode.ILSpy.TextView
textOutput.PrepareDocument();
tcs.SetResult(textOutput);
#if DEBUG
} catch (AggregateException ex) {
tcs.SetException(ex);
} catch (OperationCanceledException ex) {
#else
} catch (Exception ex) {

26
ILSpy/TreeNodes/AssemblyListTreeNode.cs

@ -49,22 +49,24 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -49,22 +49,24 @@ namespace ICSharpCode.ILSpy.TreeNodes
get { return assemblyList.ListName; }
}
/*
public override DropEffect CanDrop(IDataObject data, DropEffect requestedEffect)
public override bool CanDrop(DragEventArgs e, int index)
{
if (data.GetDataPresent(AssemblyTreeNode.DataFormat))
return DropEffect.Move;
else if (data.GetDataPresent(DataFormats.FileDrop))
return DropEffect.Move;
else
return DropEffect.None;
e.Effects = DragDropEffects.Move;
if (e.Data.GetDataPresent(AssemblyTreeNode.DataFormat))
return true;
else if (e.Data.GetDataPresent(DataFormats.FileDrop))
return true;
else {
e.Effects = DragDropEffects.None;
return false;
}
}
public override void Drop(IDataObject data, int index, DropEffect finalEffect)
public override void Drop(DragEventArgs e, int index)
{
string[] files = data.GetData(AssemblyTreeNode.DataFormat) as string[];
string[] files = e.Data.GetData(AssemblyTreeNode.DataFormat) as string[];
if (files == null)
files = data.GetData(DataFormats.FileDrop) as string[];
files = e.Data.GetData(DataFormats.FileDrop) as string[];
if (files != null) {
lock (assemblyList.assemblies) {
var nodes = (from file in files
@ -84,7 +86,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -84,7 +86,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
}
}*/
}
public Action<SharpTreeNode> Select = delegate {};

9
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -206,10 +206,15 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -206,10 +206,15 @@ namespace ICSharpCode.ILSpy.TreeNodes
}
}
/*public override bool CanDrag(SharpTreeNode[] nodes)
public override bool CanDrag(SharpTreeNode[] nodes)
{
return nodes.All(n => n is AssemblyTreeNode);
}*/
}
public override void StartDrag(DependencyObject dragSource, SharpTreeNode[] nodes)
{
DragDrop.DoDragDrop(dragSource, Copy(nodes), DragDropEffects.All);
}
public override bool CanDelete()
{

15
SharpTreeView/DropEffect.cs

@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ICSharpCode.TreeView
{
public enum DropEffect
{
None, Move, Copy, Link
}
}

1
SharpTreeView/ICSharpCode.TreeView.csproj

@ -70,7 +70,6 @@ @@ -70,7 +70,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Converters.cs" />
<Compile Include="DropEffect.cs" />
<Compile Include="EditTextBox.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="GeneralAdorner.cs" />

125
SharpTreeView/SharpTreeNode.cs

@ -569,99 +569,42 @@ namespace ICSharpCode.TreeView @@ -569,99 +569,42 @@ namespace ICSharpCode.TreeView
#endregion
#region Drag and Drop
/*
internal bool InternalCanDrag()
{
return CanDrag(ActiveNodesArray);
}
internal void InternalDrag(DependencyObject dragSource)
{
DragDrop.DoDragDrop(dragSource, Copy(ActiveNodesArray), DragDropEffects.All);
}
internal bool InternalCanDrop(DragEventArgs e, int index)
{
var finalEffect = GetFinalEffect(e, index);
e.Effects = GetDragDropEffects(finalEffect);
return finalEffect != DropEffect.None;
}
internal void InternalDrop(DragEventArgs e, int index)
{
if (LazyLoading) {
EnsureLazyChildren();
index = Children.Count;
}
var finalEffect = GetFinalEffect(e, index);
Drop(e.Data, index, finalEffect);
if (finalEffect == DropEffect.Move) {
foreach (SharpTreeNode node in ActiveNodesArray)
node.DeleteCore();
}
}
DropEffect GetFinalEffect(DragEventArgs e, int index)
{
var requestedEffect = GetDropEffect(e);
var result = CanDrop(e.Data, requestedEffect);
if (result == DropEffect.Move) {
if (!ActiveNodesArray.All(n => n.CanDelete())) {
return DropEffect.None;
}
}
return result;
}
static DropEffect GetDropEffect(DragEventArgs e)
{
if (e.Data != null) {
var all = DragDropKeyStates.ControlKey | DragDropKeyStates.ShiftKey | DragDropKeyStates.AltKey;
if ((e.KeyStates & all) == DragDropKeyStates.ControlKey) {
return DropEffect.Copy;
}
if ((e.KeyStates & all) == DragDropKeyStates.AltKey) {
return DropEffect.Link;
}
if ((e.KeyStates & all) == (DragDropKeyStates.ControlKey | DragDropKeyStates.ShiftKey)) {
return DropEffect.Link;
}
return DropEffect.Move;
}
return DropEffect.None;
}
static DragDropEffects GetDragDropEffects(DropEffect effect)
{
switch (effect) {
case DropEffect.Copy:
return DragDropEffects.Copy;
case DropEffect.Link:
return DragDropEffects.Link;
case DropEffect.Move:
return DragDropEffects.Move;
}
return DragDropEffects.None;
}
public virtual bool CanDrag(SharpTreeNode[] nodes)
{
return false;
}
public virtual DropEffect CanDrop(IDataObject data, DropEffect requestedEffect)
{
return DropEffect.None;
public virtual bool CanDrag(SharpTreeNode[] nodes)
{
return false;
}
public virtual void StartDrag(DependencyObject dragSource, SharpTreeNode[] nodes)
{
DragDropEffects effects = DragDropEffects.All;
if (!nodes.All(n => n.CanDelete()))
effects &= ~DragDropEffects.Move;
DragDropEffects result = DragDrop.DoDragDrop(dragSource, Copy(nodes), effects);
if (result == DragDropEffects.Move) {
foreach (SharpTreeNode node in nodes)
node.DeleteCore();
}
public virtual void Drop(IDataObject data, int index, DropEffect finalEffect)
{
throw new NotSupportedException(GetType().Name + " does not support Drop()");
}
public virtual bool CanDrop(DragEventArgs e, int index)
{
return false;
}
internal void InternalDrop(DragEventArgs e, int index)
{
if (LazyLoading) {
EnsureLazyChildren();
index = Children.Count;
}
*/
Drop(e, index);
}
public virtual void Drop(DragEventArgs e, int index)
{
throw new NotSupportedException(GetType().Name + " does not support Drop()");
}
#endregion
#region IsLast (for TreeView lines)

26
SharpTreeView/SharpTreeView.cs

@ -247,7 +247,6 @@ namespace ICSharpCode.TreeView @@ -247,7 +247,6 @@ namespace ICSharpCode.TreeView
#endregion
#region Drag and Drop
/*
protected override void OnDragEnter(DragEventArgs e)
{
OnDragOver(e);
@ -256,20 +255,20 @@ namespace ICSharpCode.TreeView @@ -256,20 +255,20 @@ namespace ICSharpCode.TreeView
protected override void OnDragOver(DragEventArgs e)
{
e.Effects = DragDropEffects.None;
e.Handled = true;
if (Root != null && !ShowRoot && Root.Children.Count == 0) {
Root.InternalCanDrop(e, 0);
if (Root != null && !ShowRoot) {
e.Handled = true;
Root.CanDrop(e, Root.Children.Count);
}
}
protected override void OnDrop(DragEventArgs e)
{
e.Effects = DragDropEffects.None;
e.Handled = true;
if (Root != null && !ShowRoot && Root.Children.Count == 0) {
Root.InternalDrop(e, 0);
if (Root != null && !ShowRoot) {
e.Handled = true;
Root.InternalDrop(e, Root.Children.Count);
}
}
@ -281,10 +280,10 @@ namespace ICSharpCode.TreeView @@ -281,10 +280,10 @@ namespace ICSharpCode.TreeView
internal void HandleDragOver(SharpTreeViewItem item, DragEventArgs e)
{
HidePreview();
e.Handled = true;
var target = GetDropTarget(item, e);
if (target != null) {
e.Handled = true;
ShowPreview(target.Item, target.Place);
}
}
@ -293,10 +292,10 @@ namespace ICSharpCode.TreeView @@ -293,10 +292,10 @@ namespace ICSharpCode.TreeView
{
try {
HidePreview();
e.Handled = true;
var target = GetDropTarget(item, e);
if (target != null) {
e.Handled = true;
target.Node.InternalDrop(e, target.Index);
}
} catch (Exception ex) {
@ -390,7 +389,7 @@ namespace ICSharpCode.TreeView @@ -390,7 +389,7 @@ namespace ICSharpCode.TreeView
if (node != null) {
e.Effects = DragDropEffects.None;
if (node.InternalCanDrop(e, index)) {
if (node.CanDrop(e, index)) {
DropTarget target = new DropTarget() {
Item = item,
Place = place,
@ -464,14 +463,14 @@ namespace ICSharpCode.TreeView @@ -464,14 +463,14 @@ namespace ICSharpCode.TreeView
insertMarker.Margin = new Thickness(p.X, p.Y, 0, 0);
SharpTreeNodeView secondNodeView = null;
var index = flattener.List.IndexOf(item.Node);
var index = flattener.IndexOf(item.Node);
if (place == DropPlace.Before) {
if (index > 0) {
secondNodeView = (ItemContainerGenerator.ContainerFromIndex(index - 1) as SharpTreeViewItem).NodeView;
}
}
else if (index + 1 < flattener.List.Count) {
else if (index + 1 < flattener.Count) {
secondNodeView = (ItemContainerGenerator.ContainerFromIndex(index + 1) as SharpTreeViewItem).NodeView;
}
@ -497,7 +496,6 @@ namespace ICSharpCode.TreeView @@ -497,7 +496,6 @@ namespace ICSharpCode.TreeView
previewNodeView = null;
}
}
*/
#endregion
#region Cut / Copy / Paste / Delete Commands

31
SharpTreeView/SharpTreeViewItem.cs

@ -84,9 +84,10 @@ namespace ICSharpCode.TreeView @@ -84,9 +84,10 @@ namespace ICSharpCode.TreeView
if (Math.Abs(currentPoint.X - startPoint.X) >= SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(currentPoint.Y - startPoint.Y) >= SystemParameters.MinimumVerticalDragDistance) {
// if (Node.InternalCanDrag()) {
// Node.InternalDrag(this);
// }
var selection = ParentTreeView.GetTopLevelSelection().ToArray();
if (Node.CanDrag(selection)) {
Node.StartDrag(this, selection);
}
}
}
}
@ -110,5 +111,29 @@ namespace ICSharpCode.TreeView @@ -110,5 +111,29 @@ namespace ICSharpCode.TreeView
}
#endregion
#region Drag and Drop
protected override void OnDragEnter(DragEventArgs e)
{
ParentTreeView.HandleDragEnter(this, e);
}
protected override void OnDragOver(DragEventArgs e)
{
ParentTreeView.HandleDragOver(this, e);
}
protected override void OnDrop(DragEventArgs e)
{
ParentTreeView.HandleDrop(this, e);
}
protected override void OnDragLeave(DragEventArgs e)
{
ParentTreeView.HandleDragLeave(this, e);
}
#endregion
}
}

Loading…
Cancel
Save