implement server switching menu
This commit is contained in:
+40
-15
@@ -48,7 +48,10 @@
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
|
||||
this.enableItem = new System.Windows.Forms.MenuItem();
|
||||
this.configItem = new System.Windows.Forms.MenuItem();
|
||||
this.ServersItem = new System.Windows.Forms.MenuItem();
|
||||
this.SeperatorItem = new System.Windows.Forms.MenuItem();
|
||||
this.ConfigItem = new System.Windows.Forms.MenuItem();
|
||||
this.menuItem4 = new System.Windows.Forms.MenuItem();
|
||||
this.editPACFileItem = new System.Windows.Forms.MenuItem();
|
||||
this.aboutItem = new System.Windows.Forms.MenuItem();
|
||||
this.menuItem3 = new System.Windows.Forms.MenuItem();
|
||||
@@ -256,7 +259,8 @@
|
||||
//
|
||||
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||
this.enableItem,
|
||||
this.configItem,
|
||||
this.ServersItem,
|
||||
this.menuItem4,
|
||||
this.editPACFileItem,
|
||||
this.aboutItem,
|
||||
this.menuItem3,
|
||||
@@ -265,36 +269,54 @@
|
||||
// enableItem
|
||||
//
|
||||
this.enableItem.Index = 0;
|
||||
this.enableItem.Text = "Enable";
|
||||
this.enableItem.Text = "&Enable";
|
||||
this.enableItem.Click += new System.EventHandler(this.EnableItem_Click);
|
||||
//
|
||||
// configItem
|
||||
// ServersItem
|
||||
//
|
||||
this.configItem.Index = 1;
|
||||
this.configItem.Text = "Options...";
|
||||
this.configItem.Click += new System.EventHandler(this.Config_Click);
|
||||
this.ServersItem.Index = 1;
|
||||
this.ServersItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
||||
this.SeperatorItem,
|
||||
this.ConfigItem});
|
||||
this.ServersItem.Text = "&Servers";
|
||||
//
|
||||
// SeperatorItem
|
||||
//
|
||||
this.SeperatorItem.Index = 0;
|
||||
this.SeperatorItem.Text = "-";
|
||||
//
|
||||
// ConfigItem
|
||||
//
|
||||
this.ConfigItem.Index = 1;
|
||||
this.ConfigItem.Text = "Edit Servers...";
|
||||
this.ConfigItem.Click += new System.EventHandler(this.Config_Click);
|
||||
//
|
||||
// menuItem4
|
||||
//
|
||||
this.menuItem4.Index = 2;
|
||||
this.menuItem4.Text = "-";
|
||||
//
|
||||
// editPACFileItem
|
||||
//
|
||||
this.editPACFileItem.Index = 2;
|
||||
this.editPACFileItem.Text = "Edit PAC File...";
|
||||
this.editPACFileItem.Index = 3;
|
||||
this.editPACFileItem.Text = "Edit &PAC File...";
|
||||
this.editPACFileItem.Click += new System.EventHandler(this.EditPACFileItem_Click);
|
||||
//
|
||||
// aboutItem
|
||||
//
|
||||
this.aboutItem.Index = 3;
|
||||
this.aboutItem.Text = "About";
|
||||
this.aboutItem.Index = 4;
|
||||
this.aboutItem.Text = "About...";
|
||||
this.aboutItem.Click += new System.EventHandler(this.AboutItem_Click);
|
||||
//
|
||||
// menuItem3
|
||||
//
|
||||
this.menuItem3.Index = 4;
|
||||
this.menuItem3.Index = 5;
|
||||
this.menuItem3.Text = "-";
|
||||
//
|
||||
// quitItem
|
||||
//
|
||||
this.quitItem.Index = 5;
|
||||
this.quitItem.Text = "Quit";
|
||||
this.quitItem.Index = 6;
|
||||
this.quitItem.Text = "&Quit";
|
||||
this.quitItem.Click += new System.EventHandler(this.Quit_Click);
|
||||
//
|
||||
// panel3
|
||||
@@ -401,13 +423,16 @@
|
||||
private System.Windows.Forms.MenuItem aboutItem;
|
||||
private System.Windows.Forms.MenuItem menuItem3;
|
||||
private System.Windows.Forms.MenuItem quitItem;
|
||||
private System.Windows.Forms.MenuItem configItem;
|
||||
private System.Windows.Forms.MenuItem ConfigItem;
|
||||
private System.Windows.Forms.MenuItem editPACFileItem;
|
||||
private System.Windows.Forms.Panel panel3;
|
||||
private System.Windows.Forms.Button DeleteButton;
|
||||
private System.Windows.Forms.Button AddButton;
|
||||
private System.Windows.Forms.GroupBox ServerGroupBox;
|
||||
private System.Windows.Forms.ListBox ServersListBox;
|
||||
private System.Windows.Forms.MenuItem ServersItem;
|
||||
private System.Windows.Forms.MenuItem SeperatorItem;
|
||||
private System.Windows.Forms.MenuItem menuItem4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace Shadowsocks.View
|
||||
ServersListBox.Items.Clear();
|
||||
foreach (Server server in modifiedConfiguration.configs)
|
||||
{
|
||||
ServersListBox.Items.Add(string.IsNullOrEmpty(server.server) ? "New server" : server.server);
|
||||
ServersListBox.Items.Add(string.IsNullOrEmpty(server.server) ? "New server" : server.server + ":" + server.server_port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,9 +122,34 @@ namespace Shadowsocks.View
|
||||
ServersListBox.SelectedIndex = modifiedConfiguration.index;
|
||||
loadSelectedServer();
|
||||
|
||||
updateServersMenu();
|
||||
enableItem.Checked = modifiedConfiguration.enabled;
|
||||
}
|
||||
|
||||
private void updateServersMenu()
|
||||
{
|
||||
var items = ServersItem.MenuItems;
|
||||
|
||||
items.Clear();
|
||||
|
||||
Configuration configuration = controller.GetConfiguration();
|
||||
for (int i = 0; i < configuration.configs.Count; i++)
|
||||
{
|
||||
Server server = configuration.configs[i];
|
||||
MenuItem item = new MenuItem(server.server + ":" + server.server_port);
|
||||
item.Tag = i;
|
||||
item.Click += AServerItem_Click;
|
||||
items.Add(item);
|
||||
}
|
||||
items.Add(SeperatorItem);
|
||||
items.Add(ConfigItem);
|
||||
|
||||
if (configuration.index >= 0 && configuration.index < configuration.configs.Count)
|
||||
{
|
||||
items[configuration.index].Checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!controller.GetConfiguration().isDefault)
|
||||
@@ -243,5 +268,12 @@ namespace Shadowsocks.View
|
||||
controller.TouchPACFile();
|
||||
}
|
||||
|
||||
private void AServerItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MenuItem item = (MenuItem)sender;
|
||||
Configuration configuration = controller.GetConfiguration();
|
||||
configuration.index = (int)item.Tag;
|
||||
controller.SaveConfig(configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user