Browse Source

sort2

pull/720/head
2dust 5 years ago
parent
commit
0db772aaeb
  1. 45
      v2rayN/v2rayN/Forms/MainForm.cs
  2. 35
      v2rayN/v2rayN/Handler/ConfigHandler.cs
  3. 2
      v2rayN/v2rayN/Mode/EServerColName.cs

45
v2rayN/v2rayN/Forms/MainForm.cs

@ -239,7 +239,7 @@ namespace v2rayN.Forms
}
}
ListViewItem lvItem = new ListViewItem(def);
_addSubItem(lvItem, EServerColName.type.ToString(), ((EConfigType)item.configType).ToString());
_addSubItem(lvItem, EServerColName.configType.ToString(), ((EConfigType)item.configType).ToString());
_addSubItem(lvItem, EServerColName.remarks.ToString(), item.remarks);
_addSubItem(lvItem, EServerColName.address.ToString(), item.address);
_addSubItem(lvItem, EServerColName.port.ToString(), item.port.ToString());
@ -377,6 +377,35 @@ namespace v2rayN.Forms
}
}
private void lvServers_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (e.Column < 0)
{
return;
}
try
{
var tag = lvServers.Columns[e.Column].Tag?.ToString();
bool asc = Utils.IsNullOrEmpty(tag) ? true : !Convert.ToBoolean(tag);
if (ConfigHandler.SortServers(ref config, (EServerColName)e.Column, asc) != 0)
{
return;
}
lvServers.Columns[e.Column].Tag = Convert.ToString(asc);
RefreshServers();
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
if (e.Column < 0)
{
return;
}
}
#endregion
#region v2ray 操作
@ -1566,19 +1595,5 @@ namespace v2rayN.Forms
#endregion
private void lvServers_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (e.Column < 0)
{
return;
}
//use linq
//var temp = config.vmess.AsQueryable();
//QueryableExtension
//temp.OrderBy("Code");
// temp.OrderByDescending("Code");
}
}
}

35
v2rayN/v2rayN/Handler/ConfigHandler.cs

@ -4,6 +4,8 @@ using System.IO;
using System.Net;
using v2rayN.Mode;
using v2rayN.Base;
using System.Linq;
using v2rayN.Tool;
namespace v2rayN.Handler
{
@ -922,5 +924,38 @@ namespace v2rayN.Handler
}
}
public static int SortServers(ref Config config, EServerColName name, bool asc)
{
if (config.vmess.Count <= 0)
{
return -1;
}
switch (name)
{
case EServerColName.configType:
case EServerColName.remarks:
case EServerColName.address:
case EServerColName.port:
case EServerColName.security:
case EServerColName.network:
case EServerColName.testResult:
break;
default:
return -1;
}
var items = config.vmess.AsQueryable();
if (asc)
{
config.vmess = items.OrderBy(name.ToString()).ToList();
}
else
{
config.vmess = items.OrderByDescending(name.ToString()).ToList();
}
ToJsonFile(config);
return 0;
}
}
}

2
v2rayN/v2rayN/Mode/EServerColName.cs

@ -4,7 +4,7 @@ namespace v2rayN.Mode
public enum EServerColName
{
def = 0,
type,
configType,
remarks,
address,
port,

Loading…
Cancel
Save