public void HandleDragEnter(DragEventArgs e) { //wrap standard IDataObject in OutlookDataObject OleDataObject dataObject = new OleDataObject(e.Data); string[] filenames = null; if (dataObject.GetDataPresent("FileDrop")) { filenames = (string[])dataObject.GetData("FileDrop"); } else if (dataObject.GetDataPresent("FileGroupDescriptor")) { filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); } if (filenames != null) { e.Effect = DragDropEffects.Copy; foreach (string filename in filenames) { string ext = Path.GetExtension(filename).ToLower(); if (!this.AllowedExt.Contains(ext)) { e.Effect = DragDropEffects.None; break; } } } }
public List <string> HandleDrop(DragEventArgs e) { List <string> output = new List <string>(); OleDataObject dataObject = new OleDataObject(e.Data); if (!Directory.Exists(this.OutputDir)) { Directory.CreateDirectory(this.OutputDir); } if (e.Data.GetDataPresent("FileDrop")) { string[] data = (string[])e.Data.GetData("FileDrop"); if (data != null) { foreach (string path in data) { string filename = Path.Combine(this.OutputDir, Path.GetFileName(path).ToLower()); File.Copy(path, filename, true); output.Add(filename); } } } else if (e.Data.GetDataPresent("FileGroupDescriptor")) { //wrap standard IDataObject in OutlookDataObject // OutlookDataObject dataObject = new OutlookDataObject(e.Data); //get the names and data streams of the files dropped string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents"); for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) { //use the fileindex to get the name and data stream MemoryStream filestream = filestreams[fileIndex]; string filename = Path.Combine(this.OutputDir, filenames[fileIndex]); //save the file stream using its name to the application path using (FileStream outputStream = File.Create(filename)) { filestream.WriteTo(outputStream); outputStream.Close(); } filestream.Close(); output.Add(filename); } } return(output); }
public int ToolboxSelectionChanged(IDataObject pSelected) { if (pSelected == null) { return(VSConstants.S_FALSE); } _selectedToolboxData = (OleDataObject)pSelected; ToolboxData data = (ToolboxData)_selectedToolboxData.GetData(typeof(ToolboxData)); editorControl.tbDropData.Text = data.Content; return(VSConstants.S_OK); }
/// <summary> /// Sends notification that an item in the Toolbox is selected through a click, or by pressing ENTER. /// </summary> /// <param name="pDO">Data object that is selected.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns> int IVsToolboxUser.ItemPicked(IOleDataObject pDO) { // Create a OleDataObject from the input interface. OleDataObject oleData = new OleDataObject(pDO); // Check if the picked item is the one we added to the toolbox. if (oleData.GetDataPresent(typeof(Toolbox_TestItem1))) { Debug.WriteLine("MyToolboxItemData selected from the toolbox"); Toolbox_TestItem1 myData = (Toolbox_TestItem1)oleData.GetData(typeof(Toolbox_TestItem1)); //editorControl.Text += myData.Content; } return(VSConstants.S_OK); }
public int ItemPicked(IDataObject pDO) { // Create a OleDataObject from the input interface. OleDataObject oleData = new OleDataObject(pDO); // Check if the picked item is the one we added to the toolbox. if (oleData.GetDataPresent(typeof(ToolboxData))) { System.Diagnostics.Trace.WriteLine("MyToolboxItemData selected from the toolbox"); ToolboxData myData = (ToolboxData)oleData.GetData(typeof(ToolboxData)); editorControl.tbDropData.Text = myData.Content; } return(VSConstants.S_OK); }
public int InterceptDataObject(IDataObject pIn, out IDataObject ppOut) { ToolboxData myData = new ToolboxData("NotDefined"); ppOut = null; if (_selectedToolboxData == null) { return(VSConstants.S_FALSE); } else { myData = (ToolboxData)_selectedToolboxData.GetData(typeof(ToolboxData)); } OleDataObject newtoolboxData = new OleDataObject(); newtoolboxData.SetText($"Dropped {myData?.Content}", System.Windows.Forms.TextDataFormat.Text); ppOut = newtoolboxData; return(VSConstants.S_OK); }
/// <summary> /// The process record. /// </summary> /// <exception cref="PSInvalidOperationException"> /// An error occured /// </exception> protected override void ProcessRecord() { var project = this.Project as VSProject; if (project == null) { throw new PSInvalidOperationException("Cannot cast the Project object to a VSProject"); } var sp = new ServiceProvider((IOleServiceProvider)project.DTE); // Get the toolbox var svsToolbox = sp.GetService(typeof(SVsToolbox)); if (svsToolbox == null) { throw new PSInvalidOperationException("Cannot get global Toolbox Service (SVsToolbox)"); } var toolbox = svsToolbox as IVsToolbox; if (toolbox == null) { throw new PSInvalidOperationException("Cannot cast Toolbox Service to IVsToolbox"); } // Add the tab toolbox.AddTab(this.Category); // Find the assembly in the project references var reference = project.References.Find(this.ActivityAssembly); if (reference == null) { throw new PSInvalidOperationException( "Cannot find a project reference to assembly " + this.ActivityAssembly); } // Load the assembly // Don't load the assembly - this causes problems when uninstalling - see http://wf.codeplex.com/workitem/8762 // var assembly = Assembly.LoadFrom(reference.Path); // Get the activity type // var activityType = assembly.GetType(this.Activity); var assemblyQualifiedName = GetAssemblyQualifiedName(reference.Path, this.Activity); if (string.IsNullOrEmpty(this.DisplayName)) { this.DisplayName = GetNameFromActivity(this.Activity); } IEnumToolboxItems enumToolboxItems; toolbox.EnumItems(this.Category, out enumToolboxItems); var dataObjects = new IDataObject[1]; uint fetched; while (enumToolboxItems.Next(1, dataObjects, out fetched) == VSConstants.S_OK) { if (dataObjects[0] != null && fetched == 1) { // Create an OleDataObject to work with var itemDataObject = new OleDataObject(dataObjects[0]); // Access the data var name = itemDataObject.GetData("CF_WORKFLOW_4"); if (name != null) { // If this toolbox item already exists, remove it if (name.ToString() == this.DisplayName) { // Note: This prevents an old toolbox item from adding a ref to the wrong runtime assembly toolbox.RemoveItem(dataObjects[0]); } } } } var dataObject = new OleDataObject(); dataObject.SetData("AssemblyName", this.ActivityAssembly); dataObject.SetData("CF_WORKFLOW_4", this.DisplayName); dataObject.SetData("WorkflowItemTypeNameFormat", assemblyQualifiedName); // Load the bitmap var bitmap = (Bitmap)Resources.ResourceManager.GetObject(this.BitmapID); if (bitmap == null) { throw new PSInvalidOperationException("Cannot load bitmap ID " + this.BitmapID); } var toolboxItemInfo = new TBXITEMINFO[1]; toolboxItemInfo[0].bstrText = this.DisplayName; toolboxItemInfo[0].hBmp = bitmap.GetHbitmap(); toolboxItemInfo[0].clrTransparent = (uint)ColorTranslator.ToWin32(Color.White); toolbox.AddItem(dataObject, toolboxItemInfo, this.Category); }