Browse Source

select serveritem at ConfigForm, not only tray menu.

pull/76/head
sui 10 years ago
parent
commit
ac707a2c1a
2 changed files with 39 additions and 2 deletions
  1. +1
    -0
      shadowsocks-csharp/Data/cn.txt
  2. +38
    -2
      shadowsocks-csharp/View/ConfigForm.cs

+ 1
- 0
shadowsocks-csharp/Data/cn.txt View File

@@ -43,3 +43,4 @@ Disabled=已禁用代理
Shadowsocks URI=Shadowsocks URI Shadowsocks URI=Shadowsocks URI
Shadowsocks URI Parse=Shadowsocks URI解析 Shadowsocks URI Parse=Shadowsocks URI解析
URI Parse=URI解析 URI Parse=URI解析
Select=使用

+ 38
- 2
shadowsocks-csharp/View/ConfigForm.cs View File

@@ -20,6 +20,8 @@ namespace Shadowsocks.View
private Configuration _modifiedConfiguration; private Configuration _modifiedConfiguration;
private int _oldSelectedIndex = -1; private int _oldSelectedIndex = -1;
private ContextMenuStrip ServersListBoxContextMenu = null;
public ConfigForm(ShadowsocksController controller) public ConfigForm(ShadowsocksController controller)
{ {
this.Font = System.Drawing.SystemFonts.MessageBoxFont; this.Font = System.Drawing.SystemFonts.MessageBoxFont;
@@ -38,6 +40,38 @@ namespace Shadowsocks.View
LoadCurrentConfiguration(); LoadCurrentConfiguration();
} }
private void ServersListBoxContextMenu_Opening(object sender, CancelEventArgs e)
{
//clear the menu and add custom items
string contextItemText = I18N.GetString("Select");
ServersListBoxContextMenu.Items.Clear();
ToolStripItem item = new ToolStripMenuItem();
item.Name = string.Format("{0}", ServersListBox.SelectedIndex.ToString());
item.Text = string.Format("{0} - {1}", contextItemText, ServersListBox.SelectedItem.ToString());
ServersListBoxContextMenu.Items.Add(item);
ServersListBoxContextMenu.ItemClicked += new ToolStripItemClickedEventHandler(ServersListBoxContextMenu_ItemClicked);
}
void ServersListBoxContextMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
ToolStripItem item = e.ClickedItem;
controller.SelectServerIndex(int.Parse(item.Name));
}
private void ServersListBox_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
//select the item under the mouse pointer
ServersListBox.SelectedIndex = ServersListBox.IndexFromPoint(e.Location);
if (ServersListBox.SelectedIndex != -1)
{
ServersListBoxContextMenu.Show();
}
}
}
private void UpdateTexts() private void UpdateTexts()
{ {
AddButton.Text = I18N.GetString("&Add"); AddButton.Text = I18N.GetString("&Add");
@@ -141,7 +175,9 @@ namespace Shadowsocks.View
private void ConfigForm_Load(object sender, EventArgs e) private void ConfigForm_Load(object sender, EventArgs e)
{ {
ServersListBoxContextMenu = new ContextMenuStrip();
ServersListBoxContextMenu.Opening += new CancelEventHandler(ServersListBoxContextMenu_Opening);
ServersListBox.ContextMenuStrip = ServersListBoxContextMenu;
} }
private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e) private void ServersListBox_SelectedIndexChanged(object sender, EventArgs e)
@@ -204,7 +240,7 @@ namespace Shadowsocks.View
return; return;
} }
controller.SaveServers(_modifiedConfiguration.configs); controller.SaveServers(_modifiedConfiguration.configs);
this.Close();
//this.Close();
} }
private void CancelButton_Click(object sender, EventArgs e) private void CancelButton_Click(object sender, EventArgs e)


Loading…
Cancel
Save