mirror of
https://github.com/2dust/v2rayN.git
synced 2026-03-12 19:33:01 +00:00
Persist DataGrid column layout for ClashConnectionsView
This commit is contained in:
parent
679bd8afcc
commit
df800a60c2
3 changed files with 145 additions and 41 deletions
|
|
@ -74,23 +74,28 @@
|
||||||
<DataGridTextColumn
|
<DataGridTextColumn
|
||||||
Width="300"
|
Width="300"
|
||||||
Binding="{Binding Host}"
|
Binding="{Binding Host}"
|
||||||
Header="{x:Static resx:ResUI.TbSortingHost}" />
|
Header="{x:Static resx:ResUI.TbSortingHost}"
|
||||||
|
Tag="Host" />
|
||||||
<DataGridTextColumn
|
<DataGridTextColumn
|
||||||
Width="500"
|
Width="500"
|
||||||
Binding="{Binding Chain}"
|
Binding="{Binding Chain}"
|
||||||
Header="{x:Static resx:ResUI.TbSortingChain}" />
|
Header="{x:Static resx:ResUI.TbSortingChain}"
|
||||||
|
Tag="Chain" />
|
||||||
<DataGridTextColumn
|
<DataGridTextColumn
|
||||||
Width="80"
|
Width="80"
|
||||||
Binding="{Binding Network}"
|
Binding="{Binding Network}"
|
||||||
Header="{x:Static resx:ResUI.TbSortingNetwork}" />
|
Header="{x:Static resx:ResUI.TbSortingNetwork}"
|
||||||
|
Tag="Network" />
|
||||||
<DataGridTextColumn
|
<DataGridTextColumn
|
||||||
Width="160"
|
Width="160"
|
||||||
Binding="{Binding Type}"
|
Binding="{Binding Type}"
|
||||||
Header="{x:Static resx:ResUI.TbSortingType}" />
|
Header="{x:Static resx:ResUI.TbSortingType}"
|
||||||
|
Tag="Type" />
|
||||||
<DataGridTextColumn
|
<DataGridTextColumn
|
||||||
Width="100"
|
Width="100"
|
||||||
Binding="{Binding Elapsed}"
|
Binding="{Binding Elapsed}"
|
||||||
Header="{x:Static resx:ResUI.TbSortingTime}" />
|
Header="{x:Static resx:ResUI.TbSortingTime}"
|
||||||
|
Tag="Elapsed" />
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,15 @@ namespace v2rayN.Desktop.Views;
|
||||||
|
|
||||||
public partial class ClashConnectionsView : ReactiveUserControl<ClashConnectionsViewModel>
|
public partial class ClashConnectionsView : ReactiveUserControl<ClashConnectionsViewModel>
|
||||||
{
|
{
|
||||||
|
private static Config _config;
|
||||||
|
private static readonly string _tag = "ClashConnectionsView";
|
||||||
|
|
||||||
public ClashConnectionsView()
|
public ClashConnectionsView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
_config = AppManager.Instance.Config;
|
||||||
|
|
||||||
ViewModel = new ClashConnectionsViewModel(UpdateViewHandler);
|
ViewModel = new ClashConnectionsViewModel(UpdateViewHandler);
|
||||||
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
|
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
|
||||||
|
|
||||||
|
|
@ -19,7 +25,15 @@ public partial class ClashConnectionsView : ReactiveUserControl<ClashConnections
|
||||||
this.Bind(ViewModel, vm => vm.HostFilter, v => v.txtHostFilter.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.HostFilter, v => v.txtHostFilter.Text).DisposeWith(disposables);
|
||||||
this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.btnConnectionCloseAll).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);
|
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)
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
||||||
|
|
@ -51,4 +65,74 @@ public partial class ClashConnectionsView : ReactiveUserControl<ClashConnections
|
||||||
{
|
{
|
||||||
ViewModel?.ClashConnectionClose(false);
|
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 item2 in lstConnections.Columns)
|
||||||
|
{
|
||||||
|
if (item2.Tag == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (item2.Tag.Equals(item.Name))
|
||||||
|
{
|
||||||
|
if (item.Width < 0)
|
||||||
|
{
|
||||||
|
item2.IsVisible = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel);
|
||||||
|
item2.DisplayIndex = displayIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StorageUI()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<ColumnItem> lvColumnItem = new();
|
||||||
|
foreach (var item2 in lstConnections.Columns)
|
||||||
|
{
|
||||||
|
if (item2.Tag == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lvColumnItem.Add(new()
|
||||||
|
{
|
||||||
|
Name = (string)item2.Tag,
|
||||||
|
Width = (int)(item2.IsVisible == true ? item2.ActualWidth : -1),
|
||||||
|
Index = item2.DisplayIndex
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_config.ClashUIItem.ConnectionsColumnItem = lvColumnItem;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion UI
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||||
{
|
{
|
||||||
private static Config _config;
|
private static Config _config;
|
||||||
private Window? _window;
|
private Window? _window;
|
||||||
|
private static readonly string _tag = "ProfilesView";
|
||||||
|
|
||||||
public ProfilesView()
|
public ProfilesView()
|
||||||
{
|
{
|
||||||
|
|
@ -381,7 +382,7 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logging.SaveLog("ProfilesView", ex);
|
Logging.SaveLog(_tag, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -399,53 +400,67 @@ public partial class ProfilesView : ReactiveUserControl<ProfilesViewModel>
|
||||||
|
|
||||||
private void RestoreUI()
|
private void RestoreUI()
|
||||||
{
|
{
|
||||||
var lvColumnItem = _config.UiItem.MainColumnItem.OrderBy(t => t.Index).ToList();
|
try
|
||||||
var displayIndex = 0;
|
|
||||||
foreach (var item in lvColumnItem)
|
|
||||||
{
|
{
|
||||||
|
var lvColumnItem = _config.UiItem.MainColumnItem.OrderBy(t => t.Index).ToList();
|
||||||
|
var displayIndex = 0;
|
||||||
|
foreach (var item in lvColumnItem)
|
||||||
|
{
|
||||||
|
foreach (var item2 in lstProfiles.Columns)
|
||||||
|
{
|
||||||
|
if (item2.Tag == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (item2.Tag.Equals(item.Name))
|
||||||
|
{
|
||||||
|
if (item.Width < 0)
|
||||||
|
{
|
||||||
|
item2.IsVisible = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel);
|
||||||
|
item2.DisplayIndex = displayIndex++;
|
||||||
|
}
|
||||||
|
if (item.Name.ToLower().StartsWith("to"))
|
||||||
|
{
|
||||||
|
item2.IsVisible = _config.GuiItem.EnableStatistics;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StorageUI()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<ColumnItem> lvColumnItem = new();
|
||||||
foreach (var item2 in lstProfiles.Columns)
|
foreach (var item2 in lstProfiles.Columns)
|
||||||
{
|
{
|
||||||
if (item2.Tag == null)
|
if (item2.Tag == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (item2.Tag.Equals(item.Name))
|
lvColumnItem.Add(new()
|
||||||
{
|
{
|
||||||
if (item.Width < 0)
|
Name = (string)item2.Tag,
|
||||||
{
|
Width = (int)(item2.IsVisible == true ? item2.ActualWidth : -1),
|
||||||
item2.IsVisible = false;
|
Index = item2.DisplayIndex
|
||||||
}
|
});
|
||||||
else
|
|
||||||
{
|
|
||||||
item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel);
|
|
||||||
item2.DisplayIndex = displayIndex++;
|
|
||||||
}
|
|
||||||
if (item.Name.ToLower().StartsWith("to"))
|
|
||||||
{
|
|
||||||
item2.IsVisible = _config.GuiItem.EnableStatistics;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_config.UiItem.MainColumnItem = lvColumnItem;
|
||||||
}
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
|
|
||||||
private void StorageUI()
|
|
||||||
{
|
|
||||||
List<ColumnItem> lvColumnItem = new();
|
|
||||||
foreach (var item2 in lstProfiles.Columns)
|
|
||||||
{
|
{
|
||||||
if (item2.Tag == null)
|
Logging.SaveLog(_tag, ex);
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
lvColumnItem.Add(new()
|
|
||||||
{
|
|
||||||
Name = (string)item2.Tag,
|
|
||||||
Width = (int)(item2.IsVisible == true ? item2.ActualWidth : -1),
|
|
||||||
Index = item2.DisplayIndex
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
_config.UiItem.MainColumnItem = lvColumnItem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion UI
|
#endregion UI
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue