forked from xamarin/mac-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDragDelegate.cs
102 lines (88 loc) · 3.08 KB
/
DragDelegate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Linq;
using ObjCRuntime;
using AppKit;
using ImageKit;
using Foundation;
namespace ImageKitDemo
{
public class DragDelegate: NSDraggingDestination
{
public DragDelegate (IKImageBrowserView view)
{
browserView = view;
}
IKImageBrowserView browserView;
public override NSDragOperation DraggingEntered (NSDraggingInfo sender)
{
Console.WriteLine ("Drag Delegate received 'DraggingEntered'");
return DraggingUpdated (sender);
}
public override NSDragOperation DraggingUpdated (NSDraggingInfo sender)
{
//The ImageBrowserView uses this method to set the icon during dragging. Regardless
//of what we return the view will send a moveitems message to the datasource.
//so it is best to not display the copy icon.
//Console.WriteLine ("Drag Delegate received 'DraggingUpdated'");
NSObject obj = sender.DraggingSource;
if (obj != null && obj.Equals (browserView))
{
return NSDragOperation.Move;
}
return NSDragOperation.Copy;
}
public override bool PerformDragOperation (NSDraggingInfo sender)
{
Console.WriteLine ("Drag Delegate received 'PerformDragOperation' sender: {0}", sender);
//It seems that browserView does not send this message when it is an internal move.
//It does all the work by sending a moveitems message to the datasource,
// but I return false here just to be safe.
NSObject obj = sender.DraggingSource;
if (obj != null && obj.Equals (browserView)) {
Console.WriteLine ("\tLet the image browser handle it.");
return false;
}
NSPasteboard pb = sender.DraggingPasteboard ;
NSArray data = null;
// if (pb.Types.Contains (NSPasteboard.NSUrlType))
// data = pb.GetPropertyListForType (NSPasteboard.NSUrlType) as NSArray;
if (pb.Types.Contains (NSPasteboard.NSFilenamesType))
data = pb.GetPropertyListForType (NSPasteboard.NSFilenamesType) as NSArray;
if (data != null) {
for (int i = 0; i < (int) data.Count; i++) {
string path = (string)NSString.FromHandle (data.ValueAt ((uint)i));
Console.WriteLine ("From pasteboard Item {0} = {1}", i, path);
((BrowseData)browserView.DataSource).AddImages (
NSUrl.FromFilename (path), (int)browserView.GetIndexAtLocationOfDroppedItem ());
browserView.ReloadData ();
}
}
return true;
}
#region implemented only for testing
public override bool PrepareForDragOperation (NSDraggingInfo sender)
{
Console.WriteLine ("Drag Delegate received 'PrepareForDragOperation'");
return true;
}
public override void ConcludeDragOperation (NSDraggingInfo sender)
{
Console.WriteLine ("Drag Delegate received 'ConcludeDragOperation'");
}
public override void DraggingExited (NSDraggingInfo sender)
{
Console.WriteLine ("Drag Delegate received 'DraggingExited'");
}
public override void DraggingEnded (NSDraggingInfo sender)
{
Console.WriteLine ("Drag Delegate received 'DraggingEnded'");
}
public override bool WantsPeriodicDraggingUpdates {
get {
Console.WriteLine ("Drag Delegate was queried for 'WantsPeriodicDraggingUpdates'");
return true;
}
}
#endregion
}
}