protected void AddHtml([NotNull] string name, [NotNull, Localizable(false)] string html) { Debug.ArgumentNotNull(name, nameof(name)); Debug.ArgumentNotNull(html, nameof(html)); // ReSharper disable once SuspiciousTypeConversion.Global var toolbox = SitecorePackage.Instance.GetService <SVsToolbox>() as IVsToolbox; if (toolbox == null) { return; } var data = new OleDataObject(); data.SetText(ConvertToClipboardFormat(html, name, null), TextDataFormat.Html); var itemInfo = GetItemInfo(name); try { toolbox.AddItem(data, itemInfo, Resources.HtmlToolboxItemHandler_AddHtml_Sitecore); } catch (Exception ex) { Trace.TraceError(ex.Message); } }
/// <summary> /// This method adds a Toolbox item by VS Toolbox service. /// This way provides more flexibilities than DTE way. /// </summary> private void AddItemByVsToolboxService() { // Get shell service provider. ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_applicationObject); // Get the IVsToolbox interface. IVsToolbox tbs = sp.GetService(typeof(SVsToolbox)) as IVsToolbox; // Toolbox Item Info data TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; Bitmap bitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream("CSVSAddInToolboxItem.Demo.bmp")); itemInfo[0].bstrText = "Service Added HTML Content"; itemInfo[0].hBmp = bitmap.GetHbitmap(); itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; // OleDataObject to host toolbox data OleDataObject tbItem = new OleDataObject(); tbItem.SetText( ConvertToClipboardFormat("<input id=\"Button1\" type=\"button\" value=\"button\" />", null, null), TextDataFormat.Html); // Add a new toolbox item to MyCustomTab tab tbs.AddItem(tbItem, itemInfo, "CustomTab"); }
public void HandleDragEnter(DragEventArgs e) { //wrap standard IDataObject in OutlookDataObject OleDataObject dataObject = new OleDataObject(e.Data); string[] filenames = null; if (dataObject.GetDataPresent("FileDrop")) { filenames = (string[])dataObject.GetData("FileDrop"); } else if (dataObject.GetDataPresent("FileGroupDescriptor")) { filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); } if (filenames != null) { e.Effect = DragDropEffects.Copy; foreach (string filename in filenames) { string ext = Path.GetExtension(filename).ToLower(); if (!this.AllowedExt.Contains(ext)) { e.Effect = DragDropEffects.None; break; } } } }
void InitializeToolbox() { #if false ThreadHelper.ThrowIfNotOnUIThread(); // If toolboxData have initialized, skip creating a new one. if (toolboxData == null) { // Get the toolbox service IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox)); toolboxData = new OleDataObject[3]; // Create the data objects that will store the data for the toolbox items. toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Event] = new OleDataObject(); toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Event].SetData(typeof(Toolbox.ToolboxItemData), new Toolbox.ToolboxItemData(Toolbox.ToolboxItemData.ToolboxItems.Event)); toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.State] = new OleDataObject(); toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.State].SetData(typeof(Toolbox.ToolboxItemData), new Toolbox.ToolboxItemData(Toolbox.ToolboxItemData.ToolboxItems.State)); toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Transition] = new OleDataObject(); toolboxData[(int)Toolbox.ToolboxItemData.ToolboxItems.Transition].SetData(typeof(Toolbox.ToolboxItemData), new Toolbox.ToolboxItemData(Toolbox.ToolboxItemData.ToolboxItems.Transition)); TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; for (Toolbox.ToolboxItemData.ToolboxItems item = Toolbox.ToolboxItemData.ToolboxItems.Event; item <= Toolbox.ToolboxItemData.ToolboxItems.Transition; item++) { itemInfo[0].bstrText = item.ToString(); itemInfo[0].hBmp = IntPtr.Zero; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData[(int)item], itemInfo, "State Machine")); } } #endif }
private void CreateToolboxData(string pToolboxItemName, string pData, string pTabInToolbox, bool pRemoveTabItems = false) { // Create the data object that will store the data for the menu item. OleDataObject toolboxData = new OleDataObject(); toolboxData.SetData(typeof(ToolboxData), new ToolboxData(pData)); // Get the toolbox service IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox)); //IVsToolbox2 vsToolbox2 = (IVsToolbox2)toolbox; //IVsToolbox3 vsToolbox3 = (IVsToolbox3)vsToolbox2; if (pRemoveTabItems) { bool succeed = ErrorHandler.Succeeded(toolbox.RemoveTab(pTabInToolbox)); } // Create the array of TBXITEMINFO structures to describe the items // we are adding to the toolbox. TBXITEMINFO[] itemInfo = new TBXITEMINFO[1]; itemInfo[0].bstrText = pToolboxItemName; itemInfo[0].clrTransparent = ColorToUInt(Color.Black); itemInfo[0].hBmp = Resources.cartForToolboxItem.GetHbitmap(); itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; //itemInfo[0].iImageIndex = 0; //itemInfo[0].iImageWidth = 16; ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData, itemInfo, pTabInToolbox)); }
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); }
public int ToolboxSelectionChanged(IDataObject pSelected) { if (pSelected == null) { return(VSConstants.S_FALSE); } _selectedToolboxData = (OleDataObject)pSelected; ToolboxData data = (ToolboxData)_selectedToolboxData.GetData(typeof(ToolboxData)); editorControl.tbDropData.Text = data.Content; return(VSConstants.S_OK); }
public List <string> HandleDrop(DragEventArgs e) { List <string> output = new List <string>(); OleDataObject dataObject = new OleDataObject(e.Data); if (!Directory.Exists(this.OutputDir)) { Directory.CreateDirectory(this.OutputDir); } if (e.Data.GetDataPresent("FileDrop")) { string[] data = (string[])e.Data.GetData("FileDrop"); if (data != null) { foreach (string path in data) { string filename = Path.Combine(this.OutputDir, Path.GetFileName(path).ToLower()); File.Copy(path, filename, true); output.Add(filename); } } } else if (e.Data.GetDataPresent("FileGroupDescriptor")) { //wrap standard IDataObject in OutlookDataObject // OutlookDataObject dataObject = new OutlookDataObject(e.Data); //get the names and data streams of the files dropped string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW"); MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents"); for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++) { //use the fileindex to get the name and data stream MemoryStream filestream = filestreams[fileIndex]; string filename = Path.Combine(this.OutputDir, filenames[fileIndex]); //save the file stream using its name to the application path using (FileStream outputStream = File.Create(filename)) { filestream.WriteTo(outputStream); outputStream.Close(); } filestream.Close(); output.Add(filename); } } return(output); }
/// <summary> /// See if we can extract an IOleDataObject from the .NET data object /// if we can't we are basically screwed (no way to get the data to /// MSHTML since it only understands IOleDataObject). In that case /// return an empty data object /// </summary> /// <param name="dataObject">data object</param> /// <returns>Either the IOleDataObject extracted from the passed /// IDataObject or a special 'empty' IOleDataObject</returns> public static IOleDataObject ExtractOleDataObject(IDataObject dataObject) { OleDataObject oleDataObject = OleDataObject.CreateFrom(dataObject); if (oleDataObject != null) { return(oleDataObject.IOleDataObject); } else { return(null); } }
/// <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(Toolbox_TestItem1))) { Debug.WriteLine("MyToolboxItemData selected from the toolbox"); Toolbox_TestItem1 myData = (Toolbox_TestItem1)oleData.GetData(typeof(Toolbox_TestItem1)); //editorControl.Text += myData.Content; } return(VSConstants.S_OK); }
public int ItemPicked(IDataObject 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(ToolboxData))) { System.Diagnostics.Trace.WriteLine("MyToolboxItemData selected from the toolbox"); ToolboxData myData = (ToolboxData)oleData.GetData(typeof(ToolboxData)); editorControl.tbDropData.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); }
private static void AddToToolbox(string label, string actualText) { var tbs = Instance.ServiceProvider.GetServiceAsync(typeof(IVsToolbox)).Result as IVsToolbox; var itemInfo = new TBXITEMINFO[1]; var tbItem = new OleDataObject(); var bitmap = new System.Drawing.Bitmap("./Resources/MarkupTag_16x.png"); itemInfo[0].hBmp = bitmap.GetHbitmap(); itemInfo[0].bstrText = label; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; tbItem.SetText(actualText, TextDataFormat.Text); tbs?.AddItem(tbItem, itemInfo, "Rapid XAML"); }
private static async Task AddToToolboxAsync(string label, string actualText) { ThreadHelper.ThrowIfNotOnUIThread(); var tbs = await Instance.ServiceProvider.GetServiceAsync(typeof(IVsToolbox)) as IVsToolbox; var itemInfo = new TBXITEMINFO[1]; var tbItem = new OleDataObject(); var bitmap = new System.Drawing.Bitmap("./Resources/MarkupTag_16x.png"); itemInfo[0].hBmp = bitmap.GetHbitmap(); itemInfo[0].bstrText = label; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; tbItem.SetText(actualText, TextDataFormat.Text); tbs?.AddItem(tbItem, itemInfo, StringRes.UI_ToolboxGroupHeader); }
private static async Task AddToToolboxAsync(string label, string actualText) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var tbs = await Instance.AsyncPackage.GetServiceAsync <IVsToolbox, IVsToolbox>(); var itemInfo = new TBXITEMINFO[1]; var tbItem = new OleDataObject(); var executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var bitmap = new System.Drawing.Bitmap(Path.Combine(executionPath, "Resources", "MarkupTag_16x.png")); itemInfo[0].hBmp = bitmap.GetHbitmap(); itemInfo[0].bstrText = label; itemInfo[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; tbItem.SetText(actualText, TextDataFormat.Text); tbs?.AddItem(tbItem, itemInfo, StringRes.UI_ToolboxGroupHeader); }
public int InterceptDataObject(IDataObject pIn, out IDataObject ppOut) { ToolboxData myData = new ToolboxData("NotDefined"); ppOut = null; if (_selectedToolboxData == null) { return(VSConstants.S_FALSE); } else { myData = (ToolboxData)_selectedToolboxData.GetData(typeof(ToolboxData)); } OleDataObject newtoolboxData = new OleDataObject(); newtoolboxData.SetText($"Dropped {myData?.Content}", System.Windows.Forms.TextDataFormat.Text); ppOut = newtoolboxData; return(VSConstants.S_OK); }
/// <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> /// 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() { ThreadHelper.ThrowIfNotOnUIThread(); // If toolboxData have initialized, skip creating a new one. if (toolboxData == null) { // Get the toolbox service IVsToolbox toolbox = (IVsToolbox)GetService(typeof(SVsToolbox)); System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap(@"Resources\Bitmap1.bmp"); System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap(@"Resources\Bitmap2.bmp"); // Create the array of TBXITEMINFO structures to describe the items // we are adding to the toolbox. TBXITEMINFO[] itemInfo1 = new TBXITEMINFO[1]; itemInfo1[0].bstrText = "Toolbox Sample Item"; itemInfo1[0].hBmp = bitmap1.GetHbitmap(); itemInfo1[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; TBXITEMINFO[] itemInfo2 = new TBXITEMINFO[1]; itemInfo2[0].bstrText = "Toolbox Sample Item 2"; itemInfo2[0].hBmp = bitmap2.GetHbitmap(); itemInfo2[0].dwFlags = (uint)__TBXITEMINFOFLAGS.TBXIF_DONTPERSIST; toolboxData = new OleDataObject(); toolboxData.SetData(typeof(Toolbox_TestItem1), new Toolbox_TestItem1("Test string")); ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData, itemInfo1, "GraphML Toolbox")); toolboxData = new OleDataObject(); toolboxData.SetData(typeof(Toolbox_TestItem2), new Toolbox_TestItem2("Test string 2")); ErrorHandler.ThrowOnFailure(toolbox.AddItem(toolboxData, itemInfo2, "GraphML Toolbox")); } }
/// <summary> /// Perform a Drag and Drop operation on this node. /// </summary> public virtual void DoDragDrop(OleDataObject dataObject, uint keyState, uint effect) { }
/// <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); }
public void DoDragDrop(OleDataObject dataObject, uint grfKeyState, uint pdwEffect) { }