/// <summary> /// 添加工具箱栏目. /// </summary> void AddToolboxItem() { LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, string.Format("Entering AddToolboxItem for: {0}", toolboxItemString)); var toolboxData = new Microsoft.VisualStudio.Shell.OleDataObject(); tooltipStream = FormatTooltipData(toolboxTooltipString, toolboxDescriptionString); // 设置提示信息. toolboxData.SetData("VSToolboxTipInfo", tooltipStream); // 设置拖放文本. toolboxData.SetData(DataFormats.Text, toolboxItemTextString); TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; itemInfo[0].bstrText = toolboxItemString; itemInfo[0].hBmp = IntPtr.Zero; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; ErrorHandler.ThrowOnFailure( vsToolbox2.AddItem(toolboxData, itemInfo, toolboxTabString)); }
/// <summary> /// 添加工具箱栏目. /// </summary> void AddToolboxItem() { LogEntry(__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, string.Format("Entering AddToolboxItem for: {0}", toolboxItemString)); var toolboxData = new Microsoft.VisualStudio.Shell.OleDataObject(); tooltipStream = FormatTooltipData(toolboxTooltipString, toolboxDescriptionString); // 设置提示信息. toolboxData.SetData("VSToolboxTipInfo", tooltipStream); // 设置拖放文本. toolboxData.SetData(DataFormats.Text, toolboxItemTextString); TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; itemInfo[0].bstrText = toolboxItemString; itemInfo[0].hBmp = IntPtr.Zero; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; ErrorHandler.ThrowOnFailure( vsToolbox2.AddItem(toolboxData, itemInfo, toolboxTabString)); }
/// <summary> /// This method is called when the pane is sited with a non null service provider. /// Here is where you can do all the initialization that requare access to /// services provided by the shell. /// </summary> protected override void Initialize() { // If toolboxData have initialized, skip creating a new one. if (toolboxData == null) { // Create the data object that will store the data for the menu item. toolboxData = new OleDataObject(); toolboxData.SetData(typeof(ToolboxItemData), new ToolboxItemData("Test string")); // Get the toolbox service IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox)); // Create the array of TBXITEMINFO structures to describe the items // we are adding to the toolbox. TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; itemInfo[0].bstrText = "Toolbox Sample Item"; itemInfo[0].hBmp = IntPtr.Zero; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; ErrorHandler.ThrowOnFailure(toolbox.AddItem((IOleDataObject)toolboxData, itemInfo, "Toolbox Test")); } }
/// <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(ToolboxItemData))) { Debug.WriteLine("MyToolboxItemData selected from the toolbox"); ToolboxItemData myData = (ToolboxItemData)oleData.GetData(typeof(ToolboxItemData)); editorControl.Text += myData.Content; } return VSConstants.S_OK; }
/// <summary> /// Determines whether the Toolbox user supports the referenced data object. /// </summary> /// <param name="pDO">Data object to be supported.</param> /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns> int IVsToolboxUser.IsSupported(IOleDataObject pDO) { // Create a OleDataObject from the input interface. OleDataObject oleData = new OleDataObject(pDO); // Check if the data object is of type MyToolboxData. if (oleData.GetDataPresent(typeof(ToolboxItemData))) return VSConstants.S_OK; // In all the other cases return S_FALSE return VSConstants.S_FALSE; }
public int ItemPicked(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO) { // Create a OleDataObject from the input interface. OleDataObject oleData = new OleDataObject(pDO); // Check if the picked item is the one we can paste. if (oleData.GetDataPresent(DataFormats.UnicodeText)) { throw new NotImplementedException();//huqf //object o = null; //_editorControl.TextSelection.Paste(ref o, 0); } return VSConstants.S_OK; }
public int IsSupported(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO) { // Create a OleDataObject from the input interface. OleDataObject oleData = new OleDataObject(pDO); // && editorControl.RichTextBoxControl.CanPaste(DataFormats.GetFormat(DataFormats.UnicodeText)) // Check if the data object is of type UnicodeText. if (oleData.GetDataPresent(DataFormats.UnicodeText)) { return VSConstants.S_OK; } // In all the other cases return S_FALSE return VSConstants.S_FALSE; }
public virtual void DoDragDrop(OleDataObject dataObject, uint grfKeyState, uint pdwEffect) { }
/// <summary> /// Perform a Drag and Drop operation on this node. /// </summary> protected virtual void DoDragDrop(OleDataObject dataObject, uint keyState, uint effect) { }
int IVsSimpleObjectList2.DoDragDrop(uint index, IDataObject pDataObject, uint grfKeyState, ref uint pdwEffect) { if (index >= (uint)children.Count) { throw new ArgumentOutOfRangeException("index"); } OleDataObject dataObject = new OleDataObject(pDataObject); children[(int)index].DoDragDrop(dataObject, grfKeyState, pdwEffect); return VSConstants.S_OK; }
/// <summary> /// The item picked. /// </summary> /// <param name="pDO"> /// The p do. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int ItemPicked(IDataObject pDO) { // Create a OleDataObject from the input interface. var oleData = new OleDataObject(pDO); // Check if the picked item is the one we can paste. if (oleData.GetDataPresent(DataFormats.UnicodeText)) { object o = null; this.EditorControl.TextSelection.Paste(ref o, 0); } return VSConstants.S_OK; }
public int ItemPicked(Microsoft.VisualStudio.OLE.Interop.IDataObject pDO) { // Create a OleDataObject from the input interface. OleDataObject oleData = new OleDataObject(pDO); // Check if the picked item is the one we can paste. if (oleData.GetDataPresent(DataFormats.UnicodeText)) { object o = null; } return VSConstants.S_OK; }
/// <include file='doc\Package.uex' path='docs/doc[@for="Package.IVsToolboxItemProvider.GetItemContent"]/*' /> /// <devdoc> /// IVsToolboxItemProvider implementation. /// Called by the shell to retrieve the content of a data format in a toolbox item that /// was statically registered. See comments in vsshell100.idl for details. /// </devdoc> int IVsToolboxItemProvider.GetItemContent(string itemId, /* CLIPFORMAT */ ushort format, out /* HGLOBAL */ IntPtr global) { if (zombie) Marshal.ThrowExceptionForHR(NativeMethods.E_UNEXPECTED); object data = GetToolboxItemData(itemId, DataFormats.GetFormat(format)); if (data == null) { global = IntPtr.Zero; } else { // OleDataObject has a nice facility for serializing objects into hglobals, so // let's take advantage of it. var dataObj = new OleDataObject(); dataObj.SetData(DataFormats.GetFormat(format).Name, data); FORMATETC[] fetc = new FORMATETC[] { new FORMATETC() }; fetc[0].cfFormat = format; fetc[0].dwAspect = (uint)DVASPECT.DVASPECT_CONTENT; fetc[0].lindex = -1; fetc[0].tymed = (uint)TYMED.TYMED_HGLOBAL; STGMEDIUM[] stm = new STGMEDIUM[] { new STGMEDIUM() }; stm[0].tymed = (uint)TYMED.TYMED_HGLOBAL; ((Microsoft.VisualStudio.OLE.Interop.IDataObject)dataObj).GetData(fetc, stm); global = stm[0].unionmember; } return NativeMethods.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); }