From b061a0005761b814aed970895780e2541014c466 Mon Sep 17 00:00:00 2001
From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com>
Date: Tue, 25 Aug 2020 04:49:58 +0800
Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9F=20"ComboBox=20=E7=BB=91?=
=?UTF-8?q?=E5=AE=9A=E6=95=B0=E6=8D=AE"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Netch/Forms/MainForm.Designer.cs | 2 +-
Netch/Forms/MainForm.MenuStrip.cs | 2 +-
Netch/Forms/MainForm.Server_Mode.cs | 23 +++++++++++++
Netch/Forms/MainForm.cs | 19 +++++------
Netch/Global.cs | 2 +-
Netch/Models/Setting.cs | 2 +-
Netch/Override/SortableBindingList.cs | 47 ---------------------------
Netch/Utils/Modes.cs | 6 ----
8 files changed, 36 insertions(+), 67 deletions(-)
delete mode 100644 Netch/Override/SortableBindingList.cs
diff --git a/Netch/Forms/MainForm.Designer.cs b/Netch/Forms/MainForm.Designer.cs
index e2b42cf1..01f7523e 100644
--- a/Netch/Forms/MainForm.Designer.cs
+++ b/Netch/Forms/MainForm.Designer.cs
@@ -764,7 +764,7 @@ namespace Netch.Forms
private System.Windows.Forms.ToolStripMenuItem ImportServersFromClipboardToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem ManageSubscribeLinksToolStripMenuItem;
private System.Windows.Forms.MenuStrip MenuStrip;
- public System.Windows.Forms.SearchComboBox ModeComboBox;
+ private System.Windows.Forms.SearchComboBox ModeComboBox;
private System.Windows.Forms.Label ModeLabel;
private System.Windows.Forms.ToolStripMenuItem ModeToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem HelpToolStripMenuItem;
diff --git a/Netch/Forms/MainForm.MenuStrip.cs b/Netch/Forms/MainForm.MenuStrip.cs
index ecc7ae6b..7081fc56 100644
--- a/Netch/Forms/MainForm.MenuStrip.cs
+++ b/Netch/Forms/MainForm.MenuStrip.cs
@@ -83,7 +83,7 @@ namespace Netch.Forms
Enabled = false;
try
{
- Modes.Load();
+ InitMode();
NotifyTip(i18N.Translate("Modes have been reload"));
}
catch (Exception)
diff --git a/Netch/Forms/MainForm.Server_Mode.cs b/Netch/Forms/MainForm.Server_Mode.cs
index 44ab044e..fbc07f24 100644
--- a/Netch/Forms/MainForm.Server_Mode.cs
+++ b/Netch/Forms/MainForm.Server_Mode.cs
@@ -16,6 +16,17 @@ namespace Netch.Forms
{
#region Server
+ private void InitServer()
+ {
+ var comboBoxInitialized = _comboBoxInitialized;
+ _comboBoxInitialized = false;
+
+ ServerComboBox.Items.Clear();
+ ServerComboBox.Items.AddRange(Global.Settings.Server.ToArray());
+ SelectLastServer();
+ _comboBoxInitialized = comboBoxInitialized;
+ }
+
private static void TestServer()
{
try
@@ -50,6 +61,18 @@ namespace Netch.Forms
#region Mode
+ private void InitMode()
+ {
+ var comboBoxInitialized = _comboBoxInitialized;
+ _comboBoxInitialized = false;
+
+ ModeComboBox.Items.Clear();
+ Modes.Load();
+ ModeComboBox.Items.AddRange(Global.Modes.ToArray());
+ SelectLastMode();
+ _comboBoxInitialized = comboBoxInitialized;
+ }
+
public void SelectLastMode()
{
// 如果值合法,选中该位置
diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs
index f0b5379f..34855936 100644
--- a/Netch/Forms/MainForm.cs
+++ b/Netch/Forms/MainForm.cs
@@ -37,12 +37,9 @@ namespace Netch.Forms
// 计算 ComboBox绘制 目标宽度
_eWidth = ServerComboBox.Width / 10;
- Modes.Load();
- ServerComboBox.DataSource = Global.Settings.Server;
-
- SaveSelectIndex = true;
- SelectLastMode();
- SelectLastServer();
+ InitMode();
+ InitServer();
+ _comboBoxInitialized = true;
// 加载翻译
InitText();
@@ -340,7 +337,9 @@ namespace Netch.Forms
return;
}
- Modes.Delete(ModeComboBox.SelectedItem as Models.Mode);
+ var selectedMode = (Models.Mode) ModeComboBox.SelectedItem;
+ this.ModeComboBox.Items.Remove(selectedMode);
+ Modes.Delete(selectedMode);
SelectLastMode();
}
@@ -431,17 +430,17 @@ namespace Netch.Forms
#endregion
- private bool SaveSelectIndex = false;
+ private bool _comboBoxInitialized = false;
private void ModeComboBox_SelectedIndexChanged(object sender, EventArgs o)
{
- if (!SaveSelectIndex) return;
+ if (!_comboBoxInitialized) return;
Global.Settings.ModeComboBoxSelectedIndex = ModeComboBox.SelectedIndex;
}
private void ServerComboBox_SelectedIndexChanged(object sender, EventArgs o)
{
- if (!SaveSelectIndex) return;
+ if (!_comboBoxInitialized) return;
Global.Settings.ServerComboBoxSelectedIndex = ServerComboBox.SelectedIndex;
}
}
diff --git a/Netch/Global.cs b/Netch/Global.cs
index d0be72a7..4a67443a 100644
--- a/Netch/Global.cs
+++ b/Netch/Global.cs
@@ -203,6 +203,6 @@ namespace Netch
///
/// 用于存储模式
///
- public static readonly SortableBindingList Modes = new SortableBindingList();
+ public static readonly List Modes = new List();
}
}
diff --git a/Netch/Models/Setting.cs b/Netch/Models/Setting.cs
index 9eb20ab4..b5ba7225 100644
--- a/Netch/Models/Setting.cs
+++ b/Netch/Models/Setting.cs
@@ -147,7 +147,7 @@ namespace Netch.Models
///
/// 服务器列表
///
- public readonly BindingList Server = new BindingList();
+ public readonly List Server = new List();
///
/// 全局绕过 IP 列表
diff --git a/Netch/Override/SortableBindingList.cs b/Netch/Override/SortableBindingList.cs
deleted file mode 100644
index 25eaba78..00000000
--- a/Netch/Override/SortableBindingList.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-
-public class SortableBindingList : BindingList
-{
- public SortableBindingList(IList list) : base(list)
- {
- }
-
- public SortableBindingList()
- {
- }
-
- public void Sort()
- {
- Sort(null, null);
- }
-
- public void Sort(IComparer comparer)
- {
- Sort(comparer, null);
- }
-
- public void Sort(Comparison comparison)
- {
- Sort(null, comparison);
- }
-
- private void Sort(IComparer comparer, Comparison comparison)
- {
- // if (typeof(T).GetInterface(nameof(IComparable)) == null) return;
- var raiseListChangedEvents = this.RaiseListChangedEvents;
- this.RaiseListChangedEvents = false;
- try
- {
- var items = (List) this.Items;
- if (comparison != null) items.Sort(comparison);
- else items.Sort(comparer);
- }
- finally
- {
- this.RaiseListChangedEvents = raiseListChangedEvents;
- ResetBindings();
- }
- }
-}
\ No newline at end of file
diff --git a/Netch/Utils/Modes.cs b/Netch/Utils/Modes.cs
index 066c3922..497b6a08 100644
--- a/Netch/Utils/Modes.cs
+++ b/Netch/Utils/Modes.cs
@@ -17,10 +17,6 @@ namespace Netch.Utils
///
public static void Load()
{
- var raiseListChangedEvents = Global.Modes.RaiseListChangedEvents;
-
- Global.Modes.RaiseListChangedEvents = false;
- Global.MainForm.ModeComboBox.DataSource = null;
Global.Modes.Clear();
if (!Directory.Exists(MODE_DIR)) return;
@@ -45,8 +41,6 @@ namespace Netch.Utils
}
Sort();
- Global.MainForm.ModeComboBox.DataSource = Global.Modes;
- Global.Modes.RaiseListChangedEvents = raiseListChangedEvents;
}
private static void LoadModeFile(string path)