Browse Source

Simple and refined sorting effect

pull/695/head
YFdyh000 5 years ago
parent
commit
be7d76947b
  1. 13
      v2rayN/v2rayN/Base/ListViewSort.cs
  2. 28
      v2rayN/v2rayN/Forms/MainForm.cs
  3. 1
      v2rayN/v2rayN/Global.cs

13
v2rayN/v2rayN/Base/ListViewSort.cs

@ -19,8 +19,17 @@ namespace v2rayN.Base
int doIntSort = Sorting;
if (doIntSort > 0) // Tag will be number
{
ulong.TryParse(l1.SubItems[Column].Tag?.ToString(), out ulong fl1);
ulong.TryParse(l2.SubItems[Column].Tag?.ToString(), out ulong fl2);
var data1 = l1.SubItems[Column].Tag;
var data2 = l2.SubItems[Column].Tag;
if(data1 == null & data2 == null)
{
data1 = l1.SubItems[Column].Text;
data2 = l2.SubItems[Column].Text;
System.Diagnostics.Debug.WriteLine("Tag missing?");
}
ulong.TryParse(data1.ToString(), out ulong fl1);
ulong.TryParse(data2.ToString(), out ulong fl2);
if (doIntSort == 1)
{

28
v2rayN/v2rayN/Forms/MainForm.cs

@ -1666,30 +1666,30 @@ namespace v2rayN.Forms
tsbOptionSetting_Click(toolSslRouting, null);
}
private int lastSortedColIndex = -1;
private bool lastSortedColDirection = false;
private void lvServers_ColumnClick(object sender, ColumnClickEventArgs e)
{
Sorter s = (Sorter)lvServers.ListViewItemSorter;
s.Column = e.Column;
int doIntSort;
if (lvServers.Columns[e.Column].Tag?.ToString() == Global.sortMode.Numeric.ToString()) // 数字正序
bool isNum = lvServers.Columns[e.Column].Tag?.ToString() == Global.sortMode.Numeric.ToString();
if (lastSortedColIndex < 0 // 首次
|| (lastSortedColIndex >= 0 && lastSortedColIndex != e.Column) // 排序了其他列
|| (lastSortedColIndex == e.Column && !lastSortedColDirection) // 已排序
)
{
lvServers.Columns[e.Column].Tag = Global.sortMode.NumericB.ToString();
doIntSort = 1;
lastSortedColDirection = true;
doIntSort = isNum ? 1 : -1; // 正序
}
else if (lvServers.Columns[e.Column].Tag?.ToString() == Global.sortMode.NumericB.ToString()) // 数字倒序
{
lvServers.Columns[e.Column].Tag = Global.sortMode.Numeric.ToString();
doIntSort = 2;
}
else // 非数字
else
{
bool bGo = bool.TryParse(lvServers.Columns[e.Column].Tag?.ToString(), out bool bOk);
// 首个转换将失败,如果Tag是null或其他。
bool flag = bOk ? bGo : false;
lvServers.Columns[e.Column].Tag = !flag; // 首次则赋值true。
doIntSort = flag ? -1 : -2; // -1正序 -2倒序
lastSortedColDirection = false;
doIntSort = isNum ? 2 : -2; // 倒序
}
lastSortedColIndex = e.Column;
s.Sorting = doIntSort;
lvServers.Sort();

1
v2rayN/v2rayN/Global.cs

@ -162,7 +162,6 @@ namespace v2rayN
public enum sortMode
{
Numeric,
NumericB,
// More, like natural numbers, string length, visual length, etc.
}

Loading…
Cancel
Save