From 1a59724aff588c274e94046f2d0f5cfdc1797101 Mon Sep 17 00:00:00 2001 From: Student Main Date: Sun, 22 Mar 2020 23:33:02 +0800 Subject: [PATCH] toggle server correctly in MenuViewController --- shadowsocks-csharp/View/MenuViewController.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index e31fa67b..3a14f0ad 100644 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -38,7 +38,7 @@ namespace Shadowsocks.View private ToolStripMenuItem disableItem; private ToolStripMenuItem AutoStartupItem; private ToolStripMenuItem ShareOverLANItem; - private ToolStripSeparator SeperatorItem; + private ToolStripSeparator SeperatorItem; private ToolStripMenuItem ConfigItem; private ToolStripMenuItem ServersItem; private ToolStripMenuItem globalModeItem; @@ -277,12 +277,12 @@ namespace Shadowsocks.View private ToolStripMenuItem CreateToolStripMenuItem(string text, EventHandler click) { - return new ToolStripMenuItem(I18N.GetString(text),null, click); + return new ToolStripMenuItem(I18N.GetString(text), null, click); } private ToolStripMenuItem CreateMenuGroup(string text, ToolStripItem[] items) { - return new ToolStripMenuItem(I18N.GetString(text), null,items); + return new ToolStripMenuItem(I18N.GetString(text), null, items); } private void LoadMenu() @@ -461,7 +461,7 @@ namespace Shadowsocks.View int strategyCount = 0; foreach (var strategy in controller.GetStrategies()) { - if (!items.OfType().Any(ts=>ts.Text==strategy.Name)) + if (!items.OfType().Any(ts => ts.Text == strategy.Name)) { ToolStripMenuItem item = new ToolStripMenuItem(strategy.Name); item.Tag = strategy.ID; @@ -496,9 +496,17 @@ namespace Shadowsocks.View foreach (var item in items) { var menuItem = item as ToolStripMenuItem; - if (menuItem != null && menuItem.Tag != null && (menuItem.Tag.ToString() == configuration.index.ToString() || menuItem.Tag.ToString() == configuration.strategy)) + if (menuItem == null || menuItem.Tag == null) continue; + + if ( + menuItem.Tag.ToString() == configuration.index.ToString() + || menuItem.Tag.ToString() == configuration.strategy + ) { menuItem.Checked = true; + } else + { + menuItem.Checked = false; } } }