Exemplo n.º 1
0
        public Point GetLocation()
        {
            Object currentNode = this.parent;
            int    offsetX     = 0;
            int    offsetY     = 0;
            int    depth       = 0; //How many levels/tabs in are we?

            while (currentNode is TristateTreeNode)
            {
                TristateTreeNode cNode = (TristateTreeNode)currentNode;
                offsetY += cNode.Size.Height;
                //Console.WriteLine(offsetY);
                for (int i = 0; i < cNode.nodes.Count; i++)
                {
                    if (!cNode.nodes[i].Contains(this) && cNode.nodes[i] != this) //Not our owner, just add its height
                    {
                        //Console.WriteLine(cNode.text + " " + cNode.nodes[i].BigSize.Height);
                        //Console.WriteLine("add height: " + cNode.nodes[i].BigSize.Height);
                        offsetY += cNode.nodes[i].BigSize.Height;
                    }
                    else //We found our owner, don't add offset, since we've already done so earlier
                    {
                        i = cNode.nodes.Count; //Done.
                    }
                }
                //Console.WriteLine(offsetY);
                depth++;
                currentNode = cNode.parent;
            }
            //curentNode is now a tristatetreeview
            TristateTreeView view = (TristateTreeView)currentNode;
            bool             done = false;

            for (int i = 0; i < view.Nodes.Count && !done; i++)
            {
                if (view.Nodes[i].Contains(this) || view.Nodes[i] == this)
                {
                    done = true;
                }
                else
                {
                    offsetY += view.Nodes[i].BigSize.Height;
                }
            }
            return(new Point(tabWidth * depth + ((TristateTreeView)currentNode).StartDrawOffset.X, offsetY));
        }
        /// <summary>
        /// Initializes the changes view - Sizes columns and sets an event handler for them to autosize
        /// </summary>
        private void InitializeChangesView()
        {
            rafContentView.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(rafContentView_NodeMouseDoubleClick);
            rafContentView.AllowDrop             = true;
            rafContentView.DragOver             += new DragEventHandler(rafContentView_DragOver);
            rafContentView.MouseClick           += new MouseEventHandler(rafContentView_MouseClick);
            smallContainer.Panel1.MouseClick    += new MouseEventHandler(rafContentView_MouseClick);

            changesView                   = new TristateTreeView();
            changesView.Dock              = DockStyle.Fill;
            changesView.EmptyComment      = "No items have been added yet!  Drag skin files in!";
            changesView.EmptyBitmap       = Properties.Resources.DropFileToBegin;
            changesView.AllowDrop         = true;
            changesView.DragOver         += new DragEventHandler(changesView_DragOver);
            changesView.DragDrop         += new DragEventHandler(changesView_DragDrop);
            changesView.NodeRightClicked += new NodeRightClickedHandler(changesView_NodeRightClicked);
            this.smallContainer.Panel2.Controls.Add(changesView);
            //changesView.Nodes[0].
            //this.Resize += delegate(object sender, EventArgs e) { UpdateChangesGUI(); };
        }
        /// <summary>
        /// Initializes the changes view - Sizes columns and sets an event handler for them to autosize
        /// </summary>
        private void InitializeChangesView()
        {
            rafContentView.NodeMouseDoubleClick += new TreeNodeMouseClickEventHandler(rafContentView_NodeMouseDoubleClick);
            rafContentView.AllowDrop = true;
            rafContentView.DragOver += new DragEventHandler(rafContentView_DragOver);
            rafContentView.MouseClick += new MouseEventHandler(rafContentView_MouseClick);
            smallContainer.Panel1.MouseClick += new MouseEventHandler(rafContentView_MouseClick);

            changesView = new TristateTreeView();
            changesView.Dock = DockStyle.Fill;
            changesView.EmptyComment = "No items have been added yet!  Drag skin files in!";
            changesView.EmptyBitmap = Properties.Resources.DropFileToBegin;
            changesView.AllowDrop = true;
            changesView.DragOver += new DragEventHandler(changesView_DragOver);
            changesView.DragDrop += new DragEventHandler(changesView_DragDrop);
            changesView.NodeRightClicked += new NodeRightClickedHandler(changesView_NodeRightClicked);
            this.smallContainer.Panel2.Controls.Add(changesView);
            //changesView.Nodes[0].
            //this.Resize += delegate(object sender, EventArgs e) { UpdateChangesGUI(); };
        }
        void changesView_NodeRightClicked(TristateTreeNode node, MouseEventArgs e)
        {
            ContextMenu cm   = new ContextMenu();
            MenuItem    pack = new MenuItem("Pack (Install checked, uninstall unchecked)");

            #region pack button
            pack.Click += delegate(object sender, EventArgs e2)
            {
                if (VerifyPackPrecondition(
                        new List <TristateTreeNode>(
                            new TristateTreeNode[] { node }
                            )
                        ))
                {
                    Title("Begin Packing...");
                    PackNode(node);
                    Title(GetWindowTitle());
                    Log("Pack done");
                }
            };
            #endregion
            cm.MenuItems.Add(pack);

            MenuItem rename = new MenuItem("Rename");
            #region rename button
            rename.Click += delegate(object s2, EventArgs e2)
            {
                StringQueryDialog sqd = new StringQueryDialog("Rename '" + node.Text + "' to:", node.Text);
                sqd.ShowDialog();
                node.Text = sqd.Value;

                node.TreeView.Invalidate();
                HasProjectChanged = true;
            };
            #endregion
            cm.MenuItems.Add(rename);

            MenuItem groupButton = new MenuItem("Group");
            #region group button
            groupButton.Click += delegate(object s2, EventArgs e2)
            {
                List <TristateTreeNode> nodes = new List <TristateTreeNode>(changesView.SelectedNodes);
                changesView.SelectedNodes.Clear();

                StringQueryDialog sqd = new StringQueryDialog("What would you like to name this group?");
                sqd.ShowDialog();
                if (sqd.Value == "")
                {
                    return;
                }

                TristateTreeNode newNode = new TristateTreeNode(sqd.Value.Trim());

                //Remove the nodes from their parent, keep the first one for replacement w/ our new node
                for (int i = 1; i < nodes.Count; i++)
                {
                    if (nodes[i].Parent is TristateTreeNode)
                    {
                        ((TristateTreeNode)nodes[i].Parent).Nodes.Remove(nodes[i]);
                    }
                    else
                    {
                        ((TristateTreeView)nodes[i].Parent).Nodes.Remove(nodes[i]);
                    }
                }
                Object oldParent = nodes[0].Parent;

                //Add the nodes to our new node
                for (int i = 0; i < nodes.Count; i++)
                {
                    newNode.Nodes.Add(nodes[i]);
                }

                //Replace the previous node with our new node
                if (oldParent is TristateTreeNode)
                {
                    TristateTreeNode parent = (TristateTreeNode)oldParent;
                    parent.Nodes[parent.Nodes.IndexOf(nodes[0])] = newNode;
                    newNode.Parent = parent;
                }
                else
                {
                    TristateTreeView parent = (TristateTreeView)oldParent;
                    parent.Nodes[parent.Nodes.IndexOf(nodes[0])] = newNode;
                    newNode.Parent = parent;
                }
                newNode.HasCheckBox = true;
                newNode.UpdateCheckState(true, true);
                changesView.Invalidate();
            };
            #endregion
            cm.MenuItems.Add(groupButton);

            #region ungroup button
            if (changesView.SelectedNodes.Count == 1)
            {
                if (changesView.SelectedNode.Tag == null) //If it's a RAF Object, we can't ungroup it.
                {
                    //This isn't a raf object
                    MenuItem ungroupButton = new MenuItem("Ungroup");
                    ungroupButton.Click += delegate(object s2, EventArgs e2)
                    {
                        if (changesView.SelectedNode.Parent is TristateTreeView)
                        {
                            TristateTreeNode groupNode = changesView.SelectedNode;

                            TristateTreeView parent = (TristateTreeView)changesView.SelectedNode.Parent;
                            int oldIndex            = parent.Nodes.IndexOf(groupNode);
                            parent.Nodes.Remove(groupNode);
                            for (int i = 0; i < groupNode.Nodes.Count; i++)
                            {
                                parent.Nodes.Insert(oldIndex + i, groupNode.Nodes[i]);
                            }
                            //parent.Nodes.Remove(groupNode);
                            changesView.Invalidate();
                        }
                    };
                    cm.MenuItems.Add(ungroupButton);
                }
            }
            #endregion

            #region delete button
            if (changesView.SelectedNodes.Count >= 2)
            {
                MenuItem multiDelete = new MenuItem("Remove From Project (Won't uninstall)");
                #region delete button
                multiDelete.Click += delegate(object sender, EventArgs e2)
                {
                    while (changesView.SelectedNodes.Count > 0)
                    {
                        node = changesView.SelectedNodes[0];
                        if (node.Parent is TristateTreeView)
                        {
                            TristateTreeView p = (TristateTreeView)node.Parent;
                            p.Nodes.Remove(node);
                            if (p.SelectedNode == node)
                            {
                                p.SelectedNode = null;
                            }
                            p.Invalidate();
                        }
                        else
                        {
                            TristateTreeNode n = (TristateTreeNode)node.Parent;
                            n.Nodes.Remove(node);
                            if (n.TreeView.SelectedNode == node)
                            {
                                n.TreeView.SelectedNode = null;
                            }
                            n.TreeView.Invalidate();
                        }
                        changesView.SelectedNodes.RemoveAt(0);
                    }
                    HasProjectChanged = true;
                };
                #endregion
                cm.MenuItems.Add(multiDelete);
            }
            else
            {
                MenuItem delete = new MenuItem("Remove From Project (Won't uninstall)");
                #region delete button
                delete.Click += delegate(object sender, EventArgs e2)
                {
                    if (node.Parent is TristateTreeView)
                    {
                        TristateTreeView p = (TristateTreeView)node.Parent;
                        p.Nodes.Remove(node);
                        if (p.SelectedNode == node)
                        {
                            p.SelectedNode = null;
                        }
                        p.Invalidate();
                    }
                    else
                    {
                        TristateTreeNode n = (TristateTreeNode)node.Parent;
                        n.Nodes.Remove(node);
                        if (n.TreeView.SelectedNode == node)
                        {
                            n.TreeView.SelectedNode = null;
                        }
                        n.TreeView.Invalidate();
                    }
                    HasProjectChanged = true;
                };
                #endregion
                cm.MenuItems.Add(delete);
            }
            #endregion

            //Checkbox or radio?
            if (changesView.SelectedNode.NodeType == TristateTreeNodeType.Radio ||
                changesView.SelectedNode.NodeType == TristateTreeNodeType.Checkboxes)
            {//It's swappable
                MenuItem changeType = new MenuItem("Change to " +
                                                   (changesView.SelectedNode.NodeType == TristateTreeNodeType.Checkboxes ? "Radio Selector" : "Checkboxes")
                                                   + " - Coming Soon!"
                                                   );
                changeType.Click += delegate(object s2, EventArgs e2)
                {
                    if (changesView.SelectedNode.NodeType == TristateTreeNodeType.Radio)
                    {
                        changesView.SelectedNode.NodeType = TristateTreeNodeType.Checkboxes;
                    }
                    else if (changesView.SelectedNode.NodeType == TristateTreeNodeType.Checkboxes)
                    {
                        changesView.SelectedNode.NodeType = TristateTreeNodeType.Radio;
                    }

                    changesView.Invalidate();
                };
                changeType.Enabled = false;
                cm.MenuItems.Add(changeType);
            }

            cm.Show(changesView, new Point(e.X, e.Y));
        }