private OleGetClipboard ( Microsoft &dataObject ) : int | ||
dataObject | Microsoft | |
리턴 | int |
/// <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> /// Empties all the data structures added to the clipboard and flushes the clipboard. /// </summary> private void CleanAndFlushClipboard() { IOleDataObject oleDataObject = null; ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleGetClipboard(out oleDataObject)); if (oleDataObject == null) { return; } string sourceProjectPath = DragDropHelper.GetSourceProjectPath(oleDataObject); if (!String.IsNullOrEmpty(sourceProjectPath) && NativeMethods.IsSamePath(sourceProjectPath, this.GetMkDocument())) { ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.OleFlushClipboard()); int clipboardOpened = 0; try { ErrorHandler.ThrowOnFailure(clipboardOpened = UnsafeNativeMethods.OpenClipboard(IntPtr.Zero)); ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.EmptyClipboard()); } finally { if (clipboardOpened == 1) { ErrorHandler.ThrowOnFailure(UnsafeNativeMethods.CloseClipboard()); } } } }
/// <summary> /// Handle the Paste operation to a targetNode /// </summary> protected internal 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); }