Typos and cleaning the code

alphons <alphons@heijden.com> 29 Aug 2025, 17:39
ce284241512cd96348a130aa83b50a7faade5682
7 files changed
  • WireGuardConfigGenerator/Helpers/TreeHelpers.cs
  • WireGuardConfigGenerator/UserControlPeer.Designer.cs
  • WireGuardConfigGenerator/UserControlPeer.cs
  • WireGuardConfigGenerator/UserControlServer.Designer.cs
  • WireGuardConfigGenerator/UserControlServer.cs
  • WireGuardConfigGenerator/UserControlTree.Designer.cs
  • WireGuardConfigGenerator/UserControlTree.cs
diff --git a/WireGuardConfigGenerator/Helpers/TreeHelpers.cs b/WireGuardConfigGenerator/Helpers/TreeHelpers.cs
new file mode 100644
index 0000000..4a01a20
--- /dev/null
+++ b/WireGuardConfigGenerator/Helpers/TreeHelpers.cs
@@ -0,0 +1,126 @@
+using WireGuardConfigGenerator.DataModel;
+
+namespace WireGuardConfigGenerator.Helpers;
+
+public static class TreeHelpers
+{
+ public static void LoadTree(TreeView treeView, Root root)
+ {
+ root.Load();
+
+ treeView.Nodes.Clear();
+ foreach (var group in root.Groups)
+ {
+ var groupNode = new TreeNode(group.Name) { Tag = group };
+ treeView.Nodes.Add(groupNode);
+ foreach (var server in group.Servers)
+ {
+ server.ParentGroup = group;
+ var serverNode = new TreeNode(server.Name) { Tag = server };
+ groupNode.Nodes.Add(serverNode);
+ foreach (var peer in server.Peers)
+ {
+ peer.ParentServer = server;
+ var peerNode = new TreeNode(peer.Name) { Tag = peer };
+ serverNode.Nodes.Add(peerNode);
+ }
+ }
+ }
+ treeView.ExpandAll();
+ }
+
+ public static DialogResult DeleteIt() =>
+ MessageBox.Show("Delete", "Delete this item", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
+
+
+ public static string GetSubnet(string? ipAddress) =>
+ ipAddress == null ? "10.0.0" : ipAddress[..ipAddress.LastIndexOf('.')];
+
+
+ public static void DeleteGroup(Root root, TreeNode node, Group group)
+ {
+ if (DeleteIt() == DialogResult.OK)
+ {
+ root.Groups.Remove(group);
+ node.Remove();
+ }
+ }
+
+ public static void DeleteServer(TreeNode node, Server server)
+ {
+ if (DeleteIt() == DialogResult.OK)
+ {
+ server.ParentGroup?.Servers.Remove(server);
+ node.Remove();
+ }
+ }
+
+ public static void DeletePeer(TreeNode node, Peer peer)
+ {
+ if (DeleteIt() == DialogResult.OK)
+ {
+ peer.ParentServer?.Peers.Remove(peer);
+ node.Remove();
+ }
+ }
+
+ public static void CreateNewGroup(TreeView treeView, Root root)
+ {
+ Group newGroup = new() { Name = "New Group" };
+ root.Groups.Add(newGroup);
+ var treeNode = new TreeNode(newGroup.Name) { Tag = newGroup };
+ treeView.Nodes.Add(treeNode);
+ treeView.SelectedNode = treeNode;
+ }
+
+ public static async Task CreateNewServerAsync(TreeView treeView, Root root, AppSettings settings, TreeNode node, Group group)
+ {
+ string privateKey = await WireGuard.ExecuteAsync("wg genkey");
+ string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
+
+ var offset = group.Servers.Count + 1;
+ var name = $"Server {offset}";
+ Server server = new()
+ {
+ Name = name,
+ ParentGroup = group,
+ ListenPort = settings.ListenPort + (group.Servers.Count * 100) - ((root.Groups.Count - 1) * 1000),
+ Address = settings.Address,
+ Endpoint = settings.Endpoint,
+ PostUp = string.Format(settings.PostUp, name),
+ PrivateKey = privateKey,
+ PubKey = publicKey
+ };
+
+ group.Servers.Add(server);
+ var treeNode = new TreeNode(server.Name) { Tag = server };
+ node.Nodes.Add(treeNode);
+ node.Expand();
+ treeView.SelectedNode = treeNode;
+ }
+
+ public static async Task CreateNewPeerAsync(TreeView treeView, AppSettings settings, TreeNode node, Server server)
+ {
+ string privateKey = await WireGuard.ExecuteAsync("wg genkey");
+ string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
+
+ var offset = server.Peers.Count + 1;
+ var subnet = GetSubnet(server.Address);
+ Peer newPeer = new()
+ {
+ ParentServer = server,
+ Name = $"Peer {offset}",
+ Address = $"{subnet}.{offset + 1}/32",
+ ListenPort = server.ListenPort + offset + 1,
+ AllowedIPs = $"{server.Address.Split('/')[0]}/24",
+ PersistentKeepalive = settings.PersistentKeepalive,
+ PrivateKey = privateKey,
+ PubKey = publicKey
+ };
+ server.Peers.Add(newPeer);
+ var treeNode = new TreeNode(newPeer.Name) { Tag = newPeer };
+ node.Nodes.Add(treeNode);
+ node.Expand();
+ treeView.SelectedNode = treeNode;
+ }
+}
diff --git a/WireGuardConfigGenerator/UserControlPeer.Designer.cs b/WireGuardConfigGenerator/UserControlPeer.Designer.cs
index 24ac761..12ee06a 100644
--- a/WireGuardConfigGenerator/UserControlPeer.Designer.cs
+++ b/WireGuardConfigGenerator/UserControlPeer.Designer.cs
@@ -34,12 +34,13 @@
txtConf = new TextBox();
tabPage1 = new TabPage();
groupBox1 = new GroupBox();
+ button1 = new Button();
comboBox1 = new ComboBox();
txtPersistenKeepAlive = new TextBox();
label8 = new Label();
txtAllowedIPs = new TextBox();
label5 = new Label();
- txtPrivKey = new TextBox();
+ txtPrivateKey = new TextBox();
label1 = new Label();
txtListenPort = new TextBox();
txtAddress = new TextBox();
@@ -52,7 +53,6 @@
buttonEdit = new Button();
lblName = new Label();
label4 = new Label();
- button1 = new Button();
tabControl1.SuspendLayout();
tabPage0.SuspendLayout();
tabPage1.SuspendLayout();
@@ -78,7 +78,7 @@
tabPage0.Location = new Point(4, 24);
tabPage0.Name = "tabPage0";
tabPage0.Padding = new Padding(3);
- tabPage0.Size = new Size(451, 259);
+ tabPage0.Size = new Size(451, 371);
tabPage0.TabIndex = 1;
tabPage0.Text = "peer conf";
tabPage0.UseVisualStyleBackColor = true;
@@ -132,7 +132,7 @@
groupBox1.Controls.Add(label8);
groupBox1.Controls.Add(txtAllowedIPs);
groupBox1.Controls.Add(label5);
- groupBox1.Controls.Add(txtPrivKey);
+ groupBox1.Controls.Add(txtPrivateKey);
groupBox1.Controls.Add(label1);
groupBox1.Controls.Add(txtListenPort);
groupBox1.Controls.Add(txtAddress);
@@ -148,6 +148,16 @@
groupBox1.TabStop = false;
groupBox1.Text = "peer";
//
+ // button1
+ //
+ button1.Location = new Point(73, 80);
+ button1.Name = "button1";
+ button1.Size = new Size(108, 23);
+ button1.TabIndex = 20;
+ button1.Text = "Renew keys";
+ button1.UseVisualStyleBackColor = true;
+ button1.Click += RenewKeys_Click;
+ //
// comboBox1
//
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -192,10 +202,10 @@
//
// txtPrivKey
//
- txtPrivKey.Location = new Point(73, 22);
- txtPrivKey.Name = "txtPrivKey";
- txtPrivKey.Size = new Size(318, 23);
- txtPrivKey.TabIndex = 1;
+ txtPrivateKey.Location = new Point(73, 22);
+ txtPrivateKey.Name = "txtPrivKey";
+ txtPrivateKey.Size = new Size(318, 23);
+ txtPrivateKey.TabIndex = 1;
//
// label1
//
@@ -232,11 +242,11 @@
// label2
//
label2.AutoSize = true;
- label2.Location = new Point(20, 25);
+ label2.Location = new Point(7, 25);
label2.Name = "label2";
- label2.Size = new Size(46, 15);
+ label2.Size = new Size(62, 15);
label2.TabIndex = 0;
- label2.Text = "PrivKey";
+ label2.Text = "PrivateKey";
//
// txtPublicKey
//
@@ -307,16 +317,6 @@
label4.TabIndex = 12;
label4.Text = "Name";
//
- // button1
- //
- button1.Location = new Point(73, 80);
- button1.Name = "button1";
- button1.Size = new Size(108, 23);
- button1.TabIndex = 20;
- button1.Text = "Renew keys";
- button1.UseVisualStyleBackColor = true;
- button1.Click += RenewKeys_Click;
- //
// UserControlPeer
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -341,7 +341,7 @@
private Label lblName;
private Label label4;
private GroupBox groupBox1;
- private TextBox txtPrivKey;
+ private TextBox txtPrivateKey;
private Label label1;
private TextBox txtListenPort;
private TextBox txtAddress;
diff --git a/WireGuardConfigGenerator/UserControlPeer.cs b/WireGuardConfigGenerator/UserControlPeer.cs
index c361ba8..2fbb05c 100644
--- a/WireGuardConfigGenerator/UserControlPeer.cs
+++ b/WireGuardConfigGenerator/UserControlPeer.cs
@@ -88,7 +88,7 @@ public partial class UserControlPeer : UserControl
if (string.IsNullOrWhiteSpace(peer.AllowedIPs))
peer.AllowedIPs = $"{peer.ParentServer?.Address}";
- this.txtPrivKey.Text = peer.PrivateKey;
+ this.txtPrivateKey.Text = peer.PrivateKey;
this.txtPublicKey.Text = peer.PubKey;
this.txtListenPort.Text = peer.ListenPort.ToString();
this.txtAddress.Text = peer.Address?.Split('/')[0];
@@ -103,7 +103,7 @@ public partial class UserControlPeer : UserControl
if (peer == null)
return;
- this.peer.PrivateKey = this.txtPrivKey.Text;
+ this.peer.PrivateKey = this.txtPrivateKey.Text;
this.peer.PubKey = this.txtPublicKey.Text;
this.peer.ListenPort = int.TryParse(this.txtListenPort.Text, out int port) ? port : 0;
this.peer.Address = $"{this.txtAddress.Text}/{this.comboBox1.SelectedItem}";
@@ -131,7 +131,7 @@ public partial class UserControlPeer : UserControl
this.Invoke(() =>
{
- this.txtPrivKey.Text = peer.PrivateKey;
+ this.txtPrivateKey.Text = peer.PrivateKey;
this.txtPublicKey.Text = peer.PubKey;
MakeConfig();
});
diff --git a/WireGuardConfigGenerator/UserControlServer.Designer.cs b/WireGuardConfigGenerator/UserControlServer.Designer.cs
index 76e7a61..fbf263d 100644
--- a/WireGuardConfigGenerator/UserControlServer.Designer.cs
+++ b/WireGuardConfigGenerator/UserControlServer.Designer.cs
@@ -29,7 +29,7 @@
private void InitializeComponent()
{
label1 = new Label();
- txtPrivKey = new TextBox();
+ txtPrivateKey = new TextBox();
txtPublicKey = new TextBox();
label2 = new Label();
txtListenPort = new TextBox();
@@ -44,6 +44,7 @@
txtConf = new TextBox();
tabPage1 = new TabPage();
groupBox1 = new GroupBox();
+ button2 = new Button();
comboBox1 = new ComboBox();
txtEndpoint = new TextBox();
label6 = new Label();
@@ -52,7 +53,6 @@
buttonEdit = new Button();
lblName = new Label();
label7 = new Label();
- button2 = new Button();
tabControl1.SuspendLayout();
tabPage0.SuspendLayout();
tabPage1.SuspendLayout();
@@ -62,18 +62,18 @@
// label1
//
label1.AutoSize = true;
- label1.Location = new Point(21, 59);
+ label1.Location = new Point(8, 59);
label1.Name = "label1";
- label1.Size = new Size(46, 15);
+ label1.Size = new Size(62, 15);
label1.TabIndex = 0;
- label1.Text = "PrivKey";
+ label1.Text = "PrivateKey";
//
- // txtPrivKey
+ // txtPrivateKey
//
- txtPrivKey.Location = new Point(74, 56);
- txtPrivKey.Name = "txtPrivKey";
- txtPrivKey.Size = new Size(318, 23);
- txtPrivKey.TabIndex = 1;
+ txtPrivateKey.Location = new Point(74, 56);
+ txtPrivateKey.Name = "txtPrivateKey";
+ txtPrivateKey.Size = new Size(318, 23);
+ txtPrivateKey.TabIndex = 1;
//
// txtPublicKey
//
@@ -161,7 +161,7 @@
tabPage0.Location = new Point(4, 24);
tabPage0.Name = "tabPage0";
tabPage0.Padding = new Padding(3);
- tabPage0.Size = new Size(410, 376);
+ tabPage0.Size = new Size(410, 425);
tabPage0.TabIndex = 1;
tabPage0.Text = "server conf";
tabPage0.UseVisualStyleBackColor = true;
@@ -213,7 +213,7 @@
groupBox1.Controls.Add(comboBox1);
groupBox1.Controls.Add(txtEndpoint);
groupBox1.Controls.Add(label6);
- groupBox1.Controls.Add(txtPrivKey);
+ groupBox1.Controls.Add(txtPrivateKey);
groupBox1.Controls.Add(label4);
groupBox1.Controls.Add(txtListenPort);
groupBox1.Controls.Add(txtAddress);
@@ -231,6 +231,16 @@
groupBox1.TabStop = false;
groupBox1.Text = "server";
//
+ // button2
+ //
+ button2.Location = new Point(74, 114);
+ button2.Name = "button2";
+ button2.Size = new Size(108, 23);
+ button2.TabIndex = 19;
+ button2.Text = "Renew keys";
+ button2.UseVisualStyleBackColor = true;
+ button2.Click += RenewKeys_Click;
+ //
// comboBox1
//
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -310,16 +320,6 @@
label7.TabIndex = 14;
label7.Text = "Name";
//
- // button2
- //
- button2.Location = new Point(74, 114);
- button2.Name = "button2";
- button2.Size = new Size(108, 23);
- button2.TabIndex = 19;
- button2.Text = "Renew keys";
- button2.UseVisualStyleBackColor = true;
- button2.Click += RenewKeys_Click;
- //
// UserControlServer
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -340,7 +340,7 @@
#endregion
private Label label1;
- private TextBox txtPrivKey;
+ private TextBox txtPrivateKey;
private TextBox txtPublicKey;
private Label label2;
private TextBox txtListenPort;
diff --git a/WireGuardConfigGenerator/UserControlServer.cs b/WireGuardConfigGenerator/UserControlServer.cs
index 0adb110..b65e6f4 100644
--- a/WireGuardConfigGenerator/UserControlServer.cs
+++ b/WireGuardConfigGenerator/UserControlServer.cs
@@ -21,7 +21,7 @@ public partial class UserControlServer : UserControl
return;
this.txtEndpoint.Text = server.Endpoint;
- this.txtPrivKey.Text = server.PrivateKey;
+ this.txtPrivateKey.Text = server.PrivateKey;
this.txtPublicKey.Text = server.PubKey;
this.lblName.Text = server.Name;
this.txtListenPort.Text = server.ListenPort.ToString();
@@ -56,7 +56,7 @@ public partial class UserControlServer : UserControl
return;
this.server.Endpoint = this.txtEndpoint.Text;
- this.server.PrivateKey = this.txtPrivKey.Text;
+ this.server.PrivateKey = this.txtPrivateKey.Text;
this.server.ListenPort = int.TryParse(this.txtListenPort.Text, out int port) ? port : 0;
this.server.Address = $"{this.txtAddress.Text}/{this.comboBox1.SelectedItem}";
this.server.PostUp = this.txtPostUp.Text;
@@ -130,7 +130,7 @@ public partial class UserControlServer : UserControl
this.Invoke(() =>
{
- this.txtPrivKey.Text = server.PrivateKey;
+ this.txtPrivateKey.Text = server.PrivateKey;
this.txtPublicKey.Text = server.PubKey;
MakeConfig();
});
diff --git a/WireGuardConfigGenerator/UserControlTree.Designer.cs b/WireGuardConfigGenerator/UserControlTree.Designer.cs
index ecbf697..69a22a5 100644
--- a/WireGuardConfigGenerator/UserControlTree.Designer.cs
+++ b/WireGuardConfigGenerator/UserControlTree.Designer.cs
@@ -44,7 +44,6 @@
treeView1.TabIndex = 0;
treeView1.AfterLabelEdit += TreeView_AfterLabelEdit;
treeView1.AfterSelect += TreeView_AfterSelect;
- treeView1.DoubleClick += TreeView_DoubleClick;
treeView1.KeyDown += TreeView_KeyDown;
treeView1.MouseDown += TreeView_MouseDown;
//
diff --git a/WireGuardConfigGenerator/UserControlTree.cs b/WireGuardConfigGenerator/UserControlTree.cs
index 98f12a5..c0f89d7 100644
--- a/WireGuardConfigGenerator/UserControlTree.cs
+++ b/WireGuardConfigGenerator/UserControlTree.cs
@@ -1,5 +1,4 @@
using System.Text.Json;
-using System.Xml.Linq;
using WireGuardConfigGenerator.DataModel;
using WireGuardConfigGenerator.Helpers;
@@ -25,115 +24,9 @@ public partial class UserControlTree : UserControl
if (this.ParentForm is Form1 form)
form.FormClosing += (s, e) => root.Save();
- LoadTree();
+ TreeHelpers.LoadTree(this.treeView1, root);
}
- private void LoadTree()
- {
- root.Load();
-
- this.treeView1.Nodes.Clear();
- foreach (var group in root.Groups)
- {
- var groupNode = new TreeNode(group.Name) { Tag = group };
- this.treeView1.Nodes.Add(groupNode);
- foreach (var server in group.Servers)
- {
- server.ParentGroup = group;
- var serverNode = new TreeNode(server.Name) { Tag = server };
- groupNode.Nodes.Add(serverNode);
- foreach (var peer in server.Peers)
- {
- peer.ParentServer = server;
- var peerNode = new TreeNode(peer.Name) { Tag = peer };
- serverNode.Nodes.Add(peerNode);
- }
- }
- }
- this.treeView1.ExpandAll();
- }
-
- private static DialogResult DeleteIt() =>
- MessageBox.Show("Delete", "Delete it", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
-
-
- private static string GetSubnet(string? ipAddress) =>
- ipAddress == null ? "10.0.0" : ipAddress[..ipAddress.LastIndexOf('.')];
-
-
- private static void DeleteGroup(Root root, TreeNode node, Group group)
- {
- if (DeleteIt() == DialogResult.OK)
- {
- root.Groups.Remove(group);
- node.Remove();
- }
- }
-
- private static void DeleteServer(TreeNode node, Server server)
- {
- if (DeleteIt() == DialogResult.OK)
- {
- server.ParentGroup?.Servers.Remove(server);
- node.Remove();
- }
- }
-
- private static void DeletePeer(TreeNode node, Peer peer)
- {
- if (DeleteIt() == DialogResult.OK)
- {
- peer.ParentServer?.Peers.Remove(peer);
- node.Remove();
- }
- }
-
- private async Task CreateNewServerAsync(TreeNode node, Group group)
- {
- string privateKey = await WireGuard.ExecuteAsync("wg genkey");
- string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
-
- var offset = group.Servers.Count + 1;
- var name = $"Server {offset}";
- Server server = new()
- {
- Name = name,
- ParentGroup = group,
- ListenPort = Settings.ListenPort + (group.Servers.Count * 100) - ((this.root.Groups.Count - 1) * 1000),
- Address = Settings.Address,
- Endpoint = Settings.Endpoint,
- PostUp = string.Format(Settings.PostUp, name),
- PrivateKey = privateKey,
- PubKey = publicKey
- };
-
- group.Servers.Add(server);
- node.Nodes.Add(new TreeNode(server.Name) { Tag = server });
- node.Expand();
- }
-
- private async Task CreateNewPeerAsync(TreeNode node, Server server)
- {
- string privateKey = await WireGuard.ExecuteAsync("wg genkey");
- string publicKey = await WireGuard.ExecuteAsync($"echo {privateKey} | wg pubkey");
-
- var offset = server.Peers.Count + 1;
- var subnet = GetSubnet(server.Address);
- Peer newPeer = new()
- {
- ParentServer = server,
- Name = $"Peer {offset}",
- Address = $"{subnet}.{offset + 1}/32",
- ListenPort = server.ListenPort + offset + 1,
- AllowedIPs = $"{server.Address.Split('/')[0]}/24",
- PersistentKeepalive = Settings.PersistentKeepalive,
- PrivateKey = privateKey,
- PubKey = publicKey
- };
- server.Peers.Add(newPeer);
- node.Nodes.Add(new TreeNode(newPeer.Name) { Tag = newPeer });
- node.Expand();
- }
private void ShowContextMenu(Point location)
{
@@ -141,52 +34,46 @@ public partial class UserControlTree : UserControl
if (this.treeView1.SelectedNode is not TreeNode node)
{
- contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Group", null, (s, e) =>
- {
- Group newGroup = new() { Name = "New Group" };
- root.Groups.Add(newGroup);
- this.treeView1.Nodes.Add(new TreeNode(newGroup.Name) { Tag = newGroup });
- }));
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Group", null, (s, e) => TreeHelpers.CreateNewGroup(this.treeView1, root)));
}
else if (node.Tag is Group group)
{
- contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Server", null, async (s, e) => await CreateNewServerAsync(node, group)));
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Server", null, async (s, e) => await TreeHelpers.CreateNewServerAsync(this.treeView1, root, Settings, node, group)));
if (group.Servers.Count == 0)
- contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Group", null, (s, e) => DeleteGroup(root, node, group)));
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Group", null, (s, e) => TreeHelpers.DeleteGroup(root, node, group)));
}
else if (node.Tag is Server server)
{
- contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Peer", null, async (s, e) => await CreateNewPeerAsync(node, server)));
-
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Add Peer", null, async (s, e) => await TreeHelpers.CreateNewPeerAsync(this.treeView1, Settings, node, server)));
+
if (server.Peers.Count == 0)
- contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Server", null, (s, e) => DeleteServer(node, server)));
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Server", null, (s, e) => TreeHelpers.DeleteServer(node, server)));
}
else if (node.Tag is Peer peer)
- contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Peer", null, (s, e) => DeletePeer(node, peer)));
+ contextMenuStrip1.Items.Add(new ToolStripMenuItem("Delete Peer", null, (s, e) => TreeHelpers.DeletePeer(node, peer)));
this.contextMenuStrip1.Show(this.treeView1, location);
}
private void TreeView_AfterSelect(object sender, TreeViewEventArgs e)
+ {
+ ShowInformation(e.Node);
+ }
+
+ private void ShowInformation(TreeNode? node)
{
if (this.ParentForm is not Form1 form)
return;
var panel = form.GetPanel();
+
panel.Controls.Clear();
- if (e.Node?.Tag is Peer peer)
- {
+ if (node?.Tag is Peer peer)
panel.Controls.Add(new UserControlPeer(peer) { Dock = DockStyle.Fill });
- return;
- }
-
- if (e.Node?.Tag is Server server)
- {
+ else if (node?.Tag is Server server)
panel.Controls.Add(new UserControlServer(server) { Dock = DockStyle.Fill });
- return;
- }
}
private void TreeView_MouseDown(object sender, MouseEventArgs e)
@@ -212,28 +99,20 @@ public partial class UserControlTree : UserControl
}
if (e.Node?.Tag is Group group)
+ {
group.Name = e.Label;
+ }
else if (e.Node?.Tag is Server server)
{
server.Name = e.Label;
server.PostUp = string.Format(Settings.PostUp, server.Name);
+ ShowInformation(e.Node);
}
- else
- if (e.Node?.Tag is Peer peer)
+ else if (e.Node?.Tag is Peer peer)
+ {
peer.Name = e.Label;
- }
-
- private void TreeView_DoubleClick(object sender, EventArgs e)
- {
- var treeNode = this.treeView1.SelectedNode;
-
- if (treeNode == null)
- return;
-
- if (treeNode.Tag is not Peer peer)
- return;
-
-
+ ShowInformation(e.Node);
+ }
}
private void TreeView_KeyDown(object sender, KeyEventArgs e)
@@ -245,10 +124,10 @@ public partial class UserControlTree : UserControl
return;
if (node.Tag is Group group && group.Servers.Count == 0)
- DeleteGroup(root, node, group);
+ TreeHelpers.DeleteGroup(root, node, group);
else if (node.Tag is Server server && server.Peers.Count == 0)
- DeleteServer(node, server);
+ TreeHelpers.DeleteServer(node, server);
else if (node.Tag is Peer peer)
- DeletePeer(node, peer);
+ TreeHelpers.DeletePeer(node, peer);
}
}