Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /// <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");
        }
Exemplo n.º 3
0
        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);
        }