Skip to content

Commit f11b46e

Browse files
committed
Fix
1 parent e6c57fc commit f11b46e

File tree

5 files changed

+103
-11
lines changed

5 files changed

+103
-11
lines changed

v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,33 @@ from t33 in t3b.DefaultIfEmpty()
277277
return item;
278278
}
279279

280+
public async Task<List<ProfileItem>?> GetProfileItems()
281+
{
282+
if (SelectedProfiles == null || SelectedProfiles.Count == 0)
283+
{
284+
return null;
285+
}
286+
var lst = new List<ProfileItem>();
287+
foreach (var sp in SelectedProfiles)
288+
{
289+
if (string.IsNullOrEmpty(sp?.IndexId))
290+
{
291+
continue;
292+
}
293+
var item = await AppManager.Instance.GetProfileItem(sp.IndexId);
294+
if (item != null)
295+
{
296+
lst.Add(item);
297+
}
298+
}
299+
if (lst.Count == 0)
300+
{
301+
NoticeManager.Instance.Enqueue(ResUI.PleaseSelectServer);
302+
return null;
303+
}
304+
return lst;
305+
}
306+
280307
public void SortServer(string colName)
281308
{
282309
if (colName.IsNullOrEmpty())

v2rayN/v2rayN.Desktop/Views/ProfilesSelectWindow.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Width="800"
1212
Height="450"
1313
x:DataType="vms:ProfilesSelectViewModel"
14+
WindowStartupLocation="CenterScreen"
1415
mc:Ignorable="d">
1516

1617
<Window.Resources>
@@ -27,6 +28,7 @@
2728
<Button
2829
x:Name="btnSave"
2930
Width="100"
31+
Click="BtnSave_Click"
3032
Content="{x:Static resx:ResUI.TbConfirm}" />
3133
<Button
3234
x:Name="btnCancel"
@@ -83,14 +85,17 @@
8385
IsReadOnly="True"
8486
ItemsSource="{Binding ProfileItems}"
8587
SelectionMode="Single">
88+
<DataGrid.KeyBindings>
89+
<KeyBinding Command="{Binding SelectFinish}" Gesture="Enter" />
90+
</DataGrid.KeyBindings>
8691
<DataGrid.Columns>
8792
<DataGridTextColumn
8893
Width="80"
8994
Binding="{Binding ConfigType}"
9095
Header="{x:Static resx:ResUI.LvServiceType}"
9196
Tag="ConfigType" />
9297

93-
<DataGridTemplateColumn Tag="Remarks">
98+
<DataGridTemplateColumn Tag="Remarks" SortMemberPath="Remarks">
9499
<DataGridTemplateColumn.Header>
95100
<TextBlock Text="{x:Static resx:ResUI.LvRemarks}" />
96101
</DataGridTemplateColumn.Header>

v2rayN/v2rayN.Desktop/Views/ProfilesSelectWindow.axaml.cs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System.Threading.Tasks;
44
using Avalonia;
55
using Avalonia.Controls;
6+
using Avalonia.Controls.Primitives;
67
using Avalonia.Input;
78
using Avalonia.Interactivity;
89
using Avalonia.Markup.Xaml;
10+
using Avalonia.VisualTree;
911
using Avalonia.ReactiveUI;
1012
using ReactiveUI;
1113
using ServiceLib.Manager;
@@ -17,7 +19,9 @@ public partial class ProfilesSelectWindow : ReactiveWindow<ProfilesSelectViewMod
1719
{
1820
private static Config _config;
1921

20-
public Task<ProfileItem?> ProfileItem => GetFirstProfileItemAsync();
22+
public Task<ProfileItem?> ProfileItem => GetProfileItem();
23+
public Task<List<ProfileItem>?> ProfileItems => GetProfileItems();
24+
private bool _allowMultiSelect = false;
2125

2226
public ProfilesSelectWindow()
2327
{
@@ -45,12 +49,12 @@ public ProfilesSelectWindow()
4549
this.Bind(ViewModel, vm => vm.ServerFilter, v => v.txtServerFilter.Text).DisposeWith(disposables);
4650
});
4751

48-
btnSave.Click += (s, e) => ViewModel?.SelectFinish();
4952
btnCancel.Click += (s, e) => Close(false);
5053
}
5154

5255
public void AllowMultiSelect(bool allow)
5356
{
57+
_allowMultiSelect = allow;
5458
if (allow)
5559
{
5660
lstProfiles.SelectionMode = DataGridSelectionMode.Extended;
@@ -94,17 +98,32 @@ private void LstProfiles_LoadingRow(object? sender, DataGridRowEventArgs e)
9498

9599
private void LstProfiles_DoubleTapped(object? sender, TappedEventArgs e)
96100
{
97-
ViewModel?.SelectFinish();
101+
// 忽略表头区域的双击
102+
if (e.Source is Control src)
103+
{
104+
if (src.FindAncestorOfType<DataGridColumnHeader>() != null)
105+
{
106+
e.Handled = true;
107+
return;
108+
}
109+
110+
// 仅当在数据行或其子元素上双击时才触发选择
111+
if (src.FindAncestorOfType<DataGridRow>() != null)
112+
{
113+
ViewModel?.SelectFinish();
114+
e.Handled = true;
115+
}
116+
}
98117
}
99118

100-
private async void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e)
119+
private void LstProfiles_Sorting(object? sender, DataGridColumnEventArgs e)
101120
{
121+
// 自定义排序,防止默认行为导致误触发
102122
e.Handled = true;
103123
if (ViewModel != null && e.Column?.Tag?.ToString() != null)
104124
{
105-
await ViewModel.SortServer(e.Column.Tag.ToString());
125+
ViewModel.SortServer(e.Column.Tag.ToString());
106126
}
107-
e.Handled = false;
108127
}
109128

110129
private void LstProfiles_KeyDown(object? sender, KeyEventArgs e)
@@ -113,14 +132,19 @@ private void LstProfiles_KeyDown(object? sender, KeyEventArgs e)
113132
{
114133
if (e.Key == Key.A)
115134
{
116-
lstProfiles.SelectAll();
135+
if (_allowMultiSelect)
136+
{
137+
lstProfiles.SelectAll();
138+
}
139+
e.Handled = true;
117140
}
118141
}
119142
else
120143
{
121144
if (e.Key is Key.Enter or Key.Return)
122145
{
123146
ViewModel?.SelectFinish();
147+
e.Handled = true;
124148
}
125149
}
126150
}
@@ -152,9 +176,21 @@ private void TxtServerFilter_KeyDown(object? sender, KeyEventArgs e)
152176
}
153177
}
154178

155-
public async Task<ProfileItem?> GetFirstProfileItemAsync()
179+
public async Task<ProfileItem?> GetProfileItem()
156180
{
157181
var item = await ViewModel?.GetProfileItem();
158182
return item;
159183
}
184+
185+
public async Task<List<ProfileItem>?> GetProfileItems()
186+
{
187+
var item = await ViewModel?.GetProfileItems();
188+
return item;
189+
}
190+
191+
private void BtnSave_Click(object sender, RoutedEventArgs e)
192+
{
193+
// Trigger selection finalize when Confirm is clicked
194+
ViewModel?.SelectFinish();
195+
}
160196
}

v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Height="450"
1616
x:TypeArguments="vms:ProfilesSelectViewModel"
1717
Style="{StaticResource WindowGlobal}"
18+
WindowStartupLocation="CenterScreen"
1819
mc:Ignorable="d">
1920

2021
<Window.Resources>
@@ -33,6 +34,7 @@
3334
<Button
3435
x:Name="btnSave"
3536
Width="100"
37+
Click="BtnSave_Click"
3638
Content="{x:Static resx:ResUI.TbConfirm}"
3739
IsDefault="True"
3840
Style="{StaticResource DefButton}" />

v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public partial class ProfilesSelectWindow
1515
{
1616
private static Config _config;
1717

18-
public Task<ProfileItem?> ProfileItem => GetFirstProfileItemAsync();
18+
public Task<ProfileItem?> ProfileItem => GetProfileItem();
19+
public Task<List<ProfileItem>?> ProfileItems => GetProfileItems();
20+
private bool _allowMultiSelect = false;
1921

2022
public ProfilesSelectWindow()
2123
{
@@ -46,6 +48,7 @@ public ProfilesSelectWindow()
4648

4749
public void AllowMultiSelect(bool allow)
4850
{
51+
_allowMultiSelect = allow;
4952
if (allow)
5053
{
5154
lstProfiles.SelectionMode = DataGridSelectionMode.Extended;
@@ -108,6 +111,10 @@ private void LstProfiles_ColumnHeader_Click(object sender, RoutedEventArgs e)
108111

109112
private void menuSelectAll_Click(object sender, RoutedEventArgs e)
110113
{
114+
if (!_allowMultiSelect)
115+
{
116+
return;
117+
}
111118
lstProfiles.SelectAll();
112119
}
113120

@@ -119,6 +126,7 @@ private void LstProfiles_PreviewKeyDown(object sender, KeyEventArgs e)
119126
{
120127
case Key.A:
121128
menuSelectAll_Click(null, null);
129+
e.Handled = true;
122130
break;
123131
}
124132
}
@@ -127,6 +135,7 @@ private void LstProfiles_PreviewKeyDown(object sender, KeyEventArgs e)
127135
if (e.Key is Key.Enter or Key.Return)
128136
{
129137
ViewModel?.SelectFinish();
138+
e.Handled = true;
130139
}
131140
}
132141
}
@@ -156,13 +165,26 @@ private void TxtServerFilter_PreviewKeyDown(object sender, KeyEventArgs e)
156165
if (e.Key is Key.Enter or Key.Return)
157166
{
158167
ViewModel?.RefreshServers();
168+
e.Handled = true;
159169
}
160170
}
161171

162-
public async Task<ProfileItem?> GetFirstProfileItemAsync()
172+
public async Task<ProfileItem?> GetProfileItem()
163173
{
164174
var item = await ViewModel?.GetProfileItem();
165175
return item;
166176
}
177+
178+
public async Task<List<ProfileItem>?> GetProfileItems()
179+
{
180+
var item = await ViewModel?.GetProfileItems();
181+
return item;
182+
}
183+
184+
private void BtnSave_Click(object sender, RoutedEventArgs e)
185+
{
186+
// Trigger selection finalize when Confirm is clicked
187+
ViewModel?.SelectFinish();
188+
}
167189
#endregion Event
168190
}

0 commit comments

Comments
 (0)