Ejemplo n.º 1
0
        private TreeNode CreateItemNode(Type creatable)
        {
            string name = ItemAttribute.GetName(creatable);

            var itemNode = new TreeNode(name)
            {
                ImageIndex = 0,
                Tag        = creatable,
                Name       = name
            };

            var image = ItemAttribute.GetImage(creatable);

            if (image != null)
            {
                imageList.Images.Add(image);
                itemNode.ImageIndex = imageList.Images.Count - 1;
            }
            itemNode.SelectedImageIndex = itemNode.ImageIndex;

            return(itemNode);
        }
Ejemplo n.º 2
0
        public virtual void Configure(IEnumerable <Type> baseTypes, bool showNotInstantiableTypes, bool showGenericTypes, bool assignableToAllTypes, Func <Type, bool> typeCondition)
        {
            if (baseTypes == null)
            {
                throw new ArgumentNullException();
            }
            if (InvokeRequired)
            {
                Invoke(new Action <IEnumerable <Type>, bool, bool, bool, Func <Type, bool> >(Configure), baseTypes, showNotInstantiableTypes, showGenericTypes, assignableToAllTypes, typeCondition);
            }
            else
            {
                this.baseTypes = baseTypes;
                this.showNotInstantiableTypes = showNotInstantiableTypes;
                this.showGenericTypes         = showGenericTypes;
                bool selectedTypeFound = false;

                typeParametersSplitContainer.Panel2Collapsed = !showGenericTypes;

                TreeNode selectedNode = typesTreeView.SelectedNode;
                typesTreeView.Nodes.Clear();
                treeNodes.Clear();

                imageList.Images.Clear();
                imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class);     // default icon
                imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Namespace); // plugins
                imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Interface); // interfaces
                imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Template);  // generic types
                // additional dictionary for image indexes as imageList.ContainsKey and imageList.IndexOfKey are very slow!
                var imageNames = new Dictionary <string, int>();

                var plugins = from p in ApplicationManager.Manager.Plugins
                              orderby p.Name, p.Version ascending
                select p;
                foreach (IPluginDescription plugin in plugins)
                {
                    TreeNode pluginNode = new TreeNode();
                    pluginNode.Text               = string.Format("{0} {1}.{2}", plugin.Name, plugin.Version.Major, plugin.Version.Minor);
                    pluginNode.ImageIndex         = 1;
                    pluginNode.SelectedImageIndex = pluginNode.ImageIndex;
                    pluginNode.Tag = plugin;

                    var types = from t in ApplicationManager.Manager.GetTypes(BaseTypes, plugin, !ShowNotInstantiableTypes, ShowGenericTypes, assignableToAllTypes)
                                where typeCondition(t)
                                orderby t.Name ascending
                                select t;
                    foreach (Type type in types)
                    {
                        bool valid = (ShowNotInstantiableTypes || type.GetConstructor(Type.EmptyTypes) != null); //check for public default ctor
                        if (valid)
                        {
                            TreeNode typeNode = new TreeNode();
                            string   name     = ItemAttribute.GetName(type);
                            typeNode.Text       = name != null ? name : type.GetPrettyName();
                            typeNode.ImageIndex = 0;
                            if (type.IsInterface)
                            {
                                typeNode.ImageIndex = 2;
                            }
                            else if (type.ContainsGenericParameters)
                            {
                                typeNode.ImageIndex = 3;
                            }
                            else if (imageNames.ContainsKey(type.FullName))
                            {
                                typeNode.ImageIndex = imageNames[type.FullName];
                            }
                            else
                            {
                                var image = ItemAttribute.GetImage(type);
                                if (image != null)
                                {
                                    imageList.Images.Add(image);
                                    typeNode.ImageIndex = imageList.Images.Count - 1;
                                    imageNames.Add(type.FullName, imageList.Images.Count - 1);
                                }
                            }
                            typeNode.SelectedImageIndex = typeNode.ImageIndex;
                            typeNode.Tag = type;
                            pluginNode.Nodes.Add(typeNode);
                            if (type.Equals(selectedType))
                            {
                                selectedTypeFound = true;
                            }
                        }
                    }
                    if (pluginNode.Nodes.Count > 0)
                    {
                        treeNodes.Add(pluginNode);
                    }
                }
                if (!selectedTypeFound)
                {
                    SelectedType = null;
                }
                foreach (TreeNode node in treeNodes)
                {
                    typesTreeView.Nodes.Add((TreeNode)node.Clone());
                }
                RestoreSelectedNode(selectedNode);
                Filter(searchTextBox.Text);

                UpdateTypeParameters();
            }
        }