Created
December 11, 2016 14:47
-
-
Save agc93/9acd5ecd81034a5b82c34cda09260bb4 to your computer and use it in GitHub Desktop.
Nuget Link Drop Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows; | |
using Microsoft.VisualStudio.Text; | |
using Microsoft.VisualStudio.Text.Editor; | |
using Microsoft.VisualStudio.Text.Editor.DragDrop; | |
namespace Cake.VisualStudio.Editor | |
{ | |
class NuGetPackageDropHandler : CakeDropHandler | |
{ | |
private ITextDocument document; | |
private IWpfTextView wpfTextView; | |
public NuGetPackageDropHandler(IWpfTextView wpfTextView, ITextDocument document) | |
{ | |
this.wpfTextView = wpfTextView; | |
this.document = document; | |
} | |
public override DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo) | |
{ | |
throw new NotImplementedException(); | |
} | |
public override bool IsDropEnabled(DragDropInfo dragDropInfo) | |
{ | |
var target = GetDropTarget(dragDropInfo); | |
return false; | |
} | |
private static string GetDropTarget(DragDropInfo dragDropInfo) | |
{ | |
var data = new DataObject(dragDropInfo.Data); | |
if (dragDropInfo.Data.GetDataPresent("FileDrop")) | |
{ | |
var files = data.GetFileDropList(); | |
if (files.Count == 1) | |
{ | |
return files[0]; | |
} | |
} | |
else if (dragDropInfo.Data.GetDataPresent("CF_VSSTGPROJECTITEMS")) | |
{ | |
return data.GetText(); | |
} | |
return null; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel.Composition; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Cake.VisualStudio.Helpers; | |
using Microsoft.VisualStudio.Text; | |
using Microsoft.VisualStudio.Text.Editor; | |
using Microsoft.VisualStudio.Text.Editor.DragDrop; | |
using Microsoft.VisualStudio.Utilities; | |
namespace Cake.VisualStudio.Editor | |
{ | |
[Export(typeof(IDropHandlerProvider))] | |
[DropFormat("Rich Text Format")] | |
[DropFormat("Text")] | |
[Name("NuGetDropHandler")] | |
[ContentType(Constants.CakeContentType)] | |
[Order(Before = "CakeDropHandler")] | |
class NuGetPackageDropHandlerProvider : IDropHandlerProvider | |
{ | |
[Import] | |
ITextDocumentFactoryService TextDocumentFactoryService { get; set; } | |
public IDropHandler GetAssociatedDropHandler(IWpfTextView wpfTextView) | |
{ | |
ITextDocument document; | |
if (TextDocumentFactoryService.TryGetTextDocument(wpfTextView.TextBuffer, out document)) | |
{ | |
return | |
wpfTextView.Properties.GetOrCreateSingletonProperty( | |
() => new NuGetPackageDropHandler(wpfTextView, document)); | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment