当前位置: 首页>>代码示例>>C#>>正文


C# HierarchyNode.GetDragTargetHandlerNode方法代码示例

本文整理汇总了C#中HierarchyNode.GetDragTargetHandlerNode方法的典型用法代码示例。如果您正苦于以下问题:C# HierarchyNode.GetDragTargetHandlerNode方法的具体用法?C# HierarchyNode.GetDragTargetHandlerNode怎么用?C# HierarchyNode.GetDragTargetHandlerNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HierarchyNode的用法示例。


在下文中一共展示了HierarchyNode.GetDragTargetHandlerNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DropFilesOrFolders

        internal void DropFilesOrFolders(string[] filesDropped, HierarchyNode ontoNode) {
            var waitDialog = (IVsThreadedWaitDialog)Site.GetService(typeof(SVsThreadedWaitDialog));
            int waitResult = waitDialog.StartWaitDialog(
                "Adding files and folders...",
                "Adding files to your project, this may take several seconds...",
                null,
                0,
                null,
                null
            );
            try {
                ontoNode = ontoNode.GetDragTargetHandlerNode();
                string nodePath = ontoNode.FullPathToChildren;
                bool droppingExistingDirectory = true;
                foreach (var droppedFile in filesDropped) {
                    if (!Directory.Exists(droppedFile) ||
                        !String.Equals(Path.GetDirectoryName(droppedFile), nodePath, StringComparison.OrdinalIgnoreCase)) {
                        droppingExistingDirectory = false;
                        break;
                    }
                }

                if (droppingExistingDirectory) {
                    // we're dragging a directory/directories that already exist
                    // into the location where they exist, we can do this via a fast path,
                    // and pop up a nice progress bar.
                    AddExistingDirectories(ontoNode, filesDropped);
                } else {
                    foreach (var droppedFile in filesDropped) {
                        if (Directory.Exists(droppedFile) &&
                            CommonUtils.IsSubpathOf(droppedFile, nodePath)) {
                            int cancelled = 0;
                            waitDialog.EndWaitDialog(ref cancelled);
                            waitResult = VSConstants.E_FAIL; // don't end twice

                            Utilities.ShowMessageBox(
                                Site,
                                SR.GetString(SR.CannotAddFolderAsDescendantOfSelf, CommonUtils.GetFileOrDirectoryName(droppedFile)),
                                null,
                                OLEMSGICON.OLEMSGICON_CRITICAL,
                                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                            return;
                        }
                    }

                    // This is the code path when source is windows explorer
                    VSADDRESULT[] vsaddresults = new VSADDRESULT[1];
                    vsaddresults[0] = VSADDRESULT.ADDRESULT_Failure;
                    int addResult = AddItem(ontoNode.ID, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, null, (uint)filesDropped.Length, filesDropped, 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);
                    }
                }
            } finally {
                if (ErrorHandler.Succeeded(waitResult)) {
                    int cancelled = 0;
                    waitDialog.EndWaitDialog(ref cancelled);
                }
            }
        }
开发者ID:CforED,项目名称:Node.js-Tools-for-Visual-Studio,代码行数:63,代码来源:ProjectNode.CopyPaste.cs

示例2: PasteFromClipboard

        /// <summary>
        /// Handle the Paste operation to a targetNode
        /// </summary>
        public override int PasteFromClipboard(HierarchyNode targetNode)
        {
            int returnValue = (int)OleConstants.OLECMDERR_E_NOTSUPPORTED;

            //Get the clipboardhelper service and use it after processing dataobject
            IVsUIHierWinClipboardHelper clipboardHelper = (IVsUIHierWinClipboardHelper)GetService(typeof(SVsUIHierWinClipboardHelper));
            if (clipboardHelper == null)
            {
                return VSConstants.E_FAIL;
            }

            try
            {
                //Get dataobject from clipboard
                IOleDataObject dataObject = null;
                ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleGetClipboard(out dataObject));
                if (dataObject == null)
                {
                    return VSConstants.E_UNEXPECTED;
                }

                DropEffect dropEffect = DropEffect.None;
                DropDataType dropDataType = DropDataType.None;
                try
                {
                    dropDataType = this.ProcessSelectionDataObject(dataObject, targetNode.GetDragTargetHandlerNode());
                    dropEffect = this.QueryDropEffect(dropDataType, 0);
                }
                catch (ExternalException e)
                {
                    Trace.WriteLine("Exception : " + e.Message);

                    // If it is a drop from windows and we get any kind of error ignore it. This
                    // prevents bogus messages from the shell from being displayed
                    if (dropDataType != DropDataType.Shell)
                    {
                        throw;
                    }
                }
                finally
                {
                    // Inform VS (UiHierarchyWindow) of the paste
                    returnValue = clipboardHelper.Paste(dataObject, (uint)dropEffect);
                }
            }
            catch (COMException e)
            {
                Trace.WriteLine("Exception : " + e.Message);

                returnValue = e.ErrorCode;
            }

            return returnValue;
        }
开发者ID:CaptainHayashi,项目名称:visualfsharp,代码行数:57,代码来源:ProjectNode.CopyPaste.cs

示例3: AddFolderFromOtherProject

        /// <summary>
        /// This is used to recursively add a folder from an other project.
        /// Note that while we copy the folder content completely, we only
        /// add to the project items which are part of the source project.
        /// </summary>
        /// <param name="folderToAdd">Project reference (from data object) using the format: {Guid}|project|folderPath</param>
        /// <param name="targetNode">Node to add the new folder to</param>
        protected internal virtual bool AddFolderFromOtherProject(string folderToAdd, HierarchyNode targetNode, bool drop)
        {
            Utilities.ArgumentNotNullOrEmpty(folderToAdd, "folderToAdd");
            Utilities.ArgumentNotNull("targetNode", targetNode);

            var targetFolderNode = targetNode.GetDragTargetHandlerNode();

            // Split the reference in its 3 parts
            int index1 = Guid.Empty.ToString("B").Length;
            if (index1 + 1 >= folderToAdd.Length)
                throw new ArgumentOutOfRangeException("folderToAdd");

            // Get the Guid
            string guidString = folderToAdd.Substring(1, index1 - 2);
            Guid projectInstanceGuid = new Guid(guidString);

            // Get the project path
            int index2 = folderToAdd.IndexOf('|', index1 + 1);
            if (index2 < 0 || index2 + 1 >= folderToAdd.Length)
                throw new ArgumentOutOfRangeException("folderToAdd");

            // Finally get the source path
            string folder = folderToAdd.Substring(index2 + 1);

            // Get the target path
            string folderName = Path.GetFileName(Path.GetDirectoryName(folder));
            string targetPath = Path.Combine(GetBaseDirectoryForAddingFiles(targetFolderNode), folderName);

            // Retrieve the project from which the items are being copied
            IVsHierarchy sourceHierarchy;
            IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution));
            ErrorHandler.ThrowOnFailure(solution.GetProjectOfGuid(ref projectInstanceGuid, out sourceHierarchy));

            // Then retrieve the item ID of the item to copy
            uint itemID = VSConstants.VSITEMID_ROOT;
            ErrorHandler.ThrowOnFailure(sourceHierarchy.ParseCanonicalName(folder, out itemID));

            string name = folderName;
            // Ensure we don't end up in an endless recursion
            if (Utilities.IsSameComObject(this, sourceHierarchy))
            {
                // copy file onto its self, we should make a copy of the folder
                if (String.Equals(folder, targetNode.GetMkDocument(), StringComparison.OrdinalIgnoreCase))
                {
                    if (drop)
                    {
                        // cancelled drag and drop
                        return false;
                    }
                    string newDir;
                    string baseName = folder;
                    folder = CommonUtils.TrimEndSeparator(folder);
                    int copyCount = 0;
                    do
                    {
                        name = folderName + " - Copy";
                        if (copyCount != 0)
                        {
                            name += " (" + copyCount + ")";
                        }
                        copyCount++;
                        newDir = Path.Combine(Path.GetDirectoryName(folder), name);
                    } while (Directory.Exists(newDir));

                    targetPath = newDir;
                    targetFolderNode = targetNode.Parent;
                }
                else
                {
                    HierarchyNode cursorNode = targetFolderNode;
                    while (cursorNode != null)
                    {
                        if (String.Equals(folder, cursorNode.GetMkDocument(), StringComparison.OrdinalIgnoreCase))
                        {
                            throw new InvalidOperationException(String.Format("Cannot copy '{0}'. The destination folder is a subfolder of the source folder.", folderName));
                        }
                        cursorNode = cursorNode.Parent;
                    }
                }
            }

            // Recursively copy the directory to the new location
            Utilities.RecursivelyCopyDirectory(folder, targetPath);

            // Now walk the source project hierarchy to see which node needs to be added.
            WalkSourceProjectAndAdd(sourceHierarchy, itemID, targetFolderNode, false, name);

            return true;
        }
开发者ID:borota,项目名称:JTVS,代码行数:96,代码来源:ProjectNode.CopyPaste.cs


注:本文中的HierarchyNode.GetDragTargetHandlerNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。