示例#1
0
        //////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Build the NAnt Addin tree view from an NAntTree.
        /// </summary>
        /// <param name="treeView">The NAnt Addin tree.</param>
        /// <param name="nantTree">The NAntTree.</param>
        /// <param name="title">The title to display.</param>
        //////////////////////////////////////////////////////////////////////////

        public static void CreateTree(TreeView treeView, XmlTree nantTree, string title)
        {
            if (nantTree == null)
            {
                return;
            }

            // Initialize the treeview and its root node
            treeView.Nodes.Clear();

            // Create root node
            TreeNode rootNode = new TreeNode(title);

            rootNode.Tag = nantTree.Root;
            treeView.Nodes.Add(rootNode);


            // Build properties
            if (nantTree.Properties != null)
            {
                TreeNode treeNode = TreeViewFactory.CreateTreeNode(nantTree.Properties, "Properties");
                rootNode.Nodes.Add(treeNode);
            }

            // Build targets in two groups
            if (Properties.Settings.Default.NANT_SPLIT_TARGETS)
            {
                // Build public targets
                if (nantTree.PublicTargets != null)
                {
                    TreeNode publicNodes = TreeViewFactory.CreateTreeNode(nantTree.PublicTargets, "Public targets");
                    rootNode.Nodes.Add(publicNodes);
                    publicNodes.Expand();
                }

                // Build private targets
                if (nantTree.PrivateTargets != null)
                {
                    TreeNode privateNodes = TreeViewFactory.CreateTreeNode(nantTree.PrivateTargets, "Private targets");
                    rootNode.Nodes.Add(privateNodes);
                }
            }
            // Build target all together
            else
            {
                // Build all targets
                if (nantTree.AllTargets != null)
                {
                    TreeNode allNodes = TreeViewFactory.CreateTreeNode(nantTree.AllTargets, "Targets");
                    rootNode.Nodes.Add(allNodes);
                    allNodes.Expand();
                }
            }

            // Build icon
            TreeViewFactory.CreateIcons(treeView);

            // Finally expand the root node
            rootNode.Expand();
        }
示例#2
0
        //////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// The refresh button has been clicked or a new file has been loaded.
        /// The current TreeView will be reloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        //////////////////////////////////////////////////////////////////////////

        public void OnReload(object sender, EventArgs e)
        {
            // Save current selected node
            int[] selectedNodePath = TreeViewUtils.GetPath(m_TreeView.SelectedNode);

            // Load file if any
            if (m_ViewController.Filename == null)
            {
                m_TreeView.Nodes.Clear();
                m_ItemProperties.SelectedObject = null;
            }
            else
            {
                try
                {
                    // Load the file
                    m_ViewController.LoadFile(m_ViewController.Filename);

                    // Create a corresponding visual tree
                    TreeViewFactory.CreateTree(m_TreeView, m_ViewController.NAntTree, m_ViewController.Filename);
                }
                catch (Exception e1)
                {
                    MessageBox.Show("Error while loading file '"
                                    + m_ViewController.Filename + "'."
                                    + "\n"
                                    + e1.Message,
                                    "NAntAddin Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }

            // Retrieve current TreeNode
            m_TreeView.SelectedNode = TreeViewUtils.GetTreeNode(m_TreeView, selectedNodePath);

            // Autoselect the first node, by default
            if (m_TreeView.SelectedNode == null && m_TreeView.Nodes.Count > 0)
            {
                m_TreeView.SelectedNode = m_TreeView.Nodes[0];
            }

            RefreshView();
        }