Exemple #1
0
        public void SetToolBox(ToolboxService toolboxService)
        {
            if (toolboxService == _lastToolboxService)
                return;

            toolBoxTreeView.Nodes.Clear();
            if (toolBoxTreeView.ImageList != null)
            {
                toolBoxTreeView.ImageList.Dispose();
            }

            toolBoxTreeView.ImageList = new ImageList()
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize = new Size(16,16),
            };

            toolBoxTreeView.ImageList.Images.Add(_folderImage);
            toolBoxTreeView.ImageList.Images.Add(_pointer);

            if (toolboxService != null)
            {
                toolboxService.SelectedItemChanged += toolboxService_SelectedItemChanged;

                foreach (string category in toolboxService.CategoryNames)
                {
                    TreeNode rootNode = new TreeNode(category);
                    rootNode.Nodes.Add(new TreeNode("Pointer") { ImageIndex = 1, SelectedImageIndex = 1 });

                    foreach (ToolboxItem item in toolboxService.GetToolboxItems(category))
                    {
                        toolBoxTreeView.ImageList.Images.Add(item.Bitmap);
                        rootNode.Nodes.Add(new TreeNode(item.DisplayName)
                        {
                            ToolTipText = string.Format("{0}\r\n{1} v{2}\r\n\r\n{3}", item.TypeName, item.AssemblyName, item.Version, item.Description),
                            Tag = item,
                            ImageIndex = toolBoxTreeView.ImageList.Images.Count - 1,
                            SelectedImageIndex = toolBoxTreeView.ImageList.Images.Count - 1,
                        });
                    }

                    toolBoxTreeView.Nodes.Add(rootNode);
                    if (category == toolboxService.SelectedCategory)
                        rootNode.Expand();
                }

                label1.Visible = toolBoxTreeView.Nodes.Count == 0;
            }
            else
            {
                label1.Visible = true;
            }

            _lastToolboxService = toolboxService;
        }
        //</Snippet10>

        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        // ...
        protected override void Initialize()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture,
                                          "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs =
                GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for the menu item.
                CommandID menuCommandID = new CommandID(
                    GuidList.guidItemConfigurationCmdSet,
                    (int)PkgCmdIDList.cmdidMyCommand);
                MenuCommand menuItem = new MenuCommand(MenuItemCallback, menuCommandID);
                mcs.AddCommand(menuItem);
            }

            //<Snippet12>
            // Use the toolbox service to get a list of all toolbox items in
            // this assembly.
            ToolboxItemList = new ArrayList(
                ToolboxService.GetToolboxItems(this.GetType().Assembly, ""));
            if (null == ToolboxItemList)
            {
                throw new ApplicationException(
                          "Unable to generate a toolbox item listing for " +
                          this.GetType().FullName);
            }

            // Update the display name of each toolbox item in the list.
            Assembly thisAssembly = this.GetType().Assembly;

            foreach (ToolboxItem item in ToolboxItemList)
            {
                Type underlyingType         = thisAssembly.GetType(item.TypeName);
                AttributeCollection attribs =
                    TypeDescriptor.GetAttributes(underlyingType);
                DisplayNameAttribute displayName =
                    attribs[typeof(DisplayNameAttribute)] as DisplayNameAttribute;
                if (displayName != null && !displayName.IsDefaultAttribute())
                {
                    item.DisplayName = displayName.DisplayName;
                }
            }
            //</Snippet12>
        }
        /// <summary>
        /// Installs all the toolbox items defined in this assembly.
        /// </summary>
        void InstallToolboxItems()
        {
            // For demonstration purposes, this assembly includes toolbox items and loads them from itself.
            // It is of course possible to load toolbox items from a different assembly by either:
            // a)  loading the assembly yourself and calling ToolboxService.GetToolboxItems
            // b)  calling AssemblyName.GetAssemblyName("...") and then ToolboxService.GetToolboxItems(assemblyName)
            Assembly a = typeof(PackageWinformsToolbox).Assembly;

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

            foreach (ToolboxItem item in ToolboxService.GetToolboxItems(a, newCodeBase: null))
            {
                // This tab name can be whatever you would like it to be.
                tbxService.AddToolboxItem(item, "MyOwnTab");
            }
        }
Exemple #4
0
        private void UpgradeToolBoxItems()
        {
            var tbxService = (IToolboxService)GetService(typeof(IToolboxService));

            ModifyToolboxItems(module => {
                var assembly     = Assembly.LoadFile(module.AssemblyPath);
                var toolboxItems = ToolboxService.GetToolboxItems(assembly, null).Cast <ToolboxItem>().ToArray();
                foreach (var item in toolboxItems)
                {
                    tbxService.RemoveToolboxItem(item);
                    this.DTE2().StatusBar.Text =
                        $"{item.DisplayName} removed from the toolbox category Xpand.{module.Platform}";
                }

                return(toolboxItems.FirstOrDefault());
            });
            InstallToolBoxItems();
        }
        public void SetToolBox(ToolboxService toolboxService)
        {
            if (toolboxService == _lastToolboxService)
            {
                return;
            }

            toolBoxTreeView.Nodes.Clear();
            if (toolBoxTreeView.ImageList != null)
            {
                toolBoxTreeView.ImageList.Dispose();
            }

            toolBoxTreeView.ImageList = new ImageList()
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize  = new Size(16, 16),
            };

            toolBoxTreeView.ImageList.Images.Add(_folderImage);
            toolBoxTreeView.ImageList.Images.Add(_pointer);

            if (toolboxService != null)
            {
                toolboxService.SelectedItemChanged += toolboxService_SelectedItemChanged;

                foreach (string category in toolboxService.CategoryNames)
                {
                    TreeNode rootNode = new TreeNode(category);
                    rootNode.Nodes.Add(new TreeNode("Pointer")
                    {
                        ImageIndex = 1, SelectedImageIndex = 1
                    });

                    foreach (ToolboxItem item in toolboxService.GetToolboxItems(category))
                    {
                        toolBoxTreeView.ImageList.Images.Add(item.Bitmap);
                        rootNode.Nodes.Add(new TreeNode(item.DisplayName)
                        {
                            ToolTipText        = string.Format("{0}\r\n{1} v{2}\r\n\r\n{3}", item.TypeName, item.AssemblyName, item.Version, item.Description),
                            Tag                = item,
                            ImageIndex         = toolBoxTreeView.ImageList.Images.Count - 1,
                            SelectedImageIndex = toolBoxTreeView.ImageList.Images.Count - 1,
                        });
                    }

                    toolBoxTreeView.Nodes.Add(rootNode);
                    if (category == toolboxService.SelectedCategory)
                    {
                        rootNode.Expand();
                    }
                }

                label1.Visible = toolBoxTreeView.Nodes.Count == 0;
            }
            else
            {
                label1.Visible = true;
            }

            _lastToolboxService = toolboxService;
        }
Exemple #6
0
 static IEnumerable <ToolboxItem> EnumerateToolboxItems(Assembly assembly)
 {
     return(ToolboxService.GetToolboxItems(assembly, null).Cast <ToolboxItem>());
 }