2025-01-30 09:10:05 +00:00
|
|
|
using System.Reactive.Disposables;
|
2024-12-02 06:40:09 +00:00
|
|
|
using Avalonia.Controls;
|
2024-08-29 07:48:51 +00:00
|
|
|
using Avalonia.Interactivity;
|
|
|
|
|
using Avalonia.ReactiveUI;
|
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
namespace v2rayN.Desktop.Views;
|
|
|
|
|
|
|
|
|
|
public partial class ClashConnectionsView : ReactiveUserControl<ClashConnectionsViewModel>
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
public ClashConnectionsView()
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
InitializeComponent();
|
|
|
|
|
ViewModel = new ClashConnectionsViewModel(UpdateViewHandler);
|
|
|
|
|
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
this.WhenActivated(disposables =>
|
|
|
|
|
{
|
|
|
|
|
this.OneWayBind(ViewModel, vm => vm.ConnectionItems, v => v.lstConnections.ItemsSource).DisposeWith(disposables);
|
|
|
|
|
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstConnections.SelectedItem).DisposeWith(disposables);
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
this.BindCommand(ViewModel, vm => vm.ConnectionCloseCmd, v => v.menuConnectionClose).DisposeWith(disposables);
|
|
|
|
|
this.BindCommand(ViewModel, vm => vm.ConnectionCloseAllCmd, v => v.menuConnectionCloseAll).DisposeWith(disposables);
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(true);
|
|
|
|
|
}
|
2024-12-02 06:40:09 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void BtnAutofitColumnWidth_Click(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AutofitColumnWidth();
|
|
|
|
|
}
|
2024-12-02 06:40:09 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void AutofitColumnWidth()
|
|
|
|
|
{
|
2025-05-07 06:28:55 +00:00
|
|
|
try
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-05-07 06:28:55 +00:00
|
|
|
foreach (var it in lstConnections.Columns)
|
|
|
|
|
{
|
|
|
|
|
it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logging.SaveLog("ClashConnectionsView", ex);
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
|
|
|
|
|
private void btnClose_Click(object? sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ViewModel?.ClashConnectionClose(false);
|
|
|
|
|
}
|
2025-01-30 09:10:05 +00:00
|
|
|
}
|