From 9eb9898b61da52fc9473eb960126ed0a1decee23 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Mon, 2 Dec 2024 14:40:09 +0800
Subject: [PATCH] Improve the clash connection

---
 .../Views/ClashConnectionsView.axaml            | 17 +++++++++++++++++
 .../Views/ClashConnectionsView.axaml.cs         | 15 +++++++++++++++
 v2rayN/v2rayN/Views/ClashConnectionsView.xaml   | 11 ++++++++++-
 .../v2rayN/Views/ClashConnectionsView.xaml.cs   | 14 ++++++++++++++
 4 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml
index dd1c94ac..7318e7de 100644
--- a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml
+++ b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml
@@ -42,6 +42,23 @@
                 </Button.Content>
             </Button>
 
+            <Button
+                x:Name="btnAutofitColumnWidth"
+                Width="30"
+                Height="30"
+                Margin="8,0"
+                Classes="Success"
+                Theme="{DynamicResource BorderlessButton}"
+                ToolTip.Tip="{x:Static resx:ResUI.menuProfileAutofitColumnWidth}">
+                <Button.Content>
+                    <PathIcon
+                        Width="20"
+                        Height="20"
+                        Data="{StaticResource building_fit}"
+                        Foreground="{DynamicResource ButtonDefaultTertiaryForeground}" />
+                </Button.Content>
+            </Button>
+
             <TextBlock
                 Margin="8,0"
                 VerticalAlignment="Center"
diff --git a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs
index 48201b7c..297d2c11 100644
--- a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs
+++ b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs
@@ -1,3 +1,4 @@
+using Avalonia.Controls;
 using Avalonia.Interactivity;
 using Avalonia.ReactiveUI;
 using Avalonia.Threading;
@@ -12,6 +13,7 @@ namespace v2rayN.Desktop.Views
         {
             InitializeComponent();
             ViewModel = new ClashConnectionsViewModel(UpdateViewHandler);
+            btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
 
             this.WhenActivated(disposables =>
             {
@@ -42,6 +44,19 @@ namespace v2rayN.Desktop.Views
             return await Task.FromResult(true);
         }
 
+        private void BtnAutofitColumnWidth_Click(object? sender, RoutedEventArgs e)
+        {
+            AutofitColumnWidth();
+        }
+
+        private void AutofitColumnWidth()
+        {
+            foreach (var it in lstConnections.Columns)
+            {
+                it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);
+            }
+        }
+
         private void btnClose_Click(object? sender, RoutedEventArgs e)
         {
             ViewModel?.ClashConnectionClose(false);
diff --git a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml
index 88f6b3d1..779354e7 100644
--- a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml
+++ b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml
@@ -39,6 +39,16 @@
                 <materialDesign:PackIcon VerticalAlignment="Center" Kind="Close" />
             </Button>
 
+            <Button
+                x:Name="btnAutofitColumnWidth"
+                Width="24"
+                Height="24"
+                Margin="{StaticResource MarginLeftRight8}"
+                Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}"
+                ToolTip="{x:Static resx:ResUI.menuProfileAutofitColumnWidth}">
+                <materialDesign:PackIcon VerticalAlignment="Center" Kind="ArrowSplitVertical" />
+            </Button>
+
             <TextBlock
                 Margin="{StaticResource MarginLeftRight8}"
                 VerticalAlignment="Center"
@@ -56,7 +66,6 @@
             BorderThickness="1"
             CanUserAddRows="False"
             CanUserResizeRows="False"
-            CanUserSortColumns="False"
             EnableRowVirtualization="True"
             GridLinesVisibility="All"
             HeadersVisibility="Column"
diff --git a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs
index 059f8ad6..9de1ceae 100644
--- a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs
+++ b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs
@@ -1,6 +1,7 @@
 using ReactiveUI;
 using System.Reactive.Disposables;
 using System.Windows;
+using System.Windows.Controls;
 using System.Windows.Threading;
 
 namespace v2rayN.Views
@@ -14,6 +15,7 @@ namespace v2rayN.Views
         {
             InitializeComponent();
             ViewModel = new ClashConnectionsViewModel(UpdateViewHandler);
+            btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
 
             this.WhenActivated(disposables =>
             {
@@ -45,6 +47,18 @@ namespace v2rayN.Views
             return await Task.FromResult(true);
         }
 
+        private void BtnAutofitColumnWidth_Click(object sender, RoutedEventArgs e)
+        {
+            AutofitColumnWidth();
+        }
+        private void AutofitColumnWidth()
+        {
+            foreach (var it in lstConnections.Columns)
+            {
+                it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);
+            }
+        }
+
         private void btnClose_Click(object sender, System.Windows.RoutedEventArgs e)
         {
             ViewModel?.ClashConnectionClose(false);