fix TreeView checkbox bug, fix all selection button

This commit is contained in:
pointfeev 2021-11-22 02:36:41 -05:00
parent 4ffca7c807
commit ba897cc40f
No known key found for this signature in database
GPG key ID: AA14DC36C4D7D13C
4 changed files with 24 additions and 12 deletions

View file

@ -37,7 +37,7 @@ namespace CreamInstaller
this.updateButton = new System.Windows.Forms.Button(); this.updateButton = new System.Windows.Forms.Button();
this.ignoreButton = new System.Windows.Forms.Button(); this.ignoreButton = new System.Windows.Forms.Button();
this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.changelogTreeView = new System.Windows.Forms.TreeView(); this.changelogTreeView = new ProgramSelectionTreeView();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1
@ -118,7 +118,7 @@ namespace CreamInstaller
private Button updateButton; private Button updateButton;
private Button ignoreButton; private Button ignoreButton;
private ProgressBar progressBar1; private ProgressBar progressBar1;
private TreeView changelogTreeView; private ProgramSelectionTreeView changelogTreeView;
} }
} }

View file

@ -37,7 +37,7 @@ namespace CreamInstaller
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.noneFoundLabel = new System.Windows.Forms.Label(); this.noneFoundLabel = new System.Windows.Forms.Label();
this.treeView1 = new System.Windows.Forms.TreeView(); this.treeView1 = new ProgramSelectionTreeView();
this.allCheckBox = new System.Windows.Forms.CheckBox(); this.allCheckBox = new System.Windows.Forms.CheckBox();
this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();

View file

@ -121,7 +121,6 @@ namespace CreamInstaller
private void GetCreamApiApplicablePrograms(IProgress<int> progress) private void GetCreamApiApplicablePrograms(IProgress<int> progress)
{ {
treeView1.AfterCheck -= OnTreeViewNodeCheckedChanged;
int cur = 0; int cur = 0;
if (Program.Canceled) return; if (Program.Canceled) return;
List<Tuple<int, string, string, int, string>> applicablePrograms = new(); List<Tuple<int, string, string, int, string>> applicablePrograms = new();
@ -234,7 +233,6 @@ namespace CreamInstaller
task.Wait(); task.Wait();
} }
progress.Report(RunningTasks.Count); progress.Report(RunningTasks.Count);
treeView1.AfterCheck += OnTreeViewNodeCheckedChanged;
} }
private bool validated = false; private bool validated = false;
@ -314,22 +312,19 @@ namespace CreamInstaller
private void OnTreeViewNodeCheckedChanged(object sender, TreeViewEventArgs e) private void OnTreeViewNodeCheckedChanged(object sender, TreeViewEventArgs e)
{ {
if (e.Action == TreeViewAction.Unknown) return;
ProgramSelection selection = ProgramSelection.FromName(e.Node.Text); ProgramSelection selection = ProgramSelection.FromName(e.Node.Text);
if (selection is null) if (selection is null)
{ {
ProgramSelection.FromName(e.Node.Parent.Text).ToggleDlc(e.Node.Text, e.Node.Checked); ProgramSelection.FromName(e.Node.Parent.Text).ToggleDlc(e.Node.Text, e.Node.Checked);
treeView1.AfterCheck -= OnTreeViewNodeCheckedChanged;
e.Node.Parent.Checked = e.Node.Parent.Nodes.Cast<TreeNode>().ToList().Any(treeNode => treeNode.Checked); e.Node.Parent.Checked = e.Node.Parent.Nodes.Cast<TreeNode>().ToList().Any(treeNode => treeNode.Checked);
treeView1.AfterCheck += OnTreeViewNodeCheckedChanged;
} }
else else
{ {
if (selection.AllSteamDlc.Any()) if (selection.AllSteamDlc.Any())
{ {
selection.ToggleAllDlc(e.Node.Checked); selection.ToggleAllDlc(e.Node.Checked);
treeView1.AfterCheck -= OnTreeViewNodeCheckedChanged;
e.Node.Nodes.Cast<TreeNode>().ToList().ForEach(treeNode => treeNode.Checked = e.Node.Checked); e.Node.Nodes.Cast<TreeNode>().ToList().ForEach(treeNode => treeNode.Checked = e.Node.Checked);
treeView1.AfterCheck += OnTreeViewNodeCheckedChanged;
} }
else else
{ {
@ -467,11 +462,14 @@ namespace CreamInstaller
{ {
bool shouldCheck = false; bool shouldCheck = false;
foreach (TreeNode treeNode in treeNodes) foreach (TreeNode treeNode in treeNodes)
if (treeNode.Parent is null && !treeNode.Checked) {
shouldCheck = true;
foreach (TreeNode treeNode in treeNodes)
if (treeNode.Parent is null) if (treeNode.Parent is null)
{
if (!treeNode.Checked) shouldCheck = true;
treeNode.Checked = shouldCheck; treeNode.Checked = shouldCheck;
OnTreeViewNodeCheckedChanged(null, new(treeNode, TreeViewAction.ByMouse));
}
}
allCheckBox.Checked = shouldCheck; allCheckBox.Checked = shouldCheck;
} }
} }

View file

@ -0,0 +1,14 @@
using System;
using System.Windows.Forms;
namespace CreamInstaller
{
public class ProgramSelectionTreeView : TreeView
{
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x203) m.Result = IntPtr.Zero;
else base.WndProc(ref m);
}
}
}