Skip to content

Commit 947c84c

Browse files
committed
Refactor 'Move to Group' menu in ProfilesView
1 parent 9c74b51 commit 947c84c

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public class ProfilesViewModel : MyReactiveObject
5656

5757
public ReactiveCommand<Unit, Unit> MoveUpCmd { get; }
5858
public ReactiveCommand<Unit, Unit> MoveDownCmd { get; }
59-
public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; }
59+
public ReactiveCommand<Unit, Unit> MoveBottomCmd { get; }
60+
public ReactiveCommand<SubItem, Unit> MoveToGroupCmd { get; }
6061

6162
//servers ping
6263
public ReactiveCommand<Unit, Unit> MixedTestServerCmd { get; }
@@ -179,6 +180,10 @@ public ProfilesViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
179180
{
180181
await MoveServer(EMove.Bottom);
181182
}, canEditRemove);
183+
MoveToGroupCmd = ReactiveCommand.CreateFromTask<SubItem>(async sub =>
184+
{
185+
SelectedMoveToGroup = sub;
186+
});
182187

183188
//servers ping
184189
FastRealPingCmd = ReactiveCommand.CreateFromTask(async () =>

v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
88
xmlns:resx="clr-namespace:ServiceLib.Resx;assembly=ServiceLib"
99
xmlns:vms="clr-namespace:ServiceLib.ViewModels;assembly=ServiceLib"
10+
x:Name="Root"
1011
d:DesignHeight="450"
1112
d:DesignWidth="800"
1213
x:DataType="vms:ProfilesViewModel"
@@ -141,19 +142,18 @@
141142
InputGesture="Ctrl+T" />
142143
<MenuItem x:Name="menuSortServerResult" Header="{x:Static resx:ResUI.menuSortServerResult}" />
143144
<Separator />
144-
<MenuItem x:Name="menuMoveToGroup" Header="{x:Static resx:ResUI.menuMoveToGroup}">
145-
<MenuItem>
146-
<MenuItem.Header>
147-
<DockPanel>
148-
<ComboBox
149-
x:Name="cmbMoveToGroup"
150-
Width="200"
151-
DisplayMemberBinding="{Binding Remarks}"
152-
ItemsSource="{Binding SubItems}"
153-
ToolTip.Tip="{x:Static resx:ResUI.menuSubscription}" />
154-
</DockPanel>
155-
</MenuItem.Header>
156-
</MenuItem>
145+
<MenuItem
146+
x:Name="menuMoveToGroup"
147+
Header="{x:Static resx:ResUI.menuMoveToGroup}"
148+
ItemsSource="{Binding DataContext.SubItems, ElementName=Root}">
149+
<MenuItem.ItemTemplate>
150+
<DataTemplate>
151+
<MenuItem
152+
Command="{Binding DataContext.MoveToGroupCmd, ElementName=Root}"
153+
CommandParameter="{Binding}"
154+
Header="{Binding Remarks}" />
155+
</DataTemplate>
156+
</MenuItem.ItemTemplate>
157157
</MenuItem>
158158
<MenuItem Header="{x:Static resx:ResUI.menuMoveTo}">
159159
<MenuItem

v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public ProfilesView(Window window)
6969

7070
//servers move
7171
//this.OneWayBind(ViewModel, vm => vm.SubItems, v => v.cmbMoveToGroup.ItemsSource).DisposeWith(disposables);
72-
this.Bind(ViewModel, vm => vm.SelectedMoveToGroup, v => v.cmbMoveToGroup.SelectedItem).DisposeWith(disposables);
72+
//this.Bind(ViewModel, vm => vm.SelectedMoveToGroup, v => v.cmbMoveToGroup.SelectedItem).DisposeWith(disposables);
7373

7474
this.BindCommand(ViewModel, vm => vm.MoveTopCmd, v => v.menuMoveTop).DisposeWith(disposables);
7575
this.BindCommand(ViewModel, vm => vm.MoveUpCmd, v => v.menuMoveUp).DisposeWith(disposables);

0 commit comments

Comments
 (0)