Exemplo n.º 1
0
        private void UpdateToolboxItem(IDesignerHost host)
        {
            if (host == null)
            {
                throw new ArgumentNullException();
            }
            // Now get a hold of the toolbox service and add an icon for our user control.  The
            // toolbox service will automatically maintain this icon as long as our file lives.
            //
            IToolboxService tbx = (IToolboxService)GetService(typeof(IToolboxService));

            if (tbx != null)
            {
                fullClassName = host.RootComponentClassName;
                if (this.toolboxItem != null)
                {
                    tbx.RemoveToolboxItem(this.toolboxItem);
                }
                this.toolboxItem = new UserControlToolboxItem(fullClassName);

                try {
                    tbx.AddLinkedToolboxItem(toolboxItem, SR.GetString(SR.UserControlTab), host);
                }
                catch (Exception ex) {
                    Debug.Fail("Failed to add toolbox item", ex.ToString());
                }
            }
        }
 /// <summary>
 /// Removes all the toolbox items installed by this package (those which came from this
 /// assembly).
 /// </summary>
 private void RemoveToolboxItems()
 {
     foreach (var item in _items)
     {
         _tbxService.RemoveToolboxItem(item);
     }
 }
            /// <devdoc>
            ///     Saves any checked / unchecked changes made in the dialog to the given toolbox
            ///     service.
            /// </devdoc>
            public void SaveChanges(IToolboxService toolboxSvc)
            {
                string currentCategory = toolboxSvc.SelectedCategory;

                foreach (ToolboxListViewItem item in controlList.Items)
                {
                    if (item.InitiallyChecked != item.Checked)
                    {
                        if (item.InitiallyChecked)
                        {
                            // Item was initially checked, but it's no longer checked.
                            // Remove it from the toolbox.
                            //
                            foreach (ToolboxItem tbxItem in toolboxSvc.GetToolboxItems())
                            {
                                if (tbxItem.Equals(item.Item))
                                {
                                    toolboxSvc.RemoveToolboxItem(tbxItem);
                                }
                            }
                        }
                        else
                        {
                            // Item was not initially checked, but it is now.
                            // Add it to the toolbox.
                            //
                            toolboxSvc.AddToolboxItem(item.Item, currentCategory);
                        }
                    }

                    // Now, update the item so it reflects reality.
                    //
                    item.InitiallyChecked = item.Checked;
                }
            }
        private static void RemoveStandardItem(IToolboxService ts)
        {
            ToolboxItemCollection items        = ts.GetToolboxItems();
            ToolboxItem           standardItem = items.OfType <ToolboxItem>().FirstOrDefault(x => String.Equals(x.DisplayName, "Chart"));

            if (standardItem != null)
            {
                ts.RemoveToolboxItem(standardItem);
            }
        }
        private static void RemoveStandardItem(IToolboxService ts)
        {
            ToolboxItemCollection items        = ts.GetToolboxItems();
            ToolboxItem           standardItem = items.OfType <ToolboxItem>().FirstOrDefault(x => x.DisplayName == "Label");

            if (standardItem != null)
            {
                ts.RemoveToolboxItem(standardItem);
            }
        }
        /// <summary>
        /// Removes all the toolbox items installed by this package (those which came from this
        /// assembly).
        /// </summary>
        void RemoveToolboxItems()
        {
            Assembly a = typeof(PackageWinformsToolbox).Assembly;

            IToolboxService tbxService = (IToolboxService)GetService(typeof(IToolboxService));

            foreach (ToolboxItem item in ToolboxService.GetToolboxItems(a, newCodeBase: null))
            {
                tbxService.RemoveToolboxItem(item);
            }
        }
        //</Snippet10>

        //<Snippet11>
        void OnRefreshToolbox(object sender, EventArgs e)
        {
            // Add new instances of all ToolboxItems contained in ToolboxItemList.
            IToolboxService service =
                GetService(typeof(IToolboxService)) as IToolboxService;
            IVsToolbox toolbox = GetService(typeof(IVsToolbox)) as IVsToolbox;

            //Remove target tab and all controls under it.
            foreach (ToolboxItem oldItem in service.GetToolboxItems(CategoryTab))
            {
                service.RemoveToolboxItem(oldItem);
            }
            toolbox.RemoveTab(CategoryTab);

            foreach (ToolboxItem itemFromList in ToolboxItemList)
            {
                service.AddToolboxItem(itemFromList, CategoryTab);
            }
            service.SelectedCategory = CategoryTab;

            service.Refresh();
        }
        //<Snippet10>
        // Add new instances of all ToolboxItems to the toolbox item list.
        void OnRefreshToolbox(object sender, EventArgs e)
        {
            IToolboxService service =
                GetService(typeof(IToolboxService)) as IToolboxService;
            IVsToolbox toolbox =
                GetService(typeof(IVsToolbox)) as IVsToolbox;

            // Remove target tab and all items under it.
            foreach (ToolboxItem item in service.GetToolboxItems(CategoryTab))
            {
                service.RemoveToolboxItem(item);
            }
            toolbox.RemoveTab(CategoryTab);

            // Recreate the target tab with the items from the current list.
            foreach (ToolboxItem item in ToolboxItemList)
            {
                service.AddToolboxItem(item, CategoryTab);
            }
            service.SelectedCategory = CategoryTab;

            service.Refresh();
        }
Exemplo n.º 9
0
        private void OnRefreshToolbox(object sender, EventArgs e)
        {
            toolboxService = (IToolboxService)GetService(typeof(IToolboxService));
            IVsToolbox vsToolbox = GetService(typeof(IVsToolbox)) as IVsToolbox;

            if (toolboxService == null || vsToolbox == null)
            {
                return;
            }

            PetriNetEditorToolboxProvider toolboxProvider = new PetriNetEditorToolboxProvider();
            var itemList = toolboxProvider.GetToolboxItemList();

            if (itemList == null || itemList.Count == 0)
            {
                return;
            }

            string toolboxCategoryName = PetriNetEditorToolboxProvider.ToolboxCategoryName;

            //Remove target tab and all controls under it.
            foreach (ToolboxItem oldItem in toolboxService.GetToolboxItems(toolboxCategoryName))
            {
                toolboxService.RemoveToolboxItem(oldItem);
            }
            vsToolbox.RemoveTab(PetriNetEditorToolboxProvider.ToolboxCategoryName);

            foreach (ToolboxItem item in itemList)
            {
                toolboxService.AddToolboxItem(item, toolboxCategoryName);
            }

            toolboxService.SelectedCategory = toolboxCategoryName;
            toolboxService.Refresh();
        }