diff --git a/Netch/Forms/SubscribeForm.Designer.cs b/Netch/Forms/SubscribeForm.Designer.cs index 30358caa..b8c8d3bb 100644 --- a/Netch/Forms/SubscribeForm.Designer.cs +++ b/Netch/Forms/SubscribeForm.Designer.cs @@ -32,7 +32,7 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SubscribeForm)); this.AddSubscriptionBox = new System.Windows.Forms.GroupBox(); this.UserAgentTextBox = new System.Windows.Forms.TextBox(); - this.ClearButton = new System.Windows.Forms.Button(); + this.UnselectButton = new System.Windows.Forms.Button(); this.AddButton = new System.Windows.Forms.Button(); this.UserAgentLabel = new System.Windows.Forms.Label(); this.LinkTextBox = new System.Windows.Forms.TextBox(); @@ -60,7 +60,7 @@ // AddSubscriptionBox // this.AddSubscriptionBox.Controls.Add(this.UserAgentTextBox); - this.AddSubscriptionBox.Controls.Add(this.ClearButton); + this.AddSubscriptionBox.Controls.Add(this.UnselectButton); this.AddSubscriptionBox.Controls.Add(this.AddButton); this.AddSubscriptionBox.Controls.Add(this.UserAgentLabel); this.AddSubscriptionBox.Controls.Add(this.LinkTextBox); @@ -81,15 +81,15 @@ this.UserAgentTextBox.Size = new System.Drawing.Size(545, 23); this.UserAgentTextBox.TabIndex = 6; // - // ClearButton + // UnselectButton // - this.ClearButton.Location = new System.Drawing.Point(448, 103); - this.ClearButton.Name = "ClearButton"; - this.ClearButton.Size = new System.Drawing.Size(87, 26); - this.ClearButton.TabIndex = 7; - this.ClearButton.Text = "Unselect"; - this.ClearButton.UseVisualStyleBackColor = true; - this.ClearButton.Click += new System.EventHandler(this.ClearButton_Click); + this.UnselectButton.Location = new System.Drawing.Point(448, 103); + this.UnselectButton.Name = "UnselectButton"; + this.UnselectButton.Size = new System.Drawing.Size(87, 26); + this.UnselectButton.TabIndex = 7; + this.UnselectButton.Text = "Unselect"; + this.UnselectButton.UseVisualStyleBackColor = true; + this.UnselectButton.Click += new System.EventHandler(this.UnselectButton_Click); // // AddButton // @@ -97,7 +97,7 @@ this.AddButton.Name = "AddButton"; this.AddButton.Size = new System.Drawing.Size(113, 26); this.AddButton.TabIndex = 7; - this.AddButton.Text = "Add / Modify"; + this.AddButton.Text = "Add"; this.AddButton.UseVisualStyleBackColor = true; this.AddButton.Click += new System.EventHandler(this.AddButton_Click); // @@ -278,7 +278,7 @@ private System.Windows.Forms.Panel ControlsPanel; private System.Windows.Forms.TableLayoutPanel MainTableLayoutPanel; - private System.Windows.Forms.Button ClearButton; + private System.Windows.Forms.Button UnselectButton; private System.Windows.Forms.GroupBox AddSubscriptionBox; private System.Windows.Forms.Label RemarkLabel; private System.Windows.Forms.TextBox LinkTextBox; diff --git a/Netch/Forms/SubscribeForm.cs b/Netch/Forms/SubscribeForm.cs index 72e6442a..99434418 100644 --- a/Netch/Forms/SubscribeForm.cs +++ b/Netch/Forms/SubscribeForm.cs @@ -8,7 +8,16 @@ namespace Netch.Forms { public partial class SubscribeForm : Form { - private int _editingIndex = -1; + private int SelectedIndex + { + get + { + if (SubscribeLinkListView.MultiSelect) + throw new Exception(); + + return SubscribeLinkListView.SelectedIndices.Count == 0 ? -1 : SubscribeLinkListView.SelectedIndices[0]; + } + } public SubscribeForm() { @@ -20,51 +29,37 @@ namespace Netch.Forms UseSelectedServerCheckBox.Checked = Global.Settings.Server.Any() && Global.Settings.UseProxyToUpdateSubscription; InitSubscribeLink(); - ResetEditingGroup(); } #region EventHandler - /// - /// 订阅列表选中节点 - /// - private void SubscribeLinkListView_SelectedIndexChanged(object sender, EventArgs e) - { - var listView = (ListView) sender; - if (listView.SelectedItems.Count == 0) - { - // 重置 - ResetEditingGroup(); - return; - } - _editingIndex = listView.SelectedItems[0].Index; - - var target = SubscribeLinkListView.Items[_editingIndex]; - - AddSubscriptionBox.Text = target.SubItems[1].Text; - RemarkTextBox.Text = target.SubItems[1].Text; - LinkTextBox.Text = target.SubItems[2].Text; - UserAgentTextBox.Text = target.SubItems[3].Text; - } - private void SubscribeLinkListView_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { - if (SubscribeLinkListView.SelectedItems.Count > 0) + if (SelectedIndex != -1) { pContextMenuStrip.Show(SubscribeLinkListView, e.Location); } } } - private void SubscribeLinkListView_ItemChecked(object sender, ItemCheckedEventArgs e) + /// + /// 选中/取消选中 + /// + private void SubscribeLinkListView_SelectedIndexChanged(object sender, EventArgs e) { - var viewItem = SubscribeLinkListView.Items[e.Item.Index]; - var subscribeLink = Global.Settings.SubscribeLink[e.Item.Index]; - subscribeLink.Enable = viewItem.Checked; + SetEditingGroup(SelectedIndex); } + /// + /// 订阅启/禁用 + /// + private void SubscribeLinkListView_ItemChecked(object sender, ItemCheckedEventArgs e) + { + var index = e.Item.Index; + Global.Settings.SubscribeLink[index].Enable = SubscribeLinkListView.Items[index].Checked; + } private void SubscribeForm_FormClosing(object sender, FormClosingEventArgs e) { @@ -76,7 +71,7 @@ namespace Netch.Forms #region EditBox - private void ClearButton_Click(object sender, EventArgs e) + private void UnselectButton_Click(object sender, EventArgs e) { ResetEditingGroup(); } @@ -101,7 +96,7 @@ namespace Netch.Forms return; } - if (_editingIndex == -1) + if (SelectedIndex == -1) { if (Global.Settings.SubscribeLink.Any(link => link.Remark.Equals(RemarkTextBox.Text))) { @@ -119,9 +114,9 @@ namespace Netch.Forms } else { - var subscribeLink = Global.Settings.SubscribeLink[_editingIndex]; + var subscribeLink = Global.Settings.SubscribeLink[SelectedIndex]; - RenameServersGroup(subscribeLink.Remark, RemarkTextBox.Text); + RenameServers(subscribeLink.Remark, RemarkTextBox.Text); subscribeLink.Link = LinkTextBox.Text; subscribeLink.Remark = RemarkTextBox.Text; subscribeLink.UserAgent = UserAgentTextBox.Text; @@ -130,7 +125,6 @@ namespace Netch.Forms MessageBoxX.Show(i18N.Translate("Saved")); InitSubscribeLink(); - ResetEditingGroup(); } #endregion @@ -142,13 +136,11 @@ namespace Netch.Forms if (MessageBoxX.Show(i18N.Translate("Delete or not ? Will clean up the corresponding group of items in the server list"), confirm: true) != DialogResult.OK) return; - var viewItem = SubscribeLinkListView.SelectedItems[0]; - var subscribeLink = Global.Settings.SubscribeLink[viewItem.Index]; - - DeleteServersInGroup(subscribeLink.Remark); + var subscribeLink = Global.Settings.SubscribeLink[SelectedIndex]; + DeleteServers(subscribeLink.Remark); Global.Settings.SubscribeLink.Remove(subscribeLink); - SubscribeLinkListView.Items.Remove(viewItem); - ResetEditingGroup(); + + InitSubscribeLink(); } private void deleteServerToolStripMenuItem_Click(object sender, EventArgs e) @@ -156,27 +148,24 @@ namespace Netch.Forms if (MessageBoxX.Show(i18N.Translate("Confirm deletion?"), confirm: true) != DialogResult.OK) return; - var viewItem = SubscribeLinkListView.SelectedItems[0]; - DeleteServersInGroup(viewItem.SubItems[1].Text); + DeleteServers(Global.Settings.SubscribeLink[SelectedIndex].Remark); } private void CopyLinkToolStripMenuItem_Click(object sender, EventArgs e) { - var viewItem = SubscribeLinkListView.SelectedItems[0]; - var subscribeLink = Global.Settings.SubscribeLink[viewItem.Index]; - Clipboard.SetText(subscribeLink.Link); + Clipboard.SetText(Global.Settings.SubscribeLink[SelectedIndex].Link); } #endregion #region Helper - private static void DeleteServersInGroup(string group) + private static void DeleteServers(string group) { Global.Settings.Server.RemoveAll(server => server.Group == group); } - private static void RenameServersGroup(string oldGroup, string newGroup) + private static void RenameServers(string oldGroup, string newGroup) { foreach (var server in Global.Settings.Server.Where(server => server.Group == oldGroup)) { @@ -190,7 +179,7 @@ namespace Netch.Forms foreach (var item in Global.Settings.SubscribeLink) { - var viewItem = new ListViewItem(new[] + SubscribeLinkListView.Items.Add(new ListViewItem(new[] { "", item.Remark, @@ -199,19 +188,36 @@ namespace Netch.Forms }) { Checked = item.Enable - }; - SubscribeLinkListView.Items.Add(viewItem); + }); } + + ResetEditingGroup(); } private void ResetEditingGroup() { - _editingIndex = -1; AddSubscriptionBox.Text = string.Empty; RemarkTextBox.Text = string.Empty; LinkTextBox.Text = string.Empty; UserAgentTextBox.Text = WebUtil.DefaultUserAgent; } + private void SetEditingGroup(int index) + { + if (index == -1) + { + ResetEditingGroup(); + AddButton.Text = i18N.Translate("Add"); + return; + } + + var item = Global.Settings.SubscribeLink[index]; + AddSubscriptionBox.Text = item.Remark; + RemarkTextBox.Text = item.Remark; + LinkTextBox.Text = item.Link; + UserAgentTextBox.Text = item.UserAgent; + + AddButton.Text = i18N.Translate("Modify"); + } #endregion } diff --git a/Netch/Resources/zh-CN b/Netch/Resources/zh-CN index 9d8f217f..41510b6a 100644 --- a/Netch/Resources/zh-CN +++ b/Netch/Resources/zh-CN @@ -126,7 +126,7 @@ "Add": "添加", "Scan": "扫描", "Save": "保存", - "Add / Modify": "保存/修改", + "Modify": "修改", "Select a folder": "选择一个目录", "Please enter an process name (xxx.exe)": "请输入一个进程名(xxx.exe)", "Rule does not conform to C++ regular expression syntax": "规则不符合C ++正则表达式语法",