diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 8d94edf5..c684acd1 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -1217,6 +1217,22 @@ namespace v2rayN.Handler return 0; } + public static int MoveToGroup(Config config, List lstProfile, string subid) + { + foreach (var it in lstProfile) + { + var item = LazyConfig.Instance.GetProfileItem(it.indexId); + if (item is null) + { + continue; + } + + item.subid = subid; + SqliteHelper.Instance.Update(item); + } + + return 0; + } #endregion #region UI diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 0aa7c627..d37516f9 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -807,6 +807,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Move to group 的本地化字符串。 + /// + public static string menuMoveToGroup { + get { + return ResourceManager.GetString("menuMoveToGroup", resourceCulture); + } + } + /// /// 查找类似 Move to top (T) 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index ac226435..d1158a43 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1060,4 +1060,7 @@ Show console + + Move to group + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index 5f1122ac..6caf0c56 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1060,4 +1060,7 @@ 显示控制台 + + 移至订阅分组 + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 45ee85cf..e8579c2c 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -62,6 +62,8 @@ namespace v2rayN.ViewModels [Reactive] public SubItem SelectedSub { get; set; } [Reactive] + public SubItem SelectedMoveToGroup { get; set; } + [Reactive] public RoutingItem SelectedRouting { get; set; } [Reactive] public ComboItem SelectedServer { get; set; } @@ -86,7 +88,7 @@ namespace v2rayN.ViewModels public ReactiveCommand CopyServerCmd { get; } public ReactiveCommand SetDefaultServerCmd { get; } public ReactiveCommand ShareServerCmd { get; } - //servers move + //servers move public ReactiveCommand MoveTopCmd { get; } public ReactiveCommand MoveUpCmd { get; } public ReactiveCommand MoveDownCmd { get; } @@ -205,6 +207,7 @@ namespace v2rayN.ViewModels SelectedProfile = new(); SelectedSub = new(); + SelectedMoveToGroup = new(); SelectedRouting = new(); SelectedServer = new(); @@ -220,6 +223,10 @@ namespace v2rayN.ViewModels x => x.SelectedSub, y => y != null && !y.remarks.IsNullOrEmpty() && _subId != y.id) .Subscribe(c => SubSelectedChanged(c)); + this.WhenAnyValue( + x => x.SelectedMoveToGroup, + y => y != null && !y.remarks.IsNullOrEmpty()) + .Subscribe(c => MoveToGroup(c)); this.WhenAnyValue( x => x.SelectedRouting, @@ -305,7 +312,7 @@ namespace v2rayN.ViewModels { ShareServer(); }, canEditRemove); - //servers move + //servers move MoveTopCmd = ReactiveCommand.Create(() => { MoveServer(EMove.Top); @@ -767,7 +774,7 @@ namespace v2rayN.ViewModels private int GetProfileItems(out List lstSelecteds) { lstSelecteds = new List(); - if (SelectedProfiles == null && SelectedProfiles.Count() <= 0) + if (SelectedProfiles == null || SelectedProfiles.Count() <= 0) { return -1; } @@ -1015,6 +1022,26 @@ namespace v2rayN.ViewModels } //move server + private void MoveToGroup(bool c) + { + if (!c) + { + return; + } + + if (GetProfileItems(out List lstSelecteds) < 0) + { + return; + } + + ConfigHandler.MoveToGroup(_config, lstSelecteds, SelectedMoveToGroup.id); + _noticeHandler?.Enqueue(ResUI.OperationSuccess); + + RefreshServers(); + SelectedMoveToGroup = new(); + //Reload(); + } + public void MoveServer(EMove eMove) { var item = _lstProfile.FirstOrDefault(t => t.indexId == SelectedProfile.indexId); diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 0c1790d8..a198b5c3 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -451,6 +451,23 @@ Height="{StaticResource MenuItemHeight}" Header="{x:Static resx:ResUI.menuShareServer}" /> + + + + + + + + + vm.ShareServerCmd, v => v.menuShareServer).DisposeWith(disposables); //servers move + this.OneWayBind(ViewModel, vm => vm.SubItems, v => v.cmbMoveToGroup.ItemsSource).DisposeWith(disposables); + this.Bind(ViewModel, vm => vm.SelectedMoveToGroup, v => v.cmbMoveToGroup.SelectedItem).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.MoveTopCmd, v => v.menuMoveTop).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.MoveUpCmd, v => v.menuMoveUp).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.MoveDownCmd, v => v.menuMoveDown).DisposeWith(disposables);