diff --git a/TGControlPanel/InstanceSelector.Designer.cs b/TGControlPanel/InstanceSelector.Designer.cs index 4b07446a17..cfaf0a5ab5 100644 --- a/TGControlPanel/InstanceSelector.Designer.cs +++ b/TGControlPanel/InstanceSelector.Designer.cs @@ -36,6 +36,8 @@ this.RenameInstanceButton = new System.Windows.Forms.Button(); this.DetachInstanceButton = new System.Windows.Forms.Button(); this.RefreshButton = new System.Windows.Forms.Button(); + this.ConnectButton = new System.Windows.Forms.Button(); + this.EnabledCheckBox = new System.Windows.Forms.CheckBox(); this.SuspendLayout(); // // InstanceListBox @@ -46,6 +48,7 @@ this.InstanceListBox.Name = "InstanceListBox"; this.InstanceListBox.Size = new System.Drawing.Size(339, 238); this.InstanceListBox.TabIndex = 0; + this.InstanceListBox.SelectedIndexChanged += new System.EventHandler(this.InstanceListBox_SelectedIndexChanged); // // CreateInstanceButton // @@ -94,7 +97,7 @@ // RefreshButton // this.RefreshButton.Anchor = System.Windows.Forms.AnchorStyles.Right; - this.RefreshButton.Location = new System.Drawing.Point(358, 226); + this.RefreshButton.Location = new System.Drawing.Point(358, 195); this.RefreshButton.Name = "RefreshButton"; this.RefreshButton.Size = new System.Drawing.Size(148, 25); this.RefreshButton.TabIndex = 19; @@ -102,12 +105,37 @@ this.RefreshButton.UseVisualStyleBackColor = true; this.RefreshButton.Click += new System.EventHandler(this.RefreshButton_Click); // + // ConnectButton + // + this.ConnectButton.Anchor = System.Windows.Forms.AnchorStyles.Right; + this.ConnectButton.Location = new System.Drawing.Point(358, 226); + this.ConnectButton.Name = "ConnectButton"; + this.ConnectButton.Size = new System.Drawing.Size(148, 25); + this.ConnectButton.TabIndex = 20; + this.ConnectButton.Text = "Connect"; + this.ConnectButton.UseVisualStyleBackColor = true; + this.ConnectButton.Click += new System.EventHandler(this.ConnectButton_Click); + // + // EnabledCheckBox + // + this.EnabledCheckBox.AutoSize = true; + this.EnabledCheckBox.ForeColor = System.Drawing.Color.White; + this.EnabledCheckBox.Location = new System.Drawing.Point(396, 149); + this.EnabledCheckBox.Name = "EnabledCheckBox"; + this.EnabledCheckBox.Size = new System.Drawing.Size(65, 17); + this.EnabledCheckBox.TabIndex = 21; + this.EnabledCheckBox.Text = "Enabled"; + this.EnabledCheckBox.UseVisualStyleBackColor = true; + this.EnabledCheckBox.CheckedChanged += new System.EventHandler(this.EnabledCheckBox_CheckedChanged); + // // InstanceSelector // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34))))); this.ClientSize = new System.Drawing.Size(518, 261); + this.Controls.Add(this.EnabledCheckBox); + this.Controls.Add(this.ConnectButton); this.Controls.Add(this.RefreshButton); this.Controls.Add(this.DetachInstanceButton); this.Controls.Add(this.RenameInstanceButton); @@ -119,6 +147,7 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Server Instances"; this.ResumeLayout(false); + this.PerformLayout(); } @@ -130,5 +159,7 @@ private System.Windows.Forms.Button RenameInstanceButton; private System.Windows.Forms.Button DetachInstanceButton; private System.Windows.Forms.Button RefreshButton; + private System.Windows.Forms.Button ConnectButton; + private System.Windows.Forms.CheckBox EnabledCheckBox; } } \ No newline at end of file diff --git a/TGControlPanel/InstanceSelector.cs b/TGControlPanel/InstanceSelector.cs index 15f3f9e360..318b3d5c30 100644 --- a/TGControlPanel/InstanceSelector.cs +++ b/TGControlPanel/InstanceSelector.cs @@ -8,7 +8,7 @@ using TGServiceInterface.Components; namespace TGControlPanel { /// - /// Form used for managing manipulation functions + /// Form used for managing manipulation functions /// partial class InstanceSelector : CountedForm { @@ -20,6 +20,11 @@ namespace TGControlPanel /// List of from /// IList InstanceData; + /// + /// Used for modifying without invoking its side effects + /// + bool UpdatingEnabledCheckbox = false; + public InstanceSelector(IInterface I) { InitializeComponent(); @@ -48,15 +53,13 @@ namespace TGControlPanel } /// - /// Connects to a if it is double clicked in + /// Connects to a if it is double clicked in /// /// The sender of the event /// The void InstanceListBox_MouseDoubleClick(object sender, MouseEventArgs e) { - var index = InstanceListBox.IndexFromPoint(e.Location); - if (index != ListBox.NoMatches) - TryConnectToInstance(InstanceData[index].Name); + TryConnectToIndexInstance(InstanceListBox.IndexFromPoint(e.Location)); } /// @@ -88,15 +91,26 @@ namespace TGControlPanel }); foreach(var I in InstanceData) InstanceListBox.Items.Add(String.Format("{0}: {1} - {2} - {3}", I.LoggingID, I.Name, I.Path, I.Enabled ? "ONLINE" : "OFFLINE")); + var HasServerAdmin = masterInterface.ConnectionStatus().HasFlag(ConnectivityLevel.Administrator); + CreateInstanceButton.Enabled = HasServerAdmin; + ImportInstanceButton.Enabled = HasServerAdmin; + RenameInstanceButton.Enabled = HasServerAdmin; + DetachInstanceButton.Enabled = HasServerAdmin; + EnabledCheckBox.Enabled = HasServerAdmin; + if(InstanceData.Count > 0) + InstanceListBox.SelectedIndex = 0; } /// - /// Tries to start a for a given + /// Tries to start a for a given /// - /// The name of the to connect to - async void TryConnectToInstance(string instanceName) + /// The of to connect to + async void TryConnectToIndexInstance(int index) { - if(ControlPanel.InstancesInUse.TryGetValue(instanceName, out ControlPanel activeCP)) + if (index == ListBox.NoMatches) + return; + var instanceName = InstanceData[index].Name; + if (ControlPanel.InstancesInUse.TryGetValue(instanceName, out ControlPanel activeCP)) { activeCP.BringToFront(); return; @@ -136,7 +150,7 @@ namespace TGControlPanel if (MessageBox.Show(String.Format("This will dissociate the server instance at \"{0}\"! Are you sure?", imd.Path), "Instance Detach", MessageBoxButtons.YesNo) != DialogResult.Yes) return; string res = null; - await WrapServerOp(() => { res = masterInterface.GetServiceComponent().DetachInstance(imd.Name); }); + await WrapServerOp(() => res = masterInterface.GetServiceComponent().DetachInstance(imd.Name)); if (res != null) MessageBox.Show(res); RefreshInstances(); @@ -168,7 +182,7 @@ namespace TGControlPanel if (imd.Enabled && MessageBox.Show(String.Format("This will temporarily offline the server instance! Are you sure?", imd.Path), "Instance Restart", MessageBoxButtons.YesNo) != DialogResult.Yes) return; string res = null; - await WrapServerOp(() => { res = masterInterface.GetServiceComponent().RenameInstance(imd.Name, new_name); }); + await WrapServerOp(() => res = masterInterface.GetServiceComponent().RenameInstance(imd.Name, new_name)); if (res != null) MessageBox.Show(res); RefreshInstances(); @@ -185,7 +199,7 @@ namespace TGControlPanel if (instance_path == null) return; string res = null; - await WrapServerOp(() => { res = masterInterface.GetServiceComponent().ImportInstance(instance_path); }); + await WrapServerOp(() => res = masterInterface.GetServiceComponent().ImportInstance(instance_path)); if (res != null) MessageBox.Show(res); RefreshInstances(); @@ -205,10 +219,54 @@ namespace TGControlPanel if (instance_path == null) return; string res = null; - await WrapServerOp(() => { res = masterInterface.GetServiceComponent().CreateInstance(instance_name, instance_path); }); + await WrapServerOp(() => res = masterInterface.GetServiceComponent().CreateInstance(instance_name, instance_path)); if (res != null) MessageBox.Show(res); RefreshInstances(); } + + /// + /// Attempts to connect the user to an based on the of + /// + /// The sender of the event + /// The + private void ConnectButton_Click(object sender, EventArgs e) + { + TryConnectToIndexInstance(InstanceListBox.SelectedIndex); + } + + /// + /// Prompts the user if they want to call to either online or offline an based on its current state + /// + /// The sender of the event + /// The + async void EnabledCheckBox_CheckedChanged(object sender, EventArgs e) + { + if (UpdatingEnabledCheckbox) + return; + var enabling = EnabledCheckBox.Checked; + if (MessageBox.Show(String.Format("Are you sure you want to {0} this instance?", enabling ? "online" : "offline"), "Instance Status Change", MessageBoxButtons.YesNo) != DialogResult.Yes) + return; + string res = null; + await WrapServerOp(() => res = masterInterface.GetServiceComponent().SetInstanceEnabled(InstanceData[InstanceListBox.SelectedIndex].Name, enabling)); + if (res != null) + MessageBox.Show(res); + } + + /// + /// Update based on the selected 's property + /// + /// The sender of the event + /// The + void InstanceListBox_SelectedIndexChanged(object sender, EventArgs e) + { + var index = InstanceListBox.SelectedIndex; + if (index != ListBox.NoMatches) + { + UpdatingEnabledCheckbox = true; + EnabledCheckBox.Checked = InstanceData[index].Enabled; + UpdatingEnabledCheckbox = false; + } + } } }