/// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject1]/*' />
 public OleDataObject(IDataObject winData)
     : base(winData)
 {
     this.oleData = winData as IOleDataObject;
     if (null == this.oleData)
         oleData = (IOleDataObject)(new Ole2BclDataObject(this as IComDataObject));
 }
 /// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject2]/*' />
 public OleDataObject(IComDataObject comData)
     : base(comData)
 {
     oleData = comData as IOleDataObject;
     if (null == oleData)
         this.oleData = (IOleDataObject)(new Ole2BclDataObject(comData));
 }
        /// <summary>
        /// This is overridden to handle drop operations correctly in a help file builder project
        /// </summary>
        /// <inheritdoc />
        public override int Drop(IOleDataObject pDataObject, uint grfKeyState, uint itemid, ref uint pdwEffect)
        {
            DropDataType dropDataType = DropDataType.None;

            if (pDataObject == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            pdwEffect = (uint)DropEffect.None;

            // If the source is within the project, let the base class handle it
            if (this.SourceDraggedOrCutOrCopied)
            {
                return(base.Drop(pDataObject, grfKeyState, itemid, ref pdwEffect));
            }

            // Get the node that is being dragged over and ask it which node should handle this call
            HierarchyNode targetNode = NodeFromItemId(itemid);

            if (targetNode == null)
            {
                return(VSConstants.S_FALSE);
            }

            targetNode = targetNode.GetDragTargetHandlerNode();

            dropDataType = this.HandleSelectionDataObject(pDataObject, targetNode);

            // Since we can get a mix of files that may not necessarily be moved into the project (i.e.
            // documentation sources and references), we'll always act as if they were copied.
            pdwEffect = (uint)DropEffect.Copy;

            return((dropDataType != DropDataType.Shell) ? VSConstants.E_FAIL : VSConstants.S_OK);
        }
Example #4
0
        /// <summary>
        /// 检查工具箱栏目是否存在.
        /// </summary>
        bool VerifyToolboxItemExist()
        {
            LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
                     string.Format("Entering VerifyToolboxItemExist for: {0}", this.ToString()));

            bool exist = false;
            IEnumToolboxItems items;
            uint num;

            ErrorHandler.ThrowOnFailure(vsToolbox2.EnumItems(toolboxTabString, out items));
            var rgelt = new Microsoft.VisualStudio.OLE.Interop.IDataObject[1];

            for (int i = items.Next(1, rgelt, out num);
                 (ErrorHandler.Succeeded(i) && (num > 0)) && (rgelt[0] != null);
                 i = items.Next(1, rgelt, out num))
            {
                string displayName;
                var    hr = (vsToolbox2 as IVsToolbox3).GetItemDisplayName(rgelt[0], out displayName);
                ErrorHandler.ThrowOnFailure(hr);

                if (displayName.Equals(toolboxItemString, StringComparison.OrdinalIgnoreCase))
                {
                    exist = true;
                    break;
                }
            }

            LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
                     string.Format("VerifyToolboxItemExist {0}: {1}", toolboxItemString, exist));

            return(exist);
        }
Example #5
0
        public static string GetSourceProjectPath(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject)
        {
            string    projectPath = null;
            FORMATETC fmtetc      = CreateFormatEtc(CF_VSPROJECTCLIPDESCRIPTOR);

            if (QueryGetData(dataObject, ref fmtetc) == VSConstants.S_OK)
            {
                STGMEDIUM stgmedium = DragDropHelper.GetData(dataObject, ref fmtetc);
                if (stgmedium.tymed == (uint)TYMED.TYMED_HGLOBAL)
                {
                    // We are releasing the cloned hglobal here.
                    IntPtr dropInfoHandle = stgmedium.unionmember;
                    if (dropInfoHandle != IntPtr.Zero)
                    {
                        try
                        {
                            string path = GetData(dropInfoHandle);

                            // Clone the path that we can release our memory.
                            if (!String.IsNullOrEmpty(path))
                            {
                                projectPath = String.Copy(path);
                            }
                        }
                        finally
                        {
                            Marshal.FreeHGlobal(dropInfoHandle);
                        }
                    }
                }
            }

            return(projectPath);
        }
Example #6
0
 public static STGMEDIUM GetData(Microsoft.VisualStudio.OLE.Interop.IDataObject pDataObject, ref FORMATETC fmtetc)
 {
     FORMATETC[] af = new FORMATETC[1];
     af[0] = fmtetc;
     STGMEDIUM[] sm = new STGMEDIUM[1];
     pDataObject.GetData(af, sm);
     fmtetc = af[0];
     return(sm[0]);
 }
Example #7
0
 /// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject1]/*' />
 public OleDataObject(IDataObject winData) :
     base(winData)
 {
     this.oleData = winData as IOleDataObject;
     if (null == this.oleData)
     {
         oleData = (IOleDataObject)(new Ole2BclDataObject(this as IComDataObject));
     }
 }
Example #8
0
 /// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject2]/*' />
 public OleDataObject(IComDataObject comData) :
     base(comData)
 {
     oleData = comData as IOleDataObject;
     if (null == oleData)
     {
         this.oleData = (IOleDataObject)(new Ole2BclDataObject(comData));
     }
 }
Example #9
0
 public void DragLeave()
 {
     if (m_CurrentObject != null)
     {
         m_CurrentObject = null;
     }
     else if (m_DefaultDropTarget != null)
     {
         m_DefaultDropTarget.DragLeave();
     }
 }
Example #10
0
        public static int QueryGetData(Microsoft.VisualStudio.OLE.Interop.IDataObject pDataObject, ref FORMATETC fmtetc)
        {
            FORMATETC[] af = new FORMATETC[1];
            af[0] = fmtetc;
            int result = pDataObject.QueryGetData(af);

            if (result == VSConstants.S_OK)
            {
                fmtetc = af[0];
                return(VSConstants.S_OK);
            }
            return(result);
        }
Example #11
0
        public void DragEnter(IOleDataObject pDataObj, uint grfKeyState, IOlePoint pt, ref uint pdwEffect)
        {
            if ((OutlookDrop != null) && OutlookUtil.IsOutlookItem(pDataObj))
            {
                m_CurrentObject = pDataObj;
                pdwEffect       = DragDropUtil.DRAGDROP_LINK;
            }
            else if (m_DefaultDropTarget != null)
            {
                m_DefaultDropTarget.DragEnter(pDataObj, grfKeyState, pt, pdwEffect);

                if (pdwEffect != DragDropUtil.DRAGDROP_NONE)
                {
                    pdwEffect = DragDropUtil.DRAGDROP_LINK;
                }
            }
        }
Example #12
0
        int IVsToolboxUser.ItemPicked(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO)
        {
            // Redirect toolbox queries to supporting tool windows if the document is not the
            // active selection container.
            object           selectionContainer = MonitorSelection.CurrentSelectionContainer;
            IVsToolboxUser   redirectUser;
            IORMDesignerView designerView;

            if (selectionContainer != this &&
                null != (redirectUser = selectionContainer as IVsToolboxUser) &&
                null != (designerView = selectionContainer as IORMDesignerView) &&
                null != designerView.CurrentDiagram)
            {
                return(redirectUser.ItemPicked(pDO));
            }
            return(ItemPicked(pDO));
        }
Example #13
0
        /// <summary>
        /// Retrieves data from a VS format.
        /// </summary>
        public static List <string> GetDroppedFiles(ushort format, Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject, out DropDataType ddt)
        {
            ddt = DropDataType.None;
            List <string> droppedFiles = new List <string>();

            // try HDROP
            FORMATETC fmtetc = CreateFormatEtc(format);

            if (QueryGetData(dataObject, ref fmtetc) == VSConstants.S_OK)
            {
                STGMEDIUM stgmedium = DragDropHelper.GetData(dataObject, ref fmtetc);
                if (stgmedium.tymed == (uint)TYMED.TYMED_HGLOBAL)
                {
                    // We are releasing the cloned hglobal here.
                    IntPtr dropInfoHandle = stgmedium.unionmember;
                    if (dropInfoHandle != IntPtr.Zero)
                    {
                        ddt = DropDataType.Shell;
                        try
                        {
                            uint numFiles = UnsafeNativeMethods.DragQueryFile(dropInfoHandle, 0xFFFFFFFF, null, 0);

                            // We are a directory based project thus a projref string is placed on the clipboard.
                            // We assign the maximum length of a projref string.
                            // The format of a projref is : <Proj Guid>|<project rel path>|<file path>
                            uint   lenght  = (uint)Guid.Empty.ToString().Length + 2 * NativeMethods.MAX_PATH + 2;
                            char[] moniker = new char[lenght + 1];
                            for (uint fileIndex = 0; fileIndex < numFiles; fileIndex++)
                            {
                                uint   queryFileLength = UnsafeNativeMethods.DragQueryFile(dropInfoHandle, fileIndex, moniker, lenght);
                                string filename        = new String(moniker, 0, (int)queryFileLength);
                                droppedFiles.Add(filename);
                            }
                        }
                        finally
                        {
                            Marshal.FreeHGlobal(dropInfoHandle);
                        }
                    }
                }
            }

            return(droppedFiles);
        }
Example #14
0
        /// <summary>
        ///     Process dataobject from Drag/Drop/Cut/Copy/Paste operation
        /// </summary>
        /// <remarks>The targetNode is set if the method is called from a drop operation, otherwise it is null</remarks>
        internal DropDataType ProcessSelectionDataObject(IOleDataObject dataObject, HierarchyNode targetNode)
        {
            var dropDataType = DropDataType.None;
            var isWindowsFormat = false;

            // Try to get it as a directory based project.
            var filesDropped = DragDropHelper.GetDroppedFiles(DragDropHelper.CF_VSSTGPROJECTITEMS, dataObject,
                out dropDataType);
            if (filesDropped.Count == 0)
            {
                filesDropped = DragDropHelper.GetDroppedFiles(DragDropHelper.CF_VSREFPROJECTITEMS, dataObject,
                    out dropDataType);
            }
            if (filesDropped.Count == 0)
            {
                filesDropped = DragDropHelper.GetDroppedFiles(NativeMethods.CF_HDROP, dataObject, out dropDataType);
                isWindowsFormat = filesDropped.Count > 0;
            }

            if (dropDataType != DropDataType.None && filesDropped.Count > 0)
            {
                var filesDroppedAsArray = filesDropped.ToArray();

                var node = targetNode == null ? this : targetNode;

                // For directory based projects the content of the clipboard is a double-NULL terminated list of Projref strings.
                if (isWindowsFormat)
                {
                    // This is the code path when source is windows explorer
                    var vsaddresults = new VSADDRESULT[1];
                    vsaddresults[0] = VSADDRESULT.ADDRESULT_Failure;
                    var addResult = AddItem(node.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, null,
                        (uint) filesDropped.Count, filesDroppedAsArray, IntPtr.Zero, vsaddresults);
                    if (addResult != VSConstants.S_OK && addResult != VSConstants.S_FALSE &&
                        addResult != (int) OleConstants.OLECMDERR_E_CANCELED
                        && vsaddresults[0] != VSADDRESULT.ADDRESULT_Success)
                    {
                        ErrorHandler.ThrowOnFailure(addResult);
                    }

                    return dropDataType;
                }
                if (AddFilesFromProjectReferences(node, filesDroppedAsArray))
                {
                    return dropDataType;
                }
            }

            // If we reached this point then the drop data must be set to None.
            // Otherwise the OnPaste will be called with a valid DropData and that would actually delete the item.
            return DropDataType.None;
        }
Example #15
0
        /// <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.
            var 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;
        }
Example #16
0
        /// <summary>
        ///     Allows the drag source to prompt to save unsaved items being dropped.
        ///     Notifies the source hierarchy that information dragged from it is about to be dropped on a target.
        ///     This method is called immediately after the mouse button is released on a drop.
        /// </summary>
        /// <param name="o">
        ///     Reference to the IDataObject interface on the item being dragged.
        ///     This data object contains the data being transferred in the drag-and-drop operation.
        ///     If the drop occurs, then this data object (item) is incorporated into the hierarchy window of the new hierarchy.
        /// </param>
        /// <param name="dwEffect">Current state of the keyboard and the mouse modifier keys.</param>
        /// <param name="fCancelDrop">
        ///     If true, then the drop is cancelled by the source hierarchy. If false, then the drop can
        ///     continue.
        /// </param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
        public override int OnBeforeDropNotify(IOleDataObject o, uint dwEffect, out int fCancelDrop)
        {
            // If there is nothing to be dropped just return that drop should be cancelled.
            if (ItemsDraggedOrCutOrCopied == null)
            {
                fCancelDrop = 1;
                return VSConstants.S_OK;
            }

            fCancelDrop = 0;
            var dirty = false;
            foreach (var node in ItemsDraggedOrCutOrCopied)
            {
                bool isDirty, isOpen, isOpenedByUs;
                uint docCookie;
                IVsPersistDocData ppIVsPersistDocData;
                var manager = node.GetDocumentManager();
                if (manager != null)
                {
                    manager.GetDocInfo(out isOpen, out isDirty, out isOpenedByUs, out docCookie, out ppIVsPersistDocData);
                    if (isDirty && isOpenedByUs)
                    {
                        dirty = true;
                        break;
                    }
                }
            }

            // if there are no dirty docs we are ok to proceed
            if (!dirty)
            {
                return VSConstants.S_OK;
            }

            // Prompt to save if there are dirty docs
            var message = SR.GetString(SR.SaveModifiedDocuments, CultureInfo.CurrentUICulture);
            var title = string.Empty;
            var icon = OLEMSGICON.OLEMSGICON_WARNING;
            var buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNOCANCEL;
            var defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
            var result = VsShellUtilities.ShowMessageBox(Site, title, message, icon, buttons, defaultButton);
            switch (result)
            {
                case NativeMethods.IDYES:
                    break;

                case NativeMethods.IDNO:
                    return VSConstants.S_OK;

                case NativeMethods.IDCANCEL:
                    goto default;

                default:
                    fCancelDrop = 1;
                    return VSConstants.S_OK;
            }

            // Save all dirty documents
            foreach (var node in ItemsDraggedOrCutOrCopied)
            {
                var manager = node.GetDocumentManager();
                if (manager != null)
                {
                    manager.Save(true);
                }
            }

            return VSConstants.S_OK;
        }
Example #17
0
        /// <summary>
        ///     Called as soon as the mouse drags an item over a new hierarchy or hierarchy window
        /// </summary>
        /// <param name="pDataObject">reference to interface IDataObject of the item being dragged</param>
        /// <param name="grfKeyState">
        ///     Current state of the keyboard and the mouse modifier keys. See docs for a list of possible
        ///     values
        /// </param>
        /// <param name="itemid">Item identifier for the item currently being dragged</param>
        /// <param name="pdwEffect">On entry, a pointer to the current DropEffect. On return, must contain the new valid DropEffect</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int DragEnter(IOleDataObject pDataObject, uint grfKeyState, uint itemid, ref uint pdwEffect)
        {
            pdwEffect = (uint) DropEffect.None;

            if (SourceDraggedOrCutOrCopied)
            {
                return VSConstants.S_OK;
            }

            dropDataType = QueryDropDataType(pDataObject);
            if (dropDataType != DropDataType.None)
            {
                pdwEffect = (uint) QueryDropEffect(dropDataType, grfKeyState);
            }

            return VSConstants.S_OK;
        }
Example #18
0
 public int GetSelectionDataObject(out Microsoft.VisualStudio.OLE.Interop.IDataObject ppIDataObject)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Example #19
0
        /// <summary>
        ///     Returns information about one or more of the items being dragged
        /// </summary>
        /// <param name="pdwOKEffects">
        ///     Pointer to a DWORD value describing the effects displayed while the item is being dragged,
        ///     such as cursor icons that change during the drag-and-drop operation.
        ///     For example, if the item is dragged over an invalid target point
        ///     (such as the item's original location), the cursor icon changes to a circle with a line through it.
        ///     Similarly, if the item is dragged over a valid target point, the cursor icon changes to a file or folder.
        /// </param>
        /// <param name="ppDataObject">
        ///     Pointer to the IDataObject interface on the item being dragged.
        ///     This data object contains the data being transferred in the drag-and-drop operation.
        ///     If the drop occurs, then this data object (item) is incorporated into the target hierarchy or hierarchy window.
        /// </param>
        /// <param name="ppDropSource">Pointer to the IDropSource interface of the item being dragged.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        public override int GetDropInfo(out uint pdwOKEffects, out IOleDataObject ppDataObject,
            out IDropSource ppDropSource)
        {
            //init out params
            pdwOKEffects = (uint) DropEffect.None;
            ppDataObject = null;
            ppDropSource = null;

            IOleDataObject dataObject = PackageSelectionDataObject(false);
            if (dataObject == null)
            {
                return VSConstants.E_NOTIMPL;
            }

            SourceDraggedOrCutOrCopied = true;

            pdwOKEffects = (uint) (DropEffect.Move | DropEffect.Copy);

            ppDataObject = dataObject;
            return VSConstants.S_OK;
        }
 public static extern int OleSetClipboard(Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject);
Example #21
0
 /*internal, but public for FSharp.Project.dll*/ public static extern int OleGetClipboard(out Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject);
        /// <summary>
        /// Process data object from Drag/Drop/Cut/Copy/Paste operation
        /// </summary>
        /// <remarks>The targetNode is set if the method is called from a drop operation, otherwise it
        /// is null</remarks>
        private DropDataType HandleSelectionDataObject(IOleDataObject dataObject, HierarchyNode targetNode)
        {
            DropDataType dropDataType = DropDataType.None;
            bool isWindowsFormat = false;

            if(targetNode == null)
                targetNode = this;

            // Try to get it as a directory based project
            List<string> filesDropped = DragDropHelper.GetDroppedFiles(DragDropHelper.CF_VSSTGPROJECTITEMS,
                dataObject, out dropDataType);

            if(filesDropped.Count == 0)
                filesDropped = DragDropHelper.GetDroppedFiles(DragDropHelper.CF_VSREFPROJECTITEMS, dataObject,
                    out dropDataType);

            if(filesDropped.Count == 0)
            {
                filesDropped = DragDropHelper.GetDroppedFiles(NativeMethods.CF_HDROP, dataObject, out dropDataType);
                isWindowsFormat = (filesDropped.Count > 0);
            }

            // Handle documentation sources and references first.  These will be removed from the list before
            // passing on what's left to add as standard project files.
            if(isWindowsFormat && filesDropped.Count != 0)
            {
                List<string> docSources = filesDropped.Where(f =>
                        {
                            string ext = Path.GetExtension(f);

                            return (ext.Equals(".sln", StringComparison.OrdinalIgnoreCase) ||
                              ext.EndsWith("proj", StringComparison.OrdinalIgnoreCase));
                        }).ToList(),
                    refSources = filesDropped.Where(f =>
                        {
                            string ext = Path.GetExtension(f);

                            return (ext.Equals(".dll", StringComparison.OrdinalIgnoreCase) ||
                              ext.Equals(".exe", StringComparison.OrdinalIgnoreCase) ||
                              ext.Equals(".winmd", StringComparison.OrdinalIgnoreCase));
                        }).ToList(),
                    xmlDocSources = filesDropped.Where(f =>
                        {
                            string file = Path.GetFileNameWithoutExtension(f), ext = Path.GetExtension(f);

                            // We only want XML files with a base name that matches an assembly in the list
                            return (ext.Equals(".xml", StringComparison.OrdinalIgnoreCase) &&
                              refSources.Any(r => Path.GetFileNameWithoutExtension(r).Equals(file,
                                  StringComparison.OrdinalIgnoreCase)));
                        }).ToList(),
                    allDocSources = docSources.Concat(refSources).Concat(xmlDocSources).ToList();

                var docSourcesNode = targetNode as DocumentationSourcesContainerNode;

                // If dropped on the Documentation Sources node, add all documentation sources
                if(docSourcesNode != null)
                {
                    foreach(string f in allDocSources)
                    {
                        if(!f.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
                            docSourcesNode.AddDocumentationSource(f);
                        else
                            foreach(string project in SandcastleBuilder.Utils.MSBuild.SelectProjectsDlg.SelectSolutionOrProjects(f))
                                docSourcesNode.AddDocumentationSource(project);
                    }
                }
                else
                {
                    var refsNode = targetNode as SandcastleBuilderReferenceContainerNode;

                    // If dropped on the references node, add all reference files
                    if(refsNode != null)
                        foreach(string f in refSources)
                        {
                            var node = refsNode.AddReferenceFromSelectorData(new VSCOMPONENTSELECTORDATA
                                {
                                    type = VSCOMPONENTTYPE.VSCOMPONENTTYPE_File,
                                    bstrFile = f
                                }, null);

                            // Clear the Name and AseemblyName metadata and set the HintPath metadata so that it
                            // treats it correctly when the project is reloaded
                            if(node != null)
                            {
                                string hintPath = f;

                                if(Path.IsPathRooted(hintPath))
                                    hintPath = PackageUtilities.GetPathDistance(this.ProjectMgr.BaseURI.Uri,
                                        new Uri(hintPath));

                                node.ItemNode.SetMetadata(ProjectFileConstants.Name, null);
                                node.ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, null);
                                node.ItemNode.SetMetadata(ProjectFileConstants.HintPath, hintPath);
                            }
                        }
                }

                // Remove the documentation source and reference files from the list
                filesDropped = filesDropped.Except(allDocSources).ToList();
            }

            // Handle all other file types
            if(dropDataType != DropDataType.None && filesDropped.Count > 0)
            {
                string[] filesDroppedAsArray = filesDropped.ToArray();

                // For directory based projects the content of the clipboard is a double-NULL terminated list of
                // Projref strings.
                if(isWindowsFormat)
                {
                    // This is the code path when source is Windows Explorer
                    VSADDRESULT[] vsaddresults = new VSADDRESULT[1];
                    vsaddresults[0] = VSADDRESULT.ADDRESULT_Failure;

                    int addResult = this.AddItem(targetNode.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, null,
                        (uint)filesDropped.Count, filesDroppedAsArray, IntPtr.Zero, vsaddresults);

                    if(addResult != VSConstants.S_OK && addResult != VSConstants.S_FALSE &&
                      addResult != (int)OleConstants.OLECMDERR_E_CANCELED &&
                      vsaddresults[0] != VSADDRESULT.ADDRESULT_Success)
                        ErrorHandler.ThrowOnFailure(addResult);

                    return dropDataType;
                }
                else
                    if(AddFilesFromProjectReferences(targetNode, filesDroppedAsArray))
                        return dropDataType;
            }

            // If we reached this point then the drop data must be set to None.  Otherwise the OnPaste will be
            // called with a valid DropData and that would actually delete the item.
            return DropDataType.None;
        }
        /// <summary>
        /// This is overridden to handle drop operations correctly in a help file builder project
        /// </summary>
        /// <inheritdoc />
        public override int Drop(IOleDataObject pDataObject, uint grfKeyState, uint itemid, ref uint pdwEffect)
        {
            DropDataType dropDataType = DropDataType.None;

            if(pDataObject == null)
                return VSConstants.E_INVALIDARG;

            pdwEffect = (uint)DropEffect.None;

            // If the source is within the project, let the base class handle it
            if(this.SourceDraggedOrCutOrCopied)
                return base.Drop(pDataObject, grfKeyState, itemid, ref pdwEffect);

            // Get the node that is being dragged over and ask it which node should handle this call
            HierarchyNode targetNode = NodeFromItemId(itemid);

            if(targetNode == null)
                return VSConstants.S_FALSE;

            targetNode = targetNode.GetDragTargetHandlerNode();

            dropDataType = this.HandleSelectionDataObject(pDataObject, targetNode);

            // Since we can get a mix of files that may not necessarily be moved into the project (i.e.
            // documentation sources and references), we'll always act as if they were copied.
            pdwEffect = (uint)DropEffect.Copy;

            return (dropDataType != DropDataType.Shell) ? VSConstants.E_FAIL : VSConstants.S_OK;
        }
Example #24
0
 /// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject]/*' />
 public OleDataObject()
 {
     oleData = (IOleDataObject)(new Ole2BclDataObject(this as IComDataObject));
 }
Example #25
0
 public int FilterDataObject(Microsoft.VisualStudio.OLE.Interop.IDataObject pDataObjIn, out Microsoft.VisualStudio.OLE.Interop.IDataObject ppDataObjOut)
 {
     ppDataObjOut = null;
     return(VSErr.S_OK);
 }
Example #26
0
 /// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject3]/*' />
 public OleDataObject(IOleDataObject oleData)
     : base((oleData is IComDataObject) ? (IComDataObject)oleData : (IComDataObject)(new Ole2BclDataObject(oleData)))
 {
     this.oleData = oleData;
 }
Example #27
0
 /// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject3]/*' />
 public OleDataObject(IOleDataObject oleData) :
     base((oleData is IComDataObject) ? (IComDataObject)oleData : (IComDataObject)(new Ole2BclDataObject(oleData)))
 {
     this.oleData = oleData;
 }
Example #28
0
 int IVsTextView.GetSelectionDataObject(out Microsoft.VisualStudio.OLE.Interop.IDataObject ppIDataObject)
 {
     throw new System.NotImplementedException();
 }
        /// <summary>
        /// Process data object from Drag/Drop/Cut/Copy/Paste operation
        /// </summary>
        /// <remarks>The targetNode is set if the method is called from a drop operation, otherwise it
        /// is null</remarks>
        private DropDataType HandleSelectionDataObject(IOleDataObject dataObject, HierarchyNode targetNode)
        {
            DropDataType dropDataType    = DropDataType.None;
            bool         isWindowsFormat = false;

            if (targetNode == null)
            {
                targetNode = this;
            }

            // Try to get it as a directory based project
            List <string> filesDropped = DragDropHelper.GetDroppedFiles(DragDropHelper.CF_VSSTGPROJECTITEMS,
                                                                        dataObject, out dropDataType);

            if (filesDropped.Count == 0)
            {
                filesDropped = DragDropHelper.GetDroppedFiles(DragDropHelper.CF_VSREFPROJECTITEMS, dataObject,
                                                              out dropDataType);
            }

            if (filesDropped.Count == 0)
            {
                filesDropped    = DragDropHelper.GetDroppedFiles(NativeMethods.CF_HDROP, dataObject, out dropDataType);
                isWindowsFormat = (filesDropped.Count > 0);
            }

            // Handle documentation sources and references first.  These will be removed from the list before
            // passing on what's left to add as standard project files.
            if (isWindowsFormat && filesDropped.Count != 0)
            {
                List <string> docSources = filesDropped.Where(f =>
                {
                    string ext = Path.GetExtension(f);

                    return(ext.Equals(".sln", StringComparison.OrdinalIgnoreCase) ||
                           ext.EndsWith("proj", StringComparison.OrdinalIgnoreCase));
                }).ToList(),
                refSources = filesDropped.Where(f =>
                {
                    string ext = Path.GetExtension(f);

                    return(ext.Equals(".dll", StringComparison.OrdinalIgnoreCase) ||
                           ext.Equals(".exe", StringComparison.OrdinalIgnoreCase) ||
                           ext.Equals(".winmd", StringComparison.OrdinalIgnoreCase));
                }).ToList(),
                xmlDocSources = filesDropped.Where(f =>
                {
                    string file = Path.GetFileNameWithoutExtension(f), ext = Path.GetExtension(f);

                    // We only want XML files with a base name that matches an assembly in the list
                    return(ext.Equals(".xml", StringComparison.OrdinalIgnoreCase) &&
                           refSources.Any(r => Path.GetFileNameWithoutExtension(r).Equals(file,
                                                                                          StringComparison.OrdinalIgnoreCase)));
                }).ToList(),
                allDocSources = docSources.Concat(refSources).Concat(xmlDocSources).ToList();

                var docSourcesNode = targetNode as DocumentationSourcesContainerNode;

                // If dropped on the Documentation Sources node, add all documentation sources
                if (docSourcesNode != null)
                {
                    foreach (string f in allDocSources)
                    {
                        if (!f.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
                        {
                            docSourcesNode.AddDocumentationSource(f);
                        }
                        else
                        {
                            foreach (string project in SandcastleBuilder.Utils.MSBuild.SelectProjectsDlg.SelectSolutionOrProjects(f))
                            {
                                docSourcesNode.AddDocumentationSource(project);
                            }
                        }
                    }
                }
                else
                {
                    var refsNode = targetNode as SandcastleBuilderReferenceContainerNode;

                    // If dropped on the references node, add all reference files
                    if (refsNode != null)
                    {
                        foreach (string f in refSources)
                        {
                            var node = refsNode.AddReferenceFromSelectorData(new VSCOMPONENTSELECTORDATA
                            {
                                type     = VSCOMPONENTTYPE.VSCOMPONENTTYPE_File,
                                bstrFile = f
                            }, null);

                            // Clear the Name and AseemblyName metadata and set the HintPath metadata so that it
                            // treats it correctly when the project is reloaded
                            if (node != null)
                            {
                                string hintPath = f;

                                if (Path.IsPathRooted(hintPath))
                                {
                                    hintPath = PackageUtilities.GetPathDistance(this.ProjectMgr.BaseURI.Uri,
                                                                                new Uri(hintPath));
                                }

                                node.ItemNode.SetMetadata(ProjectFileConstants.Name, null);
                                node.ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, null);
                                node.ItemNode.SetMetadata(ProjectFileConstants.HintPath, hintPath);
                            }
                        }
                    }
                }

                // Remove the documentation source and reference files from the list
                filesDropped = filesDropped.Except(allDocSources).ToList();
            }

            // Handle all other file types
            if (dropDataType != DropDataType.None && filesDropped.Count > 0)
            {
                string[] filesDroppedAsArray = filesDropped.ToArray();

                // For directory based projects the content of the clipboard is a double-NULL terminated list of
                // Projref strings.
                if (isWindowsFormat)
                {
                    // This is the code path when source is Windows Explorer
                    VSADDRESULT[] vsaddresults = new VSADDRESULT[1];
                    vsaddresults[0] = VSADDRESULT.ADDRESULT_Failure;

                    int addResult = this.AddItem(targetNode.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, null,
                                                 (uint)filesDropped.Count, filesDroppedAsArray, IntPtr.Zero, vsaddresults);

                    if (addResult != VSConstants.S_OK && addResult != VSConstants.S_FALSE &&
                        addResult != (int)OleConstants.OLECMDERR_E_CANCELED &&
                        vsaddresults[0] != VSADDRESULT.ADDRESULT_Success)
                    {
                        ErrorHandler.ThrowOnFailure(addResult);
                    }

                    return(dropDataType);
                }
                else
                if (AddFilesFromProjectReferences(targetNode, filesDroppedAsArray))
                {
                    return(dropDataType);
                }
            }

            // If we reached this point then the drop data must be set to None.  Otherwise the OnPaste will be
            // called with a valid DropData and that would actually delete the item.
            return(DropDataType.None);
        }
Example #30
0
        /// <summary>
        ///     Called when one or more items are dropped into the target hierarchy or hierarchy window when the mouse button is
        ///     released.
        /// </summary>
        /// <param name="pDataObject">
        ///     Reference to the IDataObject interface on the item being dragged. This data object contains the data being
        ///     transferred in the drag-and-drop operation.
        ///     If the drop occurs, then this data object (item) is incorporated into the target hierarchy or hierarchy window.
        /// </param>
        /// <param name="grfKeyState">
        ///     Current state of the keyboard and the mouse modifier keys. See
        ///     <seealso cref="IVsHierarchyDropDataTarget" />
        /// </param>
        /// <param name="itemid">Item identifier of the drop data target over which the item is being dragged</param>
        /// <param name="pdwEffect">
        ///     Visual effects associated with the drag-and drop-operation, such as a cursor, bitmap, and so on.
        ///     The value of dwEffects passed to the source object via the OnDropNotify method is the value of pdwEffects returned
        ///     by the Drop method
        /// </param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
        public override int Drop(IOleDataObject pDataObject, uint grfKeyState, uint itemid, ref uint pdwEffect)
        {
            if (pDataObject == null)
            {
                return VSConstants.E_INVALIDARG;
            }

            pdwEffect = (uint) DropEffect.None;

            // Get the node that is being dragged over and ask it which node should handle this call
            var targetNode = NodeFromItemId(itemid);
            if (targetNode != null)
            {
                targetNode = targetNode.GetDragTargetHandlerNode();
            }
            else
            {
                // There is no target node. The drop can not be completed.
                return VSConstants.S_FALSE;
            }

            int returnValue;
            try
            {
                var dropDataType = DropDataType.None;
                dropDataType = ProcessSelectionDataObject(pDataObject, targetNode);
                pdwEffect = (uint) QueryDropEffect(dropDataType, grfKeyState);

                // If it is a drop from windows and we get any kind of error we return S_FALSE and dropeffect none. This
                // prevents bogus messages from the shell from being displayed
                returnValue = dropDataType != DropDataType.Shell ? VSConstants.E_FAIL : VSConstants.S_OK;
            }
            catch (FileNotFoundException e)
            {
                Trace.WriteLine("Exception : " + e.Message);

                if (!Utilities.IsInAutomationFunction(Site))
                {
                    var message = e.Message;
                    var title = string.Empty;
                    var icon = OLEMSGICON.OLEMSGICON_CRITICAL;
                    var buttons = OLEMSGBUTTON.OLEMSGBUTTON_OK;
                    var defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                    VsShellUtilities.ShowMessageBox(Site, title, message, icon, buttons, defaultButton);
                }

                returnValue = VSConstants.E_FAIL;
            }

            return returnValue;
        }
Example #31
0
 internal static extern int OleGetClipboard(out Microsoft.VisualStudio.OLE.Interop.IDataObject dataObject);
Example #32
0
        public void Drop(IOleDataObject pDataObj, uint grfKeyState, IOlePoint pt, ref uint pdwEffect)
        {
            if (m_CurrentObject == pDataObj)
            {
                try
                {
                    var outlook   = new Application();
                    var selection = outlook.ActiveExplorer().Selection;

                    if ((selection != null) && (selection.Count >= 1))
                    {
                        var title = "";
                        var id    = "";

                        var item = selection[1];

                        if (item is MailItem)
                        {
                            title = (item as MailItem).Subject;
                            id    = (item as MailItem).EntryID;
                        }
                        else if (item is ContactItem)
                        {
                            title = (item as ContactItem).Subject;
                            id    = (item as ContactItem).EntryID;
                        }
                        else if (item is JournalItem)
                        {
                            title = (item as JournalItem).Subject;
                            id    = (item as JournalItem).EntryID;
                        }
                        else if (item is TaskItem)
                        {
                            title = (item as TaskItem).Subject;
                            id    = (item as TaskItem).EntryID;
                        }
                        else if (item is NoteItem)
                        {
                            title = (item as NoteItem).Subject;
                            id    = (item as NoteItem).EntryID;
                        }
                        else if (item is AppointmentItem)
                        {
                            title = (item as AppointmentItem).Subject;
                            id    = (item as AppointmentItem).EntryID;
                        }

                        if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(id))
                        {
                            var url = OutlookUtil.FormatItemAsUrl(id);
                            OutlookDrop(this, title, url);

                            pdwEffect = DragDropUtil.DRAGDROP_LINK;
                        }
                    }
                }
                catch (System.Exception /*e*/)
                {
                    pdwEffect = DragDropUtil.DRAGDROP_NONE;
                }
            }
            else if (m_DefaultDropTarget != null)
            {
                m_DefaultDropTarget.Drop(pDataObj, grfKeyState, pt, pdwEffect);

                if (pdwEffect != DragDropUtil.DRAGDROP_NONE)
                {
                    pdwEffect = DragDropUtil.DRAGDROP_LINK;
                }
            }

            m_CurrentObject = null;
        }
        /// <summary>
        /// 检查工具箱栏目是否存在.
        /// </summary>
        bool VerifyToolboxItemExist()
        {
            LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
             string.Format("Entering VerifyToolboxItemExist for: {0}", this.ToString()));

            bool exist = false;
            IEnumToolboxItems items;
            uint num;
            ErrorHandler.ThrowOnFailure(vsToolbox2.EnumItems(toolboxTabString, out items));
            var rgelt = new Microsoft.VisualStudio.OLE.Interop.IDataObject[1];
            for (int i = items.Next(1, rgelt, out num);
                (ErrorHandler.Succeeded(i) && (num > 0)) && (rgelt[0] != null);
                i = items.Next(1, rgelt, out num))
            {
                string displayName;
                var hr = (vsToolbox2 as IVsToolbox3).GetItemDisplayName(rgelt[0], out displayName);
                ErrorHandler.ThrowOnFailure(hr);

                if (displayName.Equals(toolboxItemString, StringComparison.OrdinalIgnoreCase))
                {
                    exist = true;
                    break;
                }
            }

            LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
            string.Format("VerifyToolboxItemExist {0}: {1}", toolboxItemString, exist));

            return exist;
        }
Example #34
0
 /// <include file='doc\OleDataObject.uex' path='docs/doc[@for=OleDataObject.OleDataObject]/*' />
 public OleDataObject()
 {
     oleData = (IOleDataObject)(new Ole2BclDataObject(this as IComDataObject));
 }