Skip to content

Commit

Permalink
Added collapse and expand button for tree hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
Myrkie committed Feb 28, 2023
1 parent 397abd8 commit 9950556
Showing 1 changed file with 70 additions and 12 deletions.
82 changes: 70 additions & 12 deletions UpuGui/UpuGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public sealed class UpuGui : Form
private Button _btnSelectInputFile;
private Button _btnUnpack;
private Button _btnAbout;
private Button _btnExpand;
private Button _btnCollapse;
#pragma warning disable CS0649
private IContainer components;
#pragma warning restore CS0649
Expand All @@ -43,6 +45,8 @@ private UpuGui()
_btnAbout!.Enabled = true;
_btnSelectAll!.Enabled = false;
_btnDeselectAll!.Enabled = false;
_btnExpand!.Enabled = false;
_btnCollapse!.Enabled = false;
_progressBar!.Visible = false;
_treeViewContents!.CheckBoxes = true;
AllowDrop = true;
Expand Down Expand Up @@ -129,6 +133,8 @@ private void ReadInputFileWorkerCompleted(object sender, RunWorkerCompletedEvent
_btnUnpack.Enabled = true;
_btnSelectAll.Enabled = true;
_btnDeselectAll.Enabled = true;
_btnExpand.Enabled = true;
_btnCollapse.Enabled = true;
_btnExit.Enabled = true;
}
// iterate for the next person as a warning to not change what isn't broken
Expand Down Expand Up @@ -301,6 +307,8 @@ private void InitializeComponent()
_btnUnpack = new Button();
_btnSelectInputFile = new Button();
_groupBox = new GroupBox();
_btnExpand = new Button();
_btnCollapse = new Button();
_btnDeselectAll = new Button();
_btnSelectAll = new Button();
_treeViewContents = new TreeView();
Expand All @@ -321,7 +329,7 @@ private void InitializeComponent()
_btnUnpack.Margin = new Padding(4, 4, 4, 4);
_btnUnpack.Name = "_btnUnpack";
_btnUnpack.Size = new Size(149, 38);
_btnUnpack.TabIndex = 3;
_btnUnpack.TabIndex = 8;
_btnUnpack.Text = @"Unpack now";
_btnUnpack.UseVisualStyleBackColor = true;
#pragma warning disable CS8622
Expand All @@ -337,7 +345,7 @@ private void InitializeComponent()
_btnSelectInputFile.Margin = new Padding(4, 4, 4, 4);
_btnSelectInputFile.Name = "_btnSelectInputFile";
_btnSelectInputFile.Size = new Size(149, 38);
_btnSelectInputFile.TabIndex = 6;
_btnSelectInputFile.TabIndex = 7;
_btnSelectInputFile.Text = @"Select Input File";
_btnSelectInputFile.UseVisualStyleBackColor = true;
#pragma warning disable CS8622
Expand All @@ -349,6 +357,8 @@ private void InitializeComponent()
_groupBox.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom)
| AnchorStyles.Left)
| AnchorStyles.Right;
_groupBox.Controls.Add(_btnExpand);
_groupBox.Controls.Add(_btnCollapse);
_groupBox.Controls.Add(_btnDeselectAll);
_groupBox.Controls.Add(_btnSelectAll);
_groupBox.Controls.Add(_treeViewContents);
Expand All @@ -357,10 +367,44 @@ private void InitializeComponent()
_groupBox.Name = "_groupBox";
_groupBox.Padding = new Padding(4, 4, 4, 4);
_groupBox.Size = new Size(638, 375);
_groupBox.TabIndex = 7;
_groupBox.TabIndex = 3;
_groupBox.TabStop = false;
// ReSharper disable once StringLiteralTypo
_groupBox.Text = @"Unitypackage File";
//
// _btnExpand
//
_btnExpand.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
_btnExpand.Image = (Image)resources.GetObject("_btnExpand.Image");
_btnExpand.ImageAlign = ContentAlignment.MiddleLeft;
_btnExpand.Location = new Point(8, 341);
_btnExpand.Margin = new Padding(4);
_btnExpand.Name = "_btnExpand";
_btnExpand.Size = new Size(70, 26);
_btnExpand.TabIndex = 1;
_btnExpand.Text = @"Expand";
_btnExpand.TextAlign = ContentAlignment.MiddleRight;
_btnExpand.UseVisualStyleBackColor = true;
#pragma warning disable CS8622
_btnExpand.Click += BtnExpand_Click_1;
#pragma warning restore CS8622
//
// _btnCollapse
//
_btnCollapse.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
_btnCollapse.Image = (Image)resources.GetObject("_btnCollapse.Image");
_btnCollapse.ImageAlign = ContentAlignment.MiddleLeft;
_btnCollapse.Location = new Point(80, 341);
_btnCollapse.Margin = new Padding(4);
_btnCollapse.Name = "_btnCollapse";
_btnCollapse.Size = new Size(70, 26);
_btnCollapse.TabIndex = 2;
_btnCollapse.Text = @"Collapse";
_btnCollapse.TextAlign = ContentAlignment.MiddleRight;
_btnCollapse.UseVisualStyleBackColor = true;
#pragma warning disable CS8622
_btnCollapse.Click += BtnCollapse_Click_1;
#pragma warning restore CS8622
//
// _btnDeselectAll
//
Expand All @@ -371,7 +415,7 @@ private void InitializeComponent()
_btnDeselectAll.Margin = new Padding(4, 4, 4, 4);
_btnDeselectAll.Name = "_btnDeselectAll";
_btnDeselectAll.Size = new Size(70, 26);
_btnDeselectAll.TabIndex = 7;
_btnDeselectAll.TabIndex = 4;
_btnDeselectAll.Text = @"None";
_btnDeselectAll.TextAlign = ContentAlignment.MiddleRight;
_btnDeselectAll.UseVisualStyleBackColor = true;
Expand All @@ -388,7 +432,7 @@ private void InitializeComponent()
_btnSelectAll.Margin = new Padding(4, 4, 4, 4);
_btnSelectAll.Name = "_btnSelectAll";
_btnSelectAll.Size = new Size(70, 26);
_btnSelectAll.TabIndex = 6;
_btnSelectAll.TabIndex = 3;
_btnSelectAll.Text = @"All";
_btnSelectAll.TextAlign = ContentAlignment.MiddleRight;
_btnSelectAll.UseVisualStyleBackColor = true;
Expand All @@ -407,7 +451,7 @@ private void InitializeComponent()
_treeViewContents.Margin = new Padding(4, 4, 4, 4);
_treeViewContents.Name = "_treeViewContents";
_treeViewContents.Size = new Size(624, 312);
_treeViewContents.TabIndex = 5;
_treeViewContents.TabIndex = 8;
#pragma warning disable CS8622
_treeViewContents.AfterSelect += treeViewContents_AfterSelect;
_treeViewContents.AfterCheck += treeViewContents_AfterSelect;
Expand All @@ -423,7 +467,7 @@ private void InitializeComponent()
_btnExit.Margin = new Padding(4, 4, 4, 4);
_btnExit.Name = "_btnExit";
_btnExit.Size = new Size(149, 38);
_btnExit.TabIndex = 8;
_btnExit.TabIndex = 9;
_btnExit.Text = @"Exit";
_btnExit.UseVisualStyleBackColor = true;
#pragma warning disable CS8622
Expand All @@ -436,7 +480,7 @@ private void InitializeComponent()
_statusStrip1.Name = "_statusStrip1";
_statusStrip1.Padding = new Padding(1, 0, 16, 0);
_statusStrip1.Size = new Size(666, 22);
_statusStrip1.TabIndex = 9;
_statusStrip1.TabIndex = 10;
_statusStrip1.Text = @"statusStrip1";
//
// _progressBar
Expand All @@ -449,7 +493,7 @@ private void InitializeComponent()
_progressBar.Name = "_progressBar";
_progressBar.Size = new Size(631, 16);
_progressBar.Style = ProgressBarStyle.Marquee;
_progressBar.TabIndex = 10;
_progressBar.TabIndex = 11;
//
// _btnRegisterUnregister
//
Expand All @@ -458,7 +502,7 @@ private void InitializeComponent()
_btnRegisterUnregister.Margin = new Padding(4, 4, 4, 4);
_btnRegisterUnregister.Name = "_btnRegisterUnregister";
_btnRegisterUnregister.Size = new Size(306, 26);
_btnRegisterUnregister.TabIndex = 8;
_btnRegisterUnregister.TabIndex = 5;
_btnRegisterUnregister.Text = @"Register Context Menu Handler";
_btnRegisterUnregister.UseVisualStyleBackColor = true;
#pragma warning disable CS8622
Expand All @@ -474,7 +518,7 @@ private void InitializeComponent()
_btnAbout.Margin = new Padding(4);
_btnAbout.Name = "_btnAbout";
_btnAbout.Size = new Size(100, 31);
_btnAbout.TabIndex = 11;
_btnAbout.TabIndex = 6;
_btnAbout.Text = @"About";
_btnAbout.UseVisualStyleBackColor = true;
#pragma warning disable CS8622
Expand Down Expand Up @@ -568,7 +612,6 @@ private void CheckNode(TreeNode node, bool isChecked)
CheckNode(childNode, isChecked);
}
}

private void btnExit_Click_1(object sender, EventArgs e)
{
Application.Exit();
Expand All @@ -577,5 +620,20 @@ private void btnAbout_Click_1(object sender, EventArgs e)
{
Process.Start("cmd","/c start https://github.com/Myrkie/UpuGui");
}
private void BtnExpand_Click_1(object sender, EventArgs e)
{
foreach (var node in Collect(_treeViewContents.Nodes))
{
node.ExpandAll();
}
}

private void BtnCollapse_Click_1(object sender, EventArgs e)
{
foreach (var node in Collect(_treeViewContents.Nodes))
{
node.Collapse();
}
}
}
}

0 comments on commit 9950556

Please sign in to comment.