From 9d78de0f6c73e163cbf36ce362dbae6d238128c8 Mon Sep 17 00:00:00 2001 From: ChsBuffer <33744752+chsbuffer@users.noreply.github.com> Date: Thu, 8 Oct 2020 20:31:50 +0800 Subject: [PATCH] refactor: SubscribeForm Save - remove: duplicate link check - fix: check remark duplicate not work --- Netch/Forms/SubscribeForm.Designer.cs | 7 ++-- Netch/Forms/SubscribeForm.cs | 53 ++++----------------------- 2 files changed, 11 insertions(+), 49 deletions(-) diff --git a/Netch/Forms/SubscribeForm.Designer.cs b/Netch/Forms/SubscribeForm.Designer.cs index 56f5a3ac..83698bdf 100644 --- a/Netch/Forms/SubscribeForm.Designer.cs +++ b/Netch/Forms/SubscribeForm.Designer.cs @@ -81,11 +81,11 @@ // // ClearButton // - this.ClearButton.Location = new System.Drawing.Point(477, 103); + this.ClearButton.Location = new System.Drawing.Point(448, 103); this.ClearButton.Name = "ClearButton"; - this.ClearButton.Size = new System.Drawing.Size(58, 26); + this.ClearButton.Size = new System.Drawing.Size(87, 26); this.ClearButton.TabIndex = 7; - this.ClearButton.Text = "Clear"; + this.ClearButton.Text = "Unselect"; this.ClearButton.UseVisualStyleBackColor = true; this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click); // @@ -114,7 +114,6 @@ this.LinkTextBox.Name = "LinkTextBox"; this.LinkTextBox.Size = new System.Drawing.Size(545, 23); this.LinkTextBox.TabIndex = 4; - this.LinkTextBox.TextChanged += new System.EventHandler(this.ListTextBox_TextChanged); // // LinkLabel // diff --git a/Netch/Forms/SubscribeForm.cs b/Netch/Forms/SubscribeForm.cs index 7372be28..476f2a23 100644 --- a/Netch/Forms/SubscribeForm.cs +++ b/Netch/Forms/SubscribeForm.cs @@ -109,39 +109,23 @@ namespace Netch.Forms return; } - // 备注重复的订阅项 - var duplicateRemarkItems = Global.Settings.SubscribeLink.Where(link => link.Remark.Equals(RemarkLabel.Text)); - - // 链接重复的订阅项 - SubscribeLink duplicateLinkItem = null; - try - { - duplicateLinkItem = Global.Settings.SubscribeLink.First(link => link.Link.Equals(LinkTextBox.Text)); - } - catch - { - // ignored - } - - if (duplicateRemarkItems.Any()) + if (Global.Settings.SubscribeLink.Any(link => link.Remark.Equals(RemarkTextBox.Text))) { MessageBoxX.Show("Remark Name Duplicate!"); return; } - if (duplicateLinkItem != null) + if (_editingIndex == -1) { - if (duplicateLinkItem.Remark != RemarkTextBox.Text) + Global.Settings.SubscribeLink.Add(new SubscribeLink { - RenameServersGroup(duplicateLinkItem.Remark, RemarkTextBox.Text); - } - - duplicateLinkItem.Remark = RemarkTextBox.Text; - duplicateLinkItem.UserAgent = UserAgentTextBox.Text; + Remark = RemarkTextBox.Text, + Link = LinkTextBox.Text, + UserAgent = UserAgentTextBox.Text + }); } - else if (_editingIndex != -1) + else { - // 只修改备注/未修改被上面处理 var target = Global.Settings.SubscribeLink[_editingIndex]; if (MessageBox.Show(i18N.Translate("Delete the corresponding group of items in the server list?"), i18N.Translate("Confirm"), MessageBoxButtons.YesNo) == DialogResult.Yes) { @@ -156,15 +140,6 @@ namespace Netch.Forms target.Remark = RemarkTextBox.Text; target.UserAgent = UserAgentTextBox.Text; } - else - { - Global.Settings.SubscribeLink.Add(new SubscribeLink - { - Remark = RemarkTextBox.Text, - Link = LinkTextBox.Text, - UserAgent = UserAgentTextBox.Text - }); - } Configuration.Save(); Global.Settings.UseProxyToUpdateSubscription = UseSelectedServerCheckBox.Checked; @@ -260,17 +235,5 @@ namespace Netch.Forms { ResetEditingGroup(); } - - private void ListTextBox_TextChanged(object sender, EventArgs e) - { - for (var i = 0; i < SubscribeLinkListView.Items.Count; i++) - { - if (((TextBox) sender).Text == SubscribeLinkListView.Items[i].SubItems[1].Text) - { - _editingIndex = i; - AddSubscriptionBox.Text = SubscribeLinkListView.Items[i].SubItems[0].Text; - } - } - } } } \ No newline at end of file