mirror of
https://github.com/2dust/v2rayN.git
synced 2026-03-12 11:23:01 +00:00
Persist DataGrid column layout for ClashConnectionsView
https://github.com/2dust/v2rayN/issues/8893
This commit is contained in:
parent
66e1aeae1f
commit
679bd8afcc
5 changed files with 136 additions and 33 deletions
|
|
@ -154,6 +154,7 @@ public static class ConfigHandler
|
|||
DownMbps = 100
|
||||
};
|
||||
config.ClashUIItem ??= new();
|
||||
config.ClashUIItem.ConnectionsColumnItem ??= new();
|
||||
config.SystemProxyItem ??= new();
|
||||
config.WebDavItem ??= new();
|
||||
config.CheckUpdateItem ??= new();
|
||||
|
|
|
|||
|
|
@ -208,6 +208,7 @@ public class ClashUIItem
|
|||
public int ProxiesAutoDelayTestInterval { get; set; } = 10;
|
||||
public bool ConnectionsAutoRefresh { get; set; }
|
||||
public int ConnectionsRefreshInterval { get; set; } = 2;
|
||||
public List<ColumnItem> ConnectionsColumnItem { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
x:Class="v2rayN.Views.ClashConnectionsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:base="clr-namespace:v2rayN.Base"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
|
|
@ -78,25 +79,30 @@
|
|||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn
|
||||
<base:MyDGTextColumn
|
||||
Width="300"
|
||||
Binding="{Binding Host}"
|
||||
ExName="Host"
|
||||
Header="{x:Static resx:ResUI.TbSortingHost}" />
|
||||
<DataGridTextColumn
|
||||
<base:MyDGTextColumn
|
||||
Width="500"
|
||||
Binding="{Binding Chain}"
|
||||
ExName="Chain"
|
||||
Header="{x:Static resx:ResUI.TbSortingChain}" />
|
||||
<DataGridTextColumn
|
||||
<base:MyDGTextColumn
|
||||
Width="80"
|
||||
Binding="{Binding Network}"
|
||||
ExName="Network"
|
||||
Header="{x:Static resx:ResUI.TbSortingNetwork}" />
|
||||
<DataGridTextColumn
|
||||
<base:MyDGTextColumn
|
||||
Width="160"
|
||||
Binding="{Binding Type}"
|
||||
ExName="Type"
|
||||
Header="{x:Static resx:ResUI.TbSortingType}" />
|
||||
<DataGridTextColumn
|
||||
<base:MyDGTextColumn
|
||||
Width="100"
|
||||
Binding="{Binding Elapsed}"
|
||||
ExName="Elapsed"
|
||||
Header="{x:Static resx:ResUI.TbSortingTime}" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Windows.Controls;
|
||||
using v2rayN.Base;
|
||||
|
||||
namespace v2rayN.Views;
|
||||
|
||||
|
|
@ -7,9 +8,14 @@ namespace v2rayN.Views;
|
|||
/// </summary>
|
||||
public partial class ClashConnectionsView
|
||||
{
|
||||
private static Config _config;
|
||||
private static readonly string _tag = "ClashConnectionsView";
|
||||
|
||||
public ClashConnectionsView()
|
||||
{
|
||||
InitializeComponent();
|
||||
_config = AppManager.Instance.Config;
|
||||
|
||||
ViewModel = new ClashConnectionsViewModel(UpdateViewHandler);
|
||||
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
|
||||
|
||||
|
|
@ -24,7 +30,15 @@ public partial class ClashConnectionsView
|
|||
this.Bind(ViewModel, vm => vm.HostFilter, v => v.txtHostFilter.Text).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.btnConnectionCloseAll).DisposeWith(disposables);
|
||||
this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables);
|
||||
|
||||
AppEvents.AppExitRequested
|
||||
.AsObservable()
|
||||
.ObserveOn(RxApp.MainThreadScheduler)
|
||||
.Subscribe(_ => StorageUI())
|
||||
.DisposeWith(disposables);
|
||||
});
|
||||
|
||||
RestoreUI();
|
||||
}
|
||||
|
||||
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||
|
|
@ -48,7 +62,7 @@ public partial class ClashConnectionsView
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog("ClashConnectionsView", ex);
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -56,4 +70,71 @@ public partial class ClashConnectionsView
|
|||
{
|
||||
ViewModel?.ClashConnectionClose(false);
|
||||
}
|
||||
|
||||
#region UI
|
||||
|
||||
private void RestoreUI()
|
||||
{
|
||||
try
|
||||
{
|
||||
var lvColumnItem = _config.ClashUIItem?.ConnectionsColumnItem?.OrderBy(t => t.Index).ToList();
|
||||
if (lvColumnItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var displayIndex = 0;
|
||||
foreach (var item in lvColumnItem)
|
||||
{
|
||||
foreach (var col in lstConnections.Columns.Cast<MyDGTextColumn>())
|
||||
{
|
||||
if (col.ExName == item.Name)
|
||||
{
|
||||
if (item.Width > 0)
|
||||
{
|
||||
col.Width = item.Width;
|
||||
}
|
||||
|
||||
col.DisplayIndex = displayIndex++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void StorageUI()
|
||||
{
|
||||
try
|
||||
{
|
||||
List<ColumnItem> lvColumnItem = new();
|
||||
foreach (var col in lstConnections.Columns.Cast<MyDGTextColumn>())
|
||||
{
|
||||
var name = col.ExName;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
lvColumnItem.Add(new()
|
||||
{
|
||||
Name = name,
|
||||
Width = (int)col.ActualWidth,
|
||||
Index = col.DisplayIndex
|
||||
});
|
||||
}
|
||||
|
||||
_config.ClashUIItem.ConnectionsColumnItem = lvColumnItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion UI
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace v2rayN.Views;
|
|||
public partial class ProfilesView
|
||||
{
|
||||
private static Config _config;
|
||||
private static readonly string _tag = "ProfilesView";
|
||||
|
||||
public ProfilesView()
|
||||
{
|
||||
|
|
@ -339,7 +340,7 @@ public partial class ProfilesView
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog("ProfilesView", ex);
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -356,12 +357,14 @@ public partial class ProfilesView
|
|||
#region UI
|
||||
|
||||
private void RestoreUI()
|
||||
{
|
||||
try
|
||||
{
|
||||
var lvColumnItem = _config.UiItem.MainColumnItem.OrderBy(t => t.Index).ToList();
|
||||
var displayIndex = 0;
|
||||
foreach (var item in lvColumnItem)
|
||||
{
|
||||
foreach (MyDGTextColumn item2 in lstProfiles.Columns)
|
||||
foreach (var item2 in lstProfiles.Columns.Cast<MyDGTextColumn>())
|
||||
{
|
||||
if (item2.ExName == item.Name)
|
||||
{
|
||||
|
|
@ -382,13 +385,19 @@ public partial class ProfilesView
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void StorageUI()
|
||||
{
|
||||
List<ColumnItem> lvColumnItem = new();
|
||||
foreach (var t in lstProfiles.Columns)
|
||||
try
|
||||
{
|
||||
List<ColumnItem> lvColumnItem = new();
|
||||
foreach (var item2 in lstProfiles.Columns.Cast<MyDGTextColumn>())
|
||||
{
|
||||
var item2 = (MyDGTextColumn)t;
|
||||
lvColumnItem.Add(new()
|
||||
{
|
||||
Name = item2.ExName,
|
||||
|
|
@ -398,6 +407,11 @@ public partial class ProfilesView
|
|||
}
|
||||
_config.UiItem.MainColumnItem = lvColumnItem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(_tag, ex);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion UI
|
||||
|
||||
|
|
@ -405,7 +419,7 @@ public partial class ProfilesView
|
|||
|
||||
private Point startPoint = new();
|
||||
private int startIndex = -1;
|
||||
private string formatData = "ProfileItemModel";
|
||||
private readonly string formatData = "ProfileItemModel";
|
||||
|
||||
/// <summary>
|
||||
/// Helper to search up the VisualTree
|
||||
|
|
|
|||
Loading…
Reference in a new issue