This commit is contained in:
DHR60 2025-09-11 14:36:37 +08:00
parent 00ed1edf92
commit 73c2a203de
4 changed files with 34 additions and 7 deletions

View file

@ -1,3 +1,4 @@
using System.Data;
using System.Reactive;
using DynamicData.Binding;
using ReactiveUI;
@ -105,7 +106,13 @@ public class AddGroupServerViewModel : MyReactiveObject
NoticeManager.Instance.Enqueue(ResUI.PleaseSelectServer);
return;
}
ChildItemsObs.Remove(SelectedChild);
foreach (var it in SelectedChildren ?? [SelectedChild])
{
if (it != null)
{
ChildItemsObs.Remove(it);
}
}
await Task.CompletedTask;
}
@ -121,6 +128,7 @@ public class AddGroupServerViewModel : MyReactiveObject
{
return;
}
var selectedChild = JsonUtils.DeepCopy(SelectedChild);
switch (eMove)
{
case EMove.Top:
@ -129,7 +137,7 @@ public class AddGroupServerViewModel : MyReactiveObject
return;
}
ChildItemsObs.RemoveAt(index);
ChildItemsObs.Insert(0, SelectedChild);
ChildItemsObs.Insert(0, selectedChild);
break;
case EMove.Up:
if (index == 0)
@ -137,7 +145,7 @@ public class AddGroupServerViewModel : MyReactiveObject
return;
}
ChildItemsObs.RemoveAt(index);
ChildItemsObs.Insert(index - 1, SelectedChild);
ChildItemsObs.Insert(index - 1, selectedChild);
break;
case EMove.Down:
if (index == ChildItemsObs.Count - 1)
@ -145,7 +153,7 @@ public class AddGroupServerViewModel : MyReactiveObject
return;
}
ChildItemsObs.RemoveAt(index);
ChildItemsObs.Insert(index + 1, SelectedChild);
ChildItemsObs.Insert(index + 1, selectedChild);
break;
case EMove.Bottom:
if (index == ChildItemsObs.Count - 1)
@ -153,7 +161,7 @@ public class AddGroupServerViewModel : MyReactiveObject
return;
}
ChildItemsObs.RemoveAt(index);
ChildItemsObs.Add(SelectedChild);
ChildItemsObs.Add(selectedChild);
break;
default:
break;
@ -183,7 +191,7 @@ public class AddGroupServerViewModel : MyReactiveObject
var childIndexIds = new List<string>();
foreach (var item in ChildItemsObs)
{
if (item.IndexId.IsNotEmpty())
if (!item.IndexId.IsNullOrEmpty())
{
childIndexIds.Add(item.IndexId);
}

View file

@ -21,6 +21,7 @@ public partial class AddGroupServerWindow : WindowBase<AddGroupServerViewModel>
this.Loaded += Window_Loaded;
btnCancel.Click += (s, e) => this.Close();
lstChild.SelectionChanged += LstChild_SelectionChanged;
ViewModel = new AddGroupServerViewModel(profileItem, UpdateViewHandler);
@ -145,4 +146,13 @@ public partial class AddGroupServerWindow : WindowBase<AddGroupServerViewModel>
ViewModel?.ChildItemsObs.AddRange(profiles);
}
}
private void LstChild_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (ViewModel != null)
{
ViewModel.SelectedChildren = lstChild.SelectedItems.Cast<ProfileItem>().ToList();
}
}
}

View file

@ -73,7 +73,6 @@
Style="{StaticResource ModuleTitle}"
Text="{x:Static resx:ResUI.menuServers}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"

View file

@ -15,6 +15,7 @@ public partial class AddGroupServerWindow
this.Owner = Application.Current.MainWindow;
this.Loaded += Window_Loaded;
this.PreviewKeyDown += AddGroupServerWindow_PreviewKeyDown;
lstChild.SelectionChanged += LstChild_SelectionChanged;
ViewModel = new AddGroupServerViewModel(profileItem, UpdateViewHandler);
@ -46,6 +47,7 @@ public partial class AddGroupServerWindow
this.Bind(ViewModel, vm => vm.PolicyGroupType, v => v.cmbPolicyGroupType.Text).DisposeWith(disposables);
this.OneWayBind(ViewModel, vm => vm.ChildItemsObs, v => v.lstChild.ItemsSource).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedChild, v => v.lstChild.SelectedItem).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.RemoveCmd, v => v.menuRemoveChildServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.MoveTopCmd, v => v.menuMoveTop).DisposeWith(disposables);
@ -120,4 +122,12 @@ public partial class AddGroupServerWindow
ViewModel?.ChildItemsObs.AddRange(profiles);
}
}
private void LstChild_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (ViewModel != null)
{
ViewModel.SelectedChildren = lstChild.SelectedItems.Cast<ProfileItem>().ToList();
}
}
}