diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index a3c7a4a8..d5a02f6b 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -73,9 +73,10 @@ namespace Shadowsocks.Controller return config.GetCurrentServer(); } + // always return copy public Configuration GetConfiguration() { - return config; + return Configuration.Load(); } diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 3ba8eb77..5efc2805 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -27,7 +27,7 @@ namespace Shadowsocks.Model } else { - return getDefaultServer(); + return GetDefaultServer(); } } @@ -59,7 +59,7 @@ namespace Shadowsocks.Model index = 0, configs = new List() { - getDefaultServer() + GetDefaultServer() } }; } @@ -83,7 +83,7 @@ namespace Shadowsocks.Model } } - private static Server getDefaultServer() + public static Server GetDefaultServer() { return new Server() { diff --git a/shadowsocks-csharp/View/ConfigForm.Designer.cs b/shadowsocks-csharp/View/ConfigForm.Designer.cs index c439a565..765aa5d6 100755 --- a/shadowsocks-csharp/View/ConfigForm.Designer.cs +++ b/shadowsocks-csharp/View/ConfigForm.Designer.cs @@ -316,6 +316,7 @@ this.DeleteButton.TabIndex = 4; this.DeleteButton.Text = "&Delete"; this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); // // AddButton // @@ -325,6 +326,7 @@ this.AddButton.TabIndex = 3; this.AddButton.Text = "&Add"; this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); // // groupBox1 // diff --git a/shadowsocks-csharp/View/ConfigForm.cs b/shadowsocks-csharp/View/ConfigForm.cs index 8827aa48..4b5d4e13 100755 --- a/shadowsocks-csharp/View/ConfigForm.cs +++ b/shadowsocks-csharp/View/ConfigForm.cs @@ -97,17 +97,22 @@ namespace Shadowsocks.View EncryptionSelect.Text = server.method == null ? "aes-256-cfb" : server.method; } - private void loadCurrentConfiguration() + private void loadConfiguration(Configuration configuration) { - modifiedConfiguration = controller.GetConfiguration(); - ServersListBox.Items.Clear(); foreach (Server server in modifiedConfiguration.configs) { - ServersListBox.Items.Add(server.server); + ServersListBox.Items.Add(string.IsNullOrEmpty(server.server) ? "New server" : server.server); } + } + + private void loadCurrentConfiguration() + { + modifiedConfiguration = controller.GetConfiguration(); + loadConfiguration(modifiedConfiguration); + oldSelectedIndex = modifiedConfiguration.index; ServersListBox.SelectedIndex = modifiedConfiguration.index; - oldSelectedIndex = ServersListBox.SelectedIndex; + loadSelectedServer(); enableItem.Checked = modifiedConfiguration.enabled; } @@ -128,7 +133,7 @@ namespace Shadowsocks.View { if (oldSelectedIndex == ServersListBox.SelectedIndex) { - // we are moving back to oldSelectedIndex + // we are moving back to oldSelectedIndex or doing a force move return; } if (!saveOldSelectedServer()) @@ -141,6 +146,24 @@ namespace Shadowsocks.View oldSelectedIndex = ServersListBox.SelectedIndex; } + private void AddButton_Click(object sender, EventArgs e) + { + if (!saveOldSelectedServer()) + { + return; + } + Server server = Configuration.GetDefaultServer(); + modifiedConfiguration.configs.Add(server); + loadConfiguration(modifiedConfiguration); + ServersListBox.SelectedIndex = modifiedConfiguration.configs.Count - 1; + oldSelectedIndex = ServersListBox.SelectedIndex; + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + + } + private void Config_Click(object sender, EventArgs e) { showWindow();