implement adding server
This commit is contained in:
@@ -73,9 +73,10 @@ namespace Shadowsocks.Controller
|
||||
return config.GetCurrentServer();
|
||||
}
|
||||
|
||||
// always return copy
|
||||
public Configuration GetConfiguration()
|
||||
{
|
||||
return config;
|
||||
return Configuration.Load();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
//
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user