Browse Source

Merge branch 'billpareto_sort' into itemIndex

pull/695/head
YFdyh000 5 years ago
parent
commit
414ac3225a
  1. 31
      v2rayN/v2rayN/Base/ListViewSort.cs
  2. 16
      v2rayN/v2rayN/Forms/MainForm.cs
  3. 1
      v2rayN/v2rayN/v2rayN.csproj

31
v2rayN/v2rayN/Base/ListViewSort.cs

@ -0,0 +1,31 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace v2rayN.Base
{
public class ListViewSort : IComparer
{
private int col;
private bool descK;
public ListViewSort()
{
col = 0;
}
public ListViewSort(int column, object Desc)
{
descK = (bool)Desc;
col = column; //当前列,0,1,2...,参数由ListView控件的ColumnClick事件传递
}
public int Compare(object x, object y)
{
int tempInt = String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
if (descK) return -tempInt;
else return tempInt;
}
}
}

16
v2rayN/v2rayN/Forms/MainForm.cs

@ -182,6 +182,9 @@ namespace v2rayN.Forms
lvServers.Columns.Add(EServerColName.testResult.ToString(), UIRes.I18N("LvTestResults"), 70); lvServers.Columns.Add(EServerColName.testResult.ToString(), UIRes.I18N("LvTestResults"), 70);
if (statistics != null && statistics.Enable) if (statistics != null && statistics.Enable)
lvServers.HeaderStyle = ColumnHeaderStyle.Clickable;
this.lvServers.AllowColumnReorder = true;
{ {
lvServers.Columns.Add(EServerColName.todayDown.ToString(), UIRes.I18N("LvTodayDownloadDataAmount"), 70); lvServers.Columns.Add(EServerColName.todayDown.ToString(), UIRes.I18N("LvTodayDownloadDataAmount"), 70);
lvServers.Columns.Add(EServerColName.todayUp.ToString(), UIRes.I18N("LvTodayUploadDataAmount"), 70); lvServers.Columns.Add(EServerColName.todayUp.ToString(), UIRes.I18N("LvTodayUploadDataAmount"), 70);
@ -1627,5 +1630,18 @@ namespace v2rayN.Forms
{ {
tsbOptionSetting_Click(toolSslRouting, null); tsbOptionSetting_Click(toolSslRouting, null);
} }
private void lvServers_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (lvServers.Columns[e.Column].Tag == null)
lvServers.Columns[e.Column].Tag = true;
bool flag = (bool)lvServers.Columns[e.Column].Tag;
if (flag)
lvServers.Columns[e.Column].Tag = false;
else
lvServers.Columns[e.Column].Tag = true;
lvServers.ListViewItemSorter = new ListViewSort(e.Column, lvServers.Columns[e.Column].Tag);
lvServers.Sort();//对列表进行自定义排序
}
} }
} }

1
v2rayN/v2rayN/v2rayN.csproj

@ -97,6 +97,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Base\ListViewSort.cs" />
<Compile Include="Forms\AddServer4Form.cs"> <Compile Include="Forms\AddServer4Form.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>

Loading…
Cancel
Save