private void projectPropertiesMenuItem_Click(object sender, EventArgs e)
        {
            NuGenProjectProperties properties = new NuGenProjectProperties();

            if (properties.DisplaySettings() == DialogResult.OK)
            {
                projectElements.Nodes[0].Text = NuGenHelperFunctions.TruncateText(NuGenProject.Instance.Name);
                NuGenUIHandler.Instance.ShowDebuggerState(DebuggerState.DebuggeeStopped);
            }
        }
        public void ShowProject()
        {
            Text = string.Format("Project Explorer - {0}", NuGenProject.Instance.Name);
            projectElements.BeginUpdate();
            projectElements.Nodes.Clear();

            TreeNode projectNode = new TreeNode(NuGenHelperFunctions.TruncateText(NuGenProject.Instance.Name));

            projectNode.ContextMenuStrip = projectMenu;
            projectNode.Tag = NuGenProject.Instance;

            foreach (NuGenAssembly assembly in NuGenProject.Instance.Assemblies)
            {
                ShowAssembly(projectNode, assembly);
            }

            projectElements.Nodes.Add(projectNode);
            projectElements.EndUpdate();
        }
        private TreeNode CreateTypeDefinitionNode(Dictionary <string, TreeNode> namespaceNodes, TreeNode moduleScopeNode, NuGenTypeDefinition typeDefinition, bool createDefinitionNode)
        {
            TreeNode result = new TreeNode(NuGenHelperFunctions.TruncateText(typeDefinition.FullName));

            result.ImageIndex = 11;
            string typeNamespace = typeDefinition.Namespace;

            if (typeNamespace.Length == 0)
            {
                typeNamespace = NuGenConstants.DefaultNamespaceName;
            }

            if (namespaceNodes.ContainsKey(typeNamespace))
            {
                namespaceNodes[typeNamespace].Nodes.Add(result);
            }
            else
            {
                TreeNode namespaceNode = new TreeNode(typeNamespace);
                namespaceNode.ImageIndex = 8;
                moduleScopeNode.Nodes.Add(namespaceNode);
                namespaceNodes[typeNamespace] = namespaceNode;

                namespaceNode.Nodes.Add(result);
            }

            if (createDefinitionNode)
            {
                TreeNode classNode = new TreeNode("definition");
                classNode.ImageIndex = 2;
                classNode.Tag        = typeDefinition;
                result.Nodes.Add(classNode);
            }
            else
            {
                CreateTypeDefinitionSubnodes(typeDefinition, result);
                result.Tag = true;
            }

            return(result);
        }
        private static void CreateTypeDefinitionSubnodes(NuGenTypeDefinition typeDefinition, TreeNode typeDefinitionNode)
        {
            NuGenAssembly assembly = typeDefinition.ModuleScope.Assembly;

            typeDefinition.LazyInitialize(assembly.AllTokens);
            Dictionary <uint, NuGenMethodDefinition> methodDefinitions = null;

            if (typeDefinition.MethodDefinitions != null)
            {
                methodDefinitions = new Dictionary <uint, NuGenMethodDefinition>(typeDefinition.MethodDefinitions);
            }

            if (typeDefinition.FieldDefinitions != null)
            {
                TreeNode fieldsNode = new TreeNode("Fields");
                fieldsNode.ImageIndex = 9;
                typeDefinitionNode.Nodes.Add(fieldsNode);

                foreach (NuGenFieldDefinition field in typeDefinition.FieldDefinitions.Values)
                {
                    field.LazyInitialize(assembly.AllTokens);
                    TreeNode fieldNode = new TreeNode(NuGenHelperFunctions.TruncateText(field.Name));
                    fieldNode.Tag        = field;
                    fieldNode.ImageIndex = 10;
                    fieldsNode.Nodes.Add(fieldNode);
                }
            }

            if (typeDefinition.Properties != null)
            {
                TreeNode propertiesNode = new TreeNode("Properties");
                propertiesNode.ImageIndex = 9;
                typeDefinitionNode.Nodes.Add(propertiesNode);

                foreach (NuGenProperty property in typeDefinition.Properties.Values)
                {
                    property.LazyInitialize(assembly.AllTokens);
                    TreeNode propertyNode = new TreeNode(NuGenHelperFunctions.TruncateText(property.Name));
                    propertyNode.ImageIndex = 11;
                    propertiesNode.Nodes.Add(propertyNode);

                    TreeNode definitionNode = new TreeNode(" definition");
                    definitionNode.Tag        = property;
                    definitionNode.ImageIndex = 2;
                    propertyNode.Nodes.Add(definitionNode);

                    if (methodDefinitions != null)
                    {
                        if (methodDefinitions.ContainsKey(property.GetterMethodToken))
                        {
                            NuGenMethodDefinition getterMethod = methodDefinitions[property.GetterMethodToken];
                            getterMethod.LazyInitialize(assembly.AllTokens);

                            TreeNode getterNode = new TreeNode(NuGenHelperFunctions.TruncateText(getterMethod.DisplayName));
                            getterNode.ImageIndex = 10;
                            getterNode.Tag        = getterMethod;
                            propertyNode.Nodes.Add(getterNode);

                            methodDefinitions.Remove(property.GetterMethodToken);
                        }

                        if (methodDefinitions.ContainsKey(property.SetterMethodToken))
                        {
                            NuGenMethodDefinition setterMethod = methodDefinitions[property.SetterMethodToken];
                            setterMethod.LazyInitialize(assembly.AllTokens);

                            TreeNode setterNode = new TreeNode(NuGenHelperFunctions.TruncateText(setterMethod.DisplayName));
                            setterNode.ImageIndex = 10;
                            setterNode.Tag        = setterMethod;
                            propertyNode.Nodes.Add(setterNode);

                            methodDefinitions.Remove(property.SetterMethodToken);
                        }

                        for (int index = 0; index < property.OtherMethodsCount; index++)
                        {
                            uint token = property.OtherMethods[index];

                            if (methodDefinitions.ContainsKey(token))
                            {
                                NuGenMethodDefinition otherMethod = methodDefinitions[token];
                                otherMethod.LazyInitialize(assembly.AllTokens);

                                TreeNode otherNode = new TreeNode(NuGenHelperFunctions.TruncateText(otherMethod.DisplayName));
                                otherNode.ImageIndex = 10;
                                otherNode.Tag        = otherMethod;
                                propertyNode.Nodes.Add(otherNode);

                                methodDefinitions.Remove(token);
                            }
                        }
                    }
                }
            }

            if (methodDefinitions != null && methodDefinitions.Count > 0)
            {
                TreeNode methodsNode = new TreeNode("Methods");
                methodsNode.ImageIndex = 9;
                typeDefinitionNode.Nodes.Add(methodsNode);

                foreach (NuGenMethodDefinition method in methodDefinitions.Values)
                {
                    method.LazyInitialize(assembly.AllTokens);
                    TreeNode methodNode = new TreeNode(NuGenHelperFunctions.TruncateText(method.DisplayName));
                    methodNode.ImageIndex = 12;
                    methodNode.Tag        = method;
                    methodsNode.Nodes.Add(methodNode);
                }
            }
        }
        private void ShowAssembly(TreeNode projectNode, NuGenAssembly assembly)
        {
            if (assembly != null)
            {
                TreeNode assemblyNode = new TreeNode(NuGenHelperFunctions.TruncateText(assembly.FileName));
                assemblyNode.ContextMenuStrip = assemblyMenu;
                assemblyNode.ImageIndex       = 1;

                if (NuGenProject.Instance.StartupAssembly == assembly)
                {
                    assemblyNode.ForeColor = Color.Red;
                    assemblyNode.NodeFont  = new Font(ProjectElements.Font, FontStyle.Italic);
                }

                assemblyNode.Tag = assembly;
                projectNode.Nodes.Add(assemblyNode);

                if (assembly.DisplayInTree)
                {
                    TreeNode assemblyDefinitionNode = new TreeNode(" definition");
                    assemblyDefinitionNode.Tag        = assembly;
                    assemblyDefinitionNode.ImageIndex = 2;
                    assemblyNode.Nodes.Add(assemblyDefinitionNode);
                }

                if (assembly.AssemblyReferences != null)
                {
                    TreeNode referencesNode = new TreeNode(" References");
                    referencesNode.Tag        = assembly;
                    referencesNode.ImageIndex = 3;
                    assemblyNode.Nodes.Add(referencesNode);

                    foreach (NuGenAssemblyReference reference in assembly.AssemblyReferences.Values)
                    {
                        TreeNode referenceNode = new TreeNode(NuGenHelperFunctions.TruncateText(reference.Name));
                        referenceNode.ContextMenuStrip = assemblyReferenceMenu;
                        referenceNode.Tag        = reference;
                        referenceNode.ImageIndex = 1;
                        referencesNode.Nodes.Add(referenceNode);
                    }
                }

                if (assembly.ManifestResources != null)
                {
                    TreeNode manifestResourcesNode = new TreeNode(" Manifest Resources");
                    manifestResourcesNode.ImageIndex = 4;
                    assemblyNode.Nodes.Add(manifestResourcesNode);

                    foreach (NuGenManifestResource manifestResource in assembly.ManifestResources)
                    {
                        TreeNode manifestResourceNode = new TreeNode(NuGenHelperFunctions.TruncateText(manifestResource.Name));
                        manifestResourceNode.Tag        = manifestResource;
                        manifestResourceNode.ImageIndex = 1;
                        manifestResourcesNode.Nodes.Add(manifestResourceNode);
                    }
                }

                if (assembly.Files != null)
                {
                    TreeNode filesNode = new TreeNode(" Files");
                    filesNode.ImageIndex = 5;
                    assemblyNode.Nodes.Add(filesNode);

                    foreach (NuGenFile file in assembly.Files)
                    {
                        if (file.DisplayInTree)
                        {
                            TreeNode fileNode = new TreeNode(NuGenHelperFunctions.TruncateText(file.Name));
                            fileNode.Tag = file;
                            fileNode.Tag = 5;
                            filesNode.Nodes.Add(fileNode);
                        }
                    }
                }

                if (assembly.ModuleReferences != null)
                {
                    TreeNode moduleReferencesNode = new TreeNode(" Module References");
                    moduleReferencesNode.ImageIndex = 6;
                    assemblyNode.Nodes.Add(moduleReferencesNode);

                    foreach (NuGenModuleReference moduleReference in assembly.ModuleReferences)
                    {
                        TreeNode moduleReferenceNode = new TreeNode(NuGenHelperFunctions.TruncateText(moduleReference.Name));
                        moduleReferenceNode.Tag        = moduleReference;
                        moduleReferenceNode.ImageIndex = 1;
                        moduleReferencesNode.Nodes.Add(moduleReferenceNode);
                    }
                }

                TreeNode moduleScopeNode = new TreeNode(NuGenHelperFunctions.TruncateText(assembly.ModuleScope.Name));
                moduleScopeNode.ImageIndex = 7;
                assemblyNode.Nodes.Add(moduleScopeNode);

                TreeNode moduleScopeDefinitionNode = new TreeNode(" definition");
                moduleScopeDefinitionNode.ImageIndex = 2;
                moduleScopeDefinitionNode.Tag        = assembly.ModuleScope;
                moduleScopeNode.Nodes.Add(moduleScopeDefinitionNode);
                Dictionary <string, TreeNode> namespaceNodes = new Dictionary <string, TreeNode>();

                foreach (NuGenTypeDefinition typeDefinition in assembly.ModuleScope.TypeDefinitions.Values)
                {
                    CreateTypeDefinitionNode(namespaceNodes, moduleScopeNode, typeDefinition, true);
                }

                if (assembly.GlobalType.FieldDefinitions != null || assembly.GlobalType.MethodDefinitions != null || assembly.GlobalType.Properties != null)
                {
                    CreateTypeDefinitionNode(namespaceNodes, moduleScopeNode, assembly.GlobalType, false).Text = " {global type}";
                }
            }
        }