This commit is contained in:
DHR60 2025-09-06 19:19:34 +08:00
parent f9ea8d83d0
commit 0085e0a507
4 changed files with 34 additions and 1 deletions

View file

@ -27,6 +27,7 @@
<Button <Button
x:Name="btnSave" x:Name="btnSave"
Width="100" Width="100"
Click="BtnSave_Click"
Content="{x:Static resx:ResUI.TbConfirm}" /> Content="{x:Static resx:ResUI.TbConfirm}" />
<Button <Button
x:Name="btnCancel" x:Name="btnCancel"
@ -83,6 +84,9 @@
IsReadOnly="True" IsReadOnly="True"
ItemsSource="{Binding ProfileItems}" ItemsSource="{Binding ProfileItems}"
SelectionMode="Single"> SelectionMode="Single">
<DataGrid.KeyBindings>
<KeyBinding Command="{Binding SelectFinish}" Gesture="Enter" />
</DataGrid.KeyBindings>
<DataGrid.Columns> <DataGrid.Columns>
<DataGridTextColumn <DataGridTextColumn
Width="80" Width="80"

View file

@ -18,6 +18,7 @@ public partial class ProfilesSelectWindow : ReactiveWindow<ProfilesSelectViewMod
private static Config _config; private static Config _config;
public Task<ProfileItem?> ProfileItem => GetFirstProfileItemAsync(); public Task<ProfileItem?> ProfileItem => GetFirstProfileItemAsync();
private bool _allowMultiSelect = false;
public ProfilesSelectWindow() public ProfilesSelectWindow()
{ {
@ -51,6 +52,7 @@ public partial class ProfilesSelectWindow : ReactiveWindow<ProfilesSelectViewMod
public void AllowMultiSelect(bool allow) public void AllowMultiSelect(bool allow)
{ {
_allowMultiSelect = allow;
if (allow) if (allow)
{ {
lstProfiles.SelectionMode = DataGridSelectionMode.Extended; lstProfiles.SelectionMode = DataGridSelectionMode.Extended;
@ -113,7 +115,11 @@ public partial class ProfilesSelectWindow : ReactiveWindow<ProfilesSelectViewMod
{ {
if (e.Key == Key.A) if (e.Key == Key.A)
{ {
lstProfiles.SelectAll(); if (_allowMultiSelect)
{
lstProfiles.SelectAll();
}
e.Handled = true;
} }
} }
else else
@ -121,6 +127,7 @@ public partial class ProfilesSelectWindow : ReactiveWindow<ProfilesSelectViewMod
if (e.Key is Key.Enter or Key.Return) if (e.Key is Key.Enter or Key.Return)
{ {
ViewModel?.SelectFinish(); ViewModel?.SelectFinish();
e.Handled = true;
} }
} }
} }
@ -157,4 +164,10 @@ public partial class ProfilesSelectWindow : ReactiveWindow<ProfilesSelectViewMod
var item = await ViewModel?.GetProfileItem(); var item = await ViewModel?.GetProfileItem();
return item; return item;
} }
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
// Trigger selection finalize when Confirm is clicked
ViewModel?.SelectFinish();
}
} }

View file

@ -35,6 +35,7 @@
Width="100" Width="100"
Content="{x:Static resx:ResUI.TbConfirm}" Content="{x:Static resx:ResUI.TbConfirm}"
IsDefault="True" IsDefault="True"
Click="BtnSave_Click"
Style="{StaticResource DefButton}" /> Style="{StaticResource DefButton}" />
<Button <Button
x:Name="btnCancel" x:Name="btnCancel"

View file

@ -16,6 +16,7 @@ public partial class ProfilesSelectWindow
private static Config _config; private static Config _config;
public Task<ProfileItem?> ProfileItem => GetFirstProfileItemAsync(); public Task<ProfileItem?> ProfileItem => GetFirstProfileItemAsync();
private bool _allowMultiSelect = false;
public ProfilesSelectWindow() public ProfilesSelectWindow()
{ {
@ -46,6 +47,7 @@ public partial class ProfilesSelectWindow
public void AllowMultiSelect(bool allow) public void AllowMultiSelect(bool allow)
{ {
_allowMultiSelect = allow;
if (allow) if (allow)
{ {
lstProfiles.SelectionMode = DataGridSelectionMode.Extended; lstProfiles.SelectionMode = DataGridSelectionMode.Extended;
@ -108,6 +110,10 @@ public partial class ProfilesSelectWindow
private void menuSelectAll_Click(object sender, RoutedEventArgs e) private void menuSelectAll_Click(object sender, RoutedEventArgs e)
{ {
if (!_allowMultiSelect)
{
return;
}
lstProfiles.SelectAll(); lstProfiles.SelectAll();
} }
@ -119,6 +125,7 @@ public partial class ProfilesSelectWindow
{ {
case Key.A: case Key.A:
menuSelectAll_Click(null, null); menuSelectAll_Click(null, null);
e.Handled = true;
break; break;
} }
} }
@ -127,6 +134,7 @@ public partial class ProfilesSelectWindow
if (e.Key is Key.Enter or Key.Return) if (e.Key is Key.Enter or Key.Return)
{ {
ViewModel?.SelectFinish(); ViewModel?.SelectFinish();
e.Handled = true;
} }
} }
} }
@ -156,6 +164,7 @@ public partial class ProfilesSelectWindow
if (e.Key is Key.Enter or Key.Return) if (e.Key is Key.Enter or Key.Return)
{ {
ViewModel?.RefreshServers(); ViewModel?.RefreshServers();
e.Handled = true;
} }
} }
@ -164,5 +173,11 @@ public partial class ProfilesSelectWindow
var item = await ViewModel?.GetProfileItem(); var item = await ViewModel?.GetProfileItem();
return item; return item;
} }
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
// Trigger selection finalize when Confirm is clicked
ViewModel?.SelectFinish();
}
#endregion Event #endregion Event
} }