Browse Source

implement adding server

tags/2.3
clowwindy 10 years ago
parent
commit
ac1172c3ec
4 changed files with 36 additions and 10 deletions
  1. +2
    -1
      shadowsocks-csharp/Controller/ShadowsocksController.cs
  2. +3
    -3
      shadowsocks-csharp/Model/Configuration.cs
  3. +2
    -0
      shadowsocks-csharp/View/ConfigForm.Designer.cs
  4. +29
    -6
      shadowsocks-csharp/View/ConfigForm.cs

+ 2
- 1
shadowsocks-csharp/Controller/ShadowsocksController.cs View File

@@ -73,9 +73,10 @@ namespace Shadowsocks.Controller
return config.GetCurrentServer();
}
// always return copy
public Configuration GetConfiguration()
{
return config;
return Configuration.Load();
}


+ 3
- 3
shadowsocks-csharp/Model/Configuration.cs View File

@@ -27,7 +27,7 @@ namespace Shadowsocks.Model
}
else
{
return getDefaultServer();
return GetDefaultServer();
}
}
@@ -59,7 +59,7 @@ namespace Shadowsocks.Model
index = 0,
configs = new List<Server>()
{
getDefaultServer()
GetDefaultServer()
}
};
}
@@ -83,7 +83,7 @@ namespace Shadowsocks.Model
}
}
private static Server getDefaultServer()
public static Server GetDefaultServer()
{
return new Server()
{


+ 2
- 0
shadowsocks-csharp/View/ConfigForm.Designer.cs View File

@@ -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
//


+ 29
- 6
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -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();


Loading…
Cancel
Save