diff --git a/src/DayzServerTools.Application/ViewModels/RandomPresetViewModel.cs b/src/DayzServerTools.Application/ViewModels/RandomPresetViewModel.cs index f032bc9..816d597 100644 --- a/src/DayzServerTools.Application/ViewModels/RandomPresetViewModel.cs +++ b/src/DayzServerTools.Application/ViewModels/RandomPresetViewModel.cs @@ -1,7 +1,10 @@ using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; - +using CommunityToolkit.Mvvm.DependencyInjection; +using CommunityToolkit.Mvvm.Input; +using DayzServerTools.Application.Services; +using DayzServerTools.Application.Stores; using DayzServerTools.Library.Xml; namespace DayzServerTools.Application.ViewModels; @@ -9,6 +12,7 @@ namespace DayzServerTools.Application.ViewModels; public class RandomPresetViewModel: ObservableObject { private RandomPreset _model; + private readonly IDialogFactory _dialogFactory; public RandomPreset Model => _model; public string Name @@ -23,8 +27,20 @@ public double Chance } public ObservableCollection Items => _model.Items; + public RelayCommand ImportClassnamesCommand { get; } + public RandomPresetViewModel(RandomPreset model) { _model=model; - } + _dialogFactory = Ioc.Default.GetRequiredService(); + + ImportClassnamesCommand = new RelayCommand(ImportClassnames); + } + + protected void ImportClassnames() + { + var dialog = _dialogFactory.CreateClassnameImportDialog(); + dialog.Store = new PresetImportStore(Items); + dialog.ShowDialog(); + } } \ No newline at end of file diff --git a/src/DayzServerTools.Application/ViewModels/RandomPresetsViewModel.cs b/src/DayzServerTools.Application/ViewModels/RandomPresetsViewModel.cs index 8dcead7..b8d63fc 100644 --- a/src/DayzServerTools.Application/ViewModels/RandomPresetsViewModel.cs +++ b/src/DayzServerTools.Application/ViewModels/RandomPresetsViewModel.cs @@ -1,6 +1,6 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; - +using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using DayzServerTools.Application.Extensions; @@ -13,6 +13,9 @@ namespace DayzServerTools.Application.ViewModels; public partial class RandomPresetsViewModel : ProjectFileViewModel, IDisposable { + [ObservableProperty] + private RandomPresetViewModel selectedPreset; + public ObservableCollection CargoPresets { get; } = new(); public ObservableCollection AttachmentsPresets { get; } = new(); diff --git a/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml b/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml index b42011f..6a18d72 100644 --- a/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml +++ b/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml @@ -8,7 +8,8 @@ x:Name="root" d:DesignHeight="450" d:DesignWidth="800"> - Items: - + + + + + + diff --git a/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml.cs b/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml.cs index d0e8fad..5acbcae 100644 --- a/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml.cs +++ b/src/DayzServerTools.Windows/Controls/RandomPresetsGrid.xaml.cs @@ -27,9 +27,16 @@ public ObservableCollection ItemsSource get { return (ObservableCollection)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } + public object SelectedItem + { + get { return GetValue(SelectedItemProperty); } + set { SetValue(SelectedItemProperty, value); } + } public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(ObservableCollection), typeof(RandomPresetsGrid), new PropertyMetadata(default)); + public static readonly DependencyProperty SelectedItemProperty = + DependencyProperty.Register("SelectedItem", typeof(object), typeof(RandomPresetsGrid), new PropertyMetadata(default)); public RandomPresetsGrid() { diff --git a/src/DayzServerTools.Windows/Views/MainWindow.xaml b/src/DayzServerTools.Windows/Views/MainWindow.xaml index 36c9ea9..67347bf 100644 --- a/src/DayzServerTools.Windows/Views/MainWindow.xaml +++ b/src/DayzServerTools.Windows/Views/MainWindow.xaml @@ -289,6 +289,10 @@ + + + diff --git a/src/DayzServerTools.Windows/Views/RandomPresetsView.xaml b/src/DayzServerTools.Windows/Views/RandomPresetsView.xaml index 713abc3..aced64f 100644 --- a/src/DayzServerTools.Windows/Views/RandomPresetsView.xaml +++ b/src/DayzServerTools.Windows/Views/RandomPresetsView.xaml @@ -23,7 +23,8 @@ Cargo + ItemsSource="{Binding CargoPresets}" + SelectedItem="{Binding SelectedPreset, Mode=OneWayToSource}"/> + ItemsSource="{Binding AttachmentsPresets}" + SelectedItem="{Binding SelectedPreset, Mode=OneWayToSource}"/>