blob: 810546ab61e9d3054f55af0b2fcde84606121712 (
plain)
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
|
using System;
using System.ComponentModel.Composition;
using AppKit;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Editor.DragDrop;
using Microsoft.VisualStudio.Utilities;
using MonoDevelop.DesignerSupport;
using MonoDevelop.DesignerSupport.Toolbox;
using MonoDevelop.Ide.Gui.Documents;
namespace MonoDevelop.TextEditor
{
[Export (typeof (IDropHandlerProvider))]
[DropFormat (ToolboxPad.ToolBoxDragDropFormat)]
[Name (nameof(MonoDevelopToolBoxDropHandlerProvider))]
sealed class MonoDevelopToolBoxDropHandlerProvider : IDropHandlerProvider
{
public IDropHandler GetAssociatedDropHandler (ICocoaTextView cocoaTextView)
{
return new MonoDevelopToolBoxDropHandler (cocoaTextView);
}
}
sealed class MonoDevelopToolBoxDropHandler : IDropHandler
{
private ICocoaTextView cocoaTextView;
public MonoDevelopToolBoxDropHandler (ICocoaTextView cocoaTextView)
{
this.cocoaTextView = cocoaTextView;
}
private bool TryGetConsumer (out IToolboxConsumer toolboxConsumer)
{
if (cocoaTextView.Properties.TryGetProperty<DocumentController> (typeof (DocumentController), out var controller)) {
if (controller.GetContent<IToolboxConsumer> () is IToolboxConsumer consumer) {
var selectedItem = DesignerSupport.DesignerSupport.Service.ToolboxService.SelectedItem;
if (DesignerSupport.DesignerSupport.Service.ToolboxService.IsSupported (selectedItem, consumer)) {
toolboxConsumer = consumer;
return true;
}
}
}
toolboxConsumer = null;
return false;
}
public DragDropPointerEffects HandleDataDropped (DragDropInfo dragDropInfo)
{
if (TryGetConsumer (out var consumer)) {
cocoaTextView.Caret.MoveTo (dragDropInfo.VirtualBufferPosition);
consumer.ConsumeItem (DesignerSupport.DesignerSupport.Service.ToolboxService.SelectedItem);
return DragDropPointerEffects.Move | DragDropPointerEffects.Track;
}
return DragDropPointerEffects.None;
}
public void HandleDragCanceled ()
{
}
public DragDropPointerEffects HandleDraggingOver (DragDropInfo dragDropInfo)
{
if (TryGetConsumer (out var _))
return DragDropPointerEffects.Move | DragDropPointerEffects.Track;
else
return DragDropPointerEffects.None;
}
public DragDropPointerEffects HandleDragStarted (DragDropInfo dragDropInfo)
{
if (TryGetConsumer (out var _))
return DragDropPointerEffects.Move | DragDropPointerEffects.Track;
else
return DragDropPointerEffects.None;
}
public bool IsDropEnabled (DragDropInfo dragDropInfo)
{
return true;
}
}
}
|