From bf0c6791e6ada6f853aa9613c5787e53bd787b9c Mon Sep 17 00:00:00 2001 From: bin456789 Date: Mon, 14 Mar 2022 23:46:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=EF=BC=9A=E8=B0=83=E6=95=B4=E9=80=BB=E8=BE=91=EF=BC=8C=E9=80=82?= =?UTF-8?q?=E5=BA=94=E6=96=B0=E5=BC=95=E5=85=A5=E7=9A=84sort=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2rayN/v2rayN/Forms/MainForm.cs | 47 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 6f1e4811..a6160946 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -282,6 +282,7 @@ namespace v2rayN.Forms } } ListViewItem lvItem = new ListViewItem(def); + lvItem.Tag = item.indexId; Utils.AddSubItem(lvItem, EServerColName.configType.ToString(), ((EConfigType)item.configType).ToString()); Utils.AddSubItem(lvItem, EServerColName.remarks.ToString(), item.remarks); Utils.AddSubItem(lvItem, EServerColName.address.ToString(), item.address); @@ -1678,43 +1679,57 @@ namespace v2rayN.Forms { targetIndex++; } - string activeIndexId = config.indexId(); + string activeIndexId = ConfigHandler.GetDefaultServer(ref config).indexId; lvServers.BeginUpdate(); - foreach (ListViewItem oldItem in lvServers.SelectedItems) + foreach (ListViewItem listItem in lvServers.SelectedItems) { - if (targetIndex == oldItem.Index) + if (targetIndex == listItem.Index) { targetIndex++; continue; } - VmessItem oldVmess = config.vmess[oldItem.Index]; - ListViewItem cloneItem = (ListViewItem)oldItem.Clone(); - VmessItem cloneVmess = Utils.DeepCopy(oldVmess); + int origIndex = listItem.Index; + bool isFocued = listItem.Focused; - lvServers.Items.Insert(targetIndex, cloneItem); - config.vmess.Insert(targetIndex, cloneVmess); - - cloneItem.Selected = true; - if (oldItem.Focused) + // 向下移动,删除自身后,targetIndex-1; + if (origIndex < targetIndex) { - cloneItem.Focused = true; + targetIndex--; } - lvServers.Items.Remove(oldItem); - config.vmess.Remove(oldVmess); - targetIndex = lvServers.Items.IndexOf(cloneItem) + 1; + listItem.Remove(); + lvServers.Items.Insert(targetIndex, listItem); + + if (isFocued) + { + listItem.Focused = true; + } + + + targetIndex++; } RefillListViewBackColor(lvServers); lvServers.EndUpdate(); - config.index = config.FindIndexId(activeIndexId); + for (int i = 0; i < lvServers.Items.Count; i++) + { + ListViewItem listItem = lvServers.Items[i]; + config.GetVmessItem((string)listItem.Tag).sort = i; + } + ConfigHandler.SaveConfig(ref config, false); + + lstVmess = config.vmess.Where(it => it.groupId == groupId).OrderBy(it => it.sort).ToList(); + //RefreshServersView(); RefreshServersMenu(); + + //RefreshServers(); + } private void lvServers_DragEnter(object sender, DragEventArgs e)