コード例 #1
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            file = new DiffFile();
            if (txtDiffFile.Text.EndsWith(".xdiff"))
            {
                file.Load(txtDiffFile.Text, DiffType.xDiff);
            }
            else
            {
                file.Load(txtDiffFile.Text, DiffType.Diff);
            }

            lstPatches.Nodes.Clear();

            if (file.xPatches.Count <= 0)
            {
                return;
            }

            int num = file.PatchCount();

            if (file.Type == DiffType.xDiff)
            {
                leftPatches  = new int[num];
                rightPatches = new int[num];
            }
            else
            {
                indexedPatches = file.Patches.ToArray();

                leftPatches  = new int[file.Patches.Count];
                rightPatches = new int[file.Patches.Count];
            }

            int i = 0;

            for (i = 0; i < leftPatches.Length; i++)
            {
                leftPatches[i]  = int.MaxValue;
                rightPatches[i] = int.MaxValue;
            }

            i = 0;
            if (file.Type == DiffType.xDiff)
            {
                foreach (KeyValuePair <int, DiffPatchBase> p in file.xPatches)
                {
                    if (p.Value is DiffPatchGroup)
                    {
                        TreeNodeEx node = new TreeNodeEx(p.Value.Name);
                        node.Tag             = file.xPatches[p.Value.ID]; //is this a reference or a copy? :x
                        node.ActAsRadioGroup = true;

                        foreach (DiffPatch p2 in ((DiffPatchGroup)p.Value).Patches)
                        {
                            TreeNodeEx n = new TreeNodeEx(p2.Name);
                            n.Tag = file.xPatches[p2.ID];
                            node.Nodes.Add(n);
                        }
                        lstPatches.Nodes.Add(node);
                    }
                    else if (p.Value is DiffPatch && ((DiffPatch)p.Value).GroupID <= 0)
                    {
                        TreeNodeEx node = new TreeNodeEx(p.Value.Name);
                        node.Tag = file.xPatches[p.Value.ID];
                        lstPatches.Nodes.Add(node);
                    }
                }
            }
            else
            {
                foreach (KeyValuePair <string, DiffPatch> p in indexedPatches)
                {
                    leftPatches[i] = i;
                    //lstPatches.Items.Add(p.Value.Name);
                    i++;
                }
            }

            grpDiff.Enabled = true;
        }
コード例 #2
0
        protected override void OnAfterCheck(TreeViewEventArgs e)
        {
            TreeNodeEx node = (TreeNodeEx)e.Node;

            if (this.CheckBoxes)
            {
                if (node.Block)
                {
                    return;
                }

                if (node.Nodes != null && node.Nodes.Count > 0 && !node.Checked)
                {
                    foreach (TreeNodeEx n in e.Node.Nodes)
                    {
                        n.Block   = true;
                        n.Checked = false;
                        n.Block   = false;
                    }

                    base.OnAfterCheck(e);
                    return;
                }

                if (node.Nodes != null && node.Nodes.Count > 0 && node.Checked) //e.Node is TreeNodeEx && !((TreeNodeEx) e.Node).Block && e.Node.Nodes != null && e.Node.Nodes.Count > 0)
                {
                    bool check = false;

                    foreach (TreeNode n in node.Nodes)
                    {
                        if (n.Checked)
                        {
                            check = true;
                        }
                    }

                    if (!check) //no checked child ! tick first child :D
                    {
                        ((TreeNodeEx)node.Nodes[0]).Block = true;
                        node.Nodes[0].Checked             = true;
                        ((TreeNodeEx)node.Nodes[0]).Block = false;
                    }

                    node.Block = false;
                    base.OnAfterCheck(e);
                    return;
                }

                if (node.Parent != null && node.Parent is TreeNodeEx)
                {
                    if (node.Checked)
                    {
                        TreeNodeEx n = (TreeNodeEx)e.Node.Parent;
                        n.Block   = true;
                        n.Checked = true; //Check parent if child is checked
                        n.Block   = false;

                        if (n.ActAsRadioGroup && !n.Block)
                        {
                            n.Block = true; // to prevent unwanted recursion
                            foreach (TreeNodeEx m in n.Nodes)
                            {
                                if (m != e.Node)
                                {
                                    m.Block   = true;
                                    m.Checked = false;
                                    m.Block   = false;
                                }
                            }
                            n.Block = false;
                        }
                    }
                    else
                    {
                        bool check = false;

                        foreach (TreeNode n in node.Parent.Nodes)
                        {
                            if (n.Checked)
                            {
                                check = true;
                            }
                        }

                        if (!check)
                        {
                            ((TreeNodeEx)node.Parent).Block = true;
                            node.Parent.Checked             = false;
                            ((TreeNodeEx)node.Parent).Block = false;
                        }
                    }
                }
            }

            base.OnAfterCheck(e);
        }
コード例 #3
0
ファイル: clsProfile.cs プロジェクト: Yommy/DiffGen
        public void Apply(ref PatchList lstPatches, ref DiffFile file)
        {
            // Clear patches and inputs
            foreach (DiffPatchBase b in file.xPatches.Values)
            {
                if (b is DiffPatchGroup)
                {
                    foreach (DiffPatch p in ((DiffPatchGroup)b).Patches)
                    {
                        p.Apply = false;
                        foreach (DiffInput i in p.Inputs)
                        {
                            i.Value = null;
                        }
                    }
                }
                else if (b is DiffPatch)
                {
                    ((DiffPatch)b).Apply = false;
                    foreach (DiffInput i in ((DiffPatch)b).Inputs)
                    {
                        i.Value = null;
                    }
                }
            }

            foreach (DiffProfileEntry entry in this.Entries)
            {
                DiffPatch patch = (DiffPatch)file.xPatches[entry.PatchID];
                ((DiffPatch)file.xPatches[entry.PatchID]).Apply = true;

                foreach (DiffProfileInput j in entry.Inputs)
                {
                    foreach (DiffInput k in patch.Inputs)
                    {
                        if (k.Name == j.name)
                        {
                            k.Value = j.value;
                        }
                    }
                }
            }

            // Lets just rebuild the whole thing =D
            lstPatches.Nodes.Clear();
            foreach (KeyValuePair <int, DiffPatchBase> p in file.xPatches)
            {
                if (p.Value is DiffPatchGroup)
                {
                    TreeNodeEx node = new TreeNodeEx(p.Value.Name);
                    node.Tag             = file.xPatches[p.Value.ID]; //is this a reference or a copy? :x
                    node.ActAsRadioGroup = true;

                    foreach (DiffPatch p2 in ((DiffPatchGroup)p.Value).Patches)
                    {
                        TreeNodeEx n = new TreeNodeEx(p2.Name);
                        n.Tag = file.xPatches[p2.ID];
                        if (((DiffPatch)n.Tag).Apply)
                        {
                            n.Checked    = true;
                            node.Checked = true;
                        }
                        node.Nodes.Add(n);
                    }
                    lstPatches.Nodes.Add(node);
                }
                else if (p.Value is DiffPatch && ((DiffPatch)p.Value).GroupID <= 0)
                {
                    TreeNodeEx node = new TreeNodeEx(p.Value.Name);
                    node.Tag = file.xPatches[p.Value.ID];
                    if (((DiffPatch)node.Tag).Apply)
                    {
                        node.Checked = true;
                    }
                    lstPatches.Nodes.Add(node);
                }
            }
        }