/// <summary> /// Determines if the paste command should be allowed. /// </summary> /// <returns></returns> protected internal override bool AllowPasteCommand() { IOleDataObject dataObject = null; try { ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleGetClipboard(out dataObject)); if (dataObject == null) { return(false); } // First see if this is a set of storage based items FORMATETC format = DragDropHelper.CreateFormatEtc((ushort)DragDropHelper.CF_VSSTGPROJECTITEMS); if (dataObject.QueryGetData(new FORMATETC[] { format }) == VSConstants.S_OK) { return(true); } // Try reference based items format = DragDropHelper.CreateFormatEtc((ushort)DragDropHelper.CF_VSREFPROJECTITEMS); if (dataObject.QueryGetData(new FORMATETC[] { format }) == VSConstants.S_OK) { return(true); } // Try windows explorer files format format = DragDropHelper.CreateFormatEtc((ushort)NativeMethods.CF_HDROP); return(dataObject.QueryGetData(new FORMATETC[] { format }) == VSConstants.S_OK); } // We catch External exceptions since it might be that it is not our data on the clipboard. catch (ExternalException e) { Trace.WriteLine("Exception :" + e.Message); return(false); } }
/// <summary> /// Get the dropdatatype from the dataobject /// </summary> /// <param name="pDataObject">The dataobject to be analysed for its format</param> /// <returns>dropdatatype or none if dataobject does not contain known format</returns> internal static DropDataType QueryDropDataType(IOleDataObject pDataObject) { if (pDataObject == null) { return(DropDataType.None); } // known formats include File Drops (as from WindowsExplorer), // VSProject Reference Items and VSProject Storage Items. FORMATETC fmt = DragDropHelper.CreateFormatEtc(NativeMethods.CF_HDROP); if (DragDropHelper.QueryGetData(pDataObject, ref fmt) == VSConstants.S_OK) { return(DropDataType.Shell); } fmt.cfFormat = DragDropHelper.CF_VSREFPROJECTITEMS; if (DragDropHelper.QueryGetData(pDataObject, ref fmt) == VSConstants.S_OK) { // Data is from a Ref-based project. return(DropDataType.VsRef); } fmt.cfFormat = DragDropHelper.CF_VSSTGPROJECTITEMS; if (DragDropHelper.QueryGetData(pDataObject, ref fmt) == VSConstants.S_OK) { return(DropDataType.VsStg); } return(DropDataType.None); }
/// <summary> /// Returns a dataobject from selected nodes /// </summary> /// <param name="cutHighlightItems">boolean that defines if the selected items must be cut</param> /// <returns>data object for selected items</returns> internal virtual DataObject PackageSelectionDataObject(bool cutHighlightItems) { this.CleanupSelectionDataObject(false, false, false); StringBuilder sb = new StringBuilder(); DataObject dataObject = null; try { IList <HierarchyNode> selectedNodes = this.GetSelectedNodes(); if (selectedNodes != null) { this.InstantiateItemsDraggedOrCutOrCopiedList(); StringBuilder selectionContent = null; // If there is a selection package the data if (selectedNodes.Count > 1) { foreach (HierarchyNode node in selectedNodes) { selectionContent = node.PrepareSelectedNodesForClipBoard(); if (selectionContent != null) { sb.Append(selectionContent); } } } else if (selectedNodes.Count == 1) { HierarchyNode selectedNode = selectedNodes[0]; selectionContent = selectedNode.PrepareSelectedNodesForClipBoard(); if (selectionContent != null) { sb.Append(selectionContent); } } } // Add the project items first. IntPtr ptrToItems = this.PackageSelectionData(sb, false); if (ptrToItems == IntPtr.Zero) { return(null); } FORMATETC fmt = DragDropHelper.CreateFormatEtc(DragDropHelper.CF_VSSTGPROJECTITEMS); dataObject = new DataObject(); dataObject.SetData(fmt, ptrToItems); // Now add the project path that sourced data. We just write the project file path. IntPtr ptrToProjectPath = this.PackageSelectionData(new StringBuilder(this.GetMkDocument()), true); if (ptrToProjectPath != IntPtr.Zero) { dataObject.SetData(DragDropHelper.CreateFormatEtc(DragDropHelper.CF_VSPROJECTCLIPDESCRIPTOR), ptrToProjectPath); } if (cutHighlightItems) { bool first = true; IVsUIHierarchyWindow w = UIHierarchyUtilities.GetUIHierarchyWindow(this.site, HierarchyNode.SolutionExplorer); foreach (HierarchyNode node in this.ItemsDraggedOrCutOrCopied) { ErrorHandler.ThrowOnFailure(w.ExpandItem((IVsUIHierarchy)this, node.ID, first ? EXPANDFLAGS.EXPF_CutHighlightItem : EXPANDFLAGS.EXPF_AddCutHighlightItem)); first = false; } } } catch (COMException e) { Trace.WriteLine("Exception : " + e.Message); dataObject = null; } return(dataObject); }