mirror of https://github.com/2dust/v2rayN
Autofit Column Width
parent
c7297dba7e
commit
12ebad436a
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace v2rayN.Mode
|
||||||
|
{
|
||||||
|
public enum EViewAction
|
||||||
|
{
|
||||||
|
AdjustMainLvColWidth,
|
||||||
|
ProfilesFocus
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ namespace v2rayN.ViewModels
|
||||||
private NoticeHandler? _noticeHandler;
|
private NoticeHandler? _noticeHandler;
|
||||||
private readonly PaletteHelper _paletteHelper = new();
|
private readonly PaletteHelper _paletteHelper = new();
|
||||||
private Dictionary<string, bool> _dicHeaderSort = new();
|
private Dictionary<string, bool> _dicHeaderSort = new();
|
||||||
private Action<string> _updateView;
|
private Action<EViewAction> _updateView;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
#region Init
|
#region Init
|
||||||
|
|
||||||
public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Action<string> updateView)
|
public MainWindowViewModel(ISnackbarMessageQueue snackbarMessageQueue, Action<EViewAction> updateView)
|
||||||
{
|
{
|
||||||
_updateView = updateView;
|
_updateView = updateView;
|
||||||
ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false);
|
ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false);
|
||||||
|
@ -549,7 +549,7 @@ namespace v2rayN.ViewModels
|
||||||
}
|
}
|
||||||
if (_config.uiItem.enableAutoAdjustMainLvColWidth)
|
if (_config.uiItem.enableAutoAdjustMainLvColWidth)
|
||||||
{
|
{
|
||||||
_updateView("AdjustMainLvColWidth");
|
_updateView(EViewAction.AdjustMainLvColWidth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -702,7 +702,7 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
RefreshServers();
|
RefreshServers();
|
||||||
|
|
||||||
_updateView("ProfilesFocus");
|
_updateView(EViewAction.ProfilesFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ServerFilterChanged(bool c)
|
private void ServerFilterChanged(bool c)
|
||||||
|
|
|
@ -378,6 +378,14 @@
|
||||||
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
||||||
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Plus" />
|
<materialDesign:PackIcon VerticalAlignment="Center" Kind="Plus" />
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
x:Name="btnAutofitColumnWidth"
|
||||||
|
Width="30"
|
||||||
|
Height="30"
|
||||||
|
Margin="4,0"
|
||||||
|
Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}">
|
||||||
|
<materialDesign:PackIcon VerticalAlignment="Center" Kind="ArrowSplitVertical" />
|
||||||
|
</Button>
|
||||||
<TextBox
|
<TextBox
|
||||||
x:Name="txtServerFilter"
|
x:Name="txtServerFilter"
|
||||||
Width="200"
|
Width="200"
|
||||||
|
@ -484,7 +492,6 @@
|
||||||
CanUserSortColumns="False"
|
CanUserSortColumns="False"
|
||||||
EnableRowVirtualization="True"
|
EnableRowVirtualization="True"
|
||||||
Focusable="True"
|
Focusable="True"
|
||||||
FrozenColumnCount="1"
|
|
||||||
GridLinesVisibility="All"
|
GridLinesVisibility="All"
|
||||||
HeadersVisibility="All"
|
HeadersVisibility="All"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
|
@ -616,11 +623,11 @@
|
||||||
<EventSetter Event="Click" Handler="LstProfiles_ColumnHeader_Click" />
|
<EventSetter Event="Click" Handler="LstProfiles_ColumnHeader_Click" />
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
<Style TargetType="DataGridCell" BasedOn="{StaticResource MaterialDesignDataGridCell}">
|
<Style BasedOn="{StaticResource MaterialDesignDataGridCell}" TargetType="DataGridCell">
|
||||||
<Style.Triggers>
|
<Style.Triggers>
|
||||||
<DataTrigger Binding="{Binding isActive}" Value="True">
|
<DataTrigger Binding="{Binding isActive}" Value="True">
|
||||||
<Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}"/>
|
<Setter Property="Background" Value="{DynamicResource PrimaryHueLightBrush}" />
|
||||||
<Setter Property="Foreground" Value="Black"></Setter>
|
<Setter Property="Foreground" Value="Black" />
|
||||||
</DataTrigger>
|
</DataTrigger>
|
||||||
</Style.Triggers>
|
</Style.Triggers>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace v2rayN.Views
|
||||||
App.Current.SessionEnding += Current_SessionEnding;
|
App.Current.SessionEnding += Current_SessionEnding;
|
||||||
this.Closing += MainWindow_Closing;
|
this.Closing += MainWindow_Closing;
|
||||||
this.PreviewKeyDown += MainWindow_PreviewKeyDown;
|
this.PreviewKeyDown += MainWindow_PreviewKeyDown;
|
||||||
|
btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click;
|
||||||
lstProfiles.PreviewKeyDown += LstProfiles_PreviewKeyDown;
|
lstProfiles.PreviewKeyDown += LstProfiles_PreviewKeyDown;
|
||||||
lstProfiles.SelectionChanged += lstProfiles_SelectionChanged;
|
lstProfiles.SelectionChanged += lstProfiles_SelectionChanged;
|
||||||
lstProfiles.LoadingRow += LstProfiles_LoadingRow;
|
lstProfiles.LoadingRow += LstProfiles_LoadingRow;
|
||||||
|
@ -206,19 +207,16 @@ namespace v2rayN.Views
|
||||||
|
|
||||||
#region Event
|
#region Event
|
||||||
|
|
||||||
private void UpdateViewHandler(string action)
|
private void UpdateViewHandler(EViewAction action)
|
||||||
{
|
{
|
||||||
if (action == "AdjustMainLvColWidth")
|
if (action == EViewAction.AdjustMainLvColWidth)
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
foreach (var it in lstProfiles.Columns)
|
AutofitColumnWidth();
|
||||||
{
|
|
||||||
it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (action == "ProfilesFocus")
|
else if (action == EViewAction.ProfilesFocus)
|
||||||
{
|
{
|
||||||
lstProfiles.Focus();
|
lstProfiles.Focus();
|
||||||
}
|
}
|
||||||
|
@ -278,16 +276,6 @@ namespace v2rayN.Views
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colHeader.Column.GetType().Name != typeof(MyDGTextColumn).Name)
|
|
||||||
{
|
|
||||||
foreach (var it in lstProfiles.Columns)
|
|
||||||
{
|
|
||||||
//it.MinWidth = it.ActualWidth;
|
|
||||||
it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var colName = ((MyDGTextColumn)colHeader.Column).ExName;
|
var colName = ((MyDGTextColumn)colHeader.Column).ExName;
|
||||||
ViewModel?.SortServer(colName);
|
ViewModel?.SortServer(colName);
|
||||||
}
|
}
|
||||||
|
@ -408,6 +396,18 @@ namespace v2rayN.Views
|
||||||
{
|
{
|
||||||
Utils.ProcessStart(Utils.GetBinPath("EnableLoopback.exe"));
|
Utils.ProcessStart(Utils.GetBinPath("EnableLoopback.exe"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BtnAutofitColumnWidth_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
AutofitColumnWidth();
|
||||||
|
}
|
||||||
|
private void AutofitColumnWidth()
|
||||||
|
{
|
||||||
|
foreach (var it in lstProfiles.Columns)
|
||||||
|
{
|
||||||
|
it.Width = new DataGridLength(1, DataGridLengthUnitType.Auto);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region UI
|
#region UI
|
||||||
|
@ -452,7 +452,7 @@ namespace v2rayN.Views
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item2.Width = item.Width;
|
item2.Width = item.Width;
|
||||||
item2.DisplayIndex = i + 1;
|
item2.DisplayIndex = i ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue