From 0e36dd9fc36ca1f08be254993e194be7f7347c1d Mon Sep 17 00:00:00 2001 From: rvost Date: Sun, 9 Oct 2022 15:33:54 +0300 Subject: [PATCH] Add Ribbon tab for Trader Config --- .../ViewModels/TraderCategoryViewModel.cs | 33 +++++--- .../ViewModels/TraderConfigViewModel.cs | 5 +- .../ViewModels/TraderViewModel.cs | 27 ++++-- .../ViewModels/WorkspaceViewModel.cs | 4 +- .../Controls/TraderCategoryControl.xaml | 17 ++-- .../Resources/IconsDictionary.xaml | 82 +++++++++++++++++++ .../Views/MainWindow.xaml | 44 +++++++++- .../Views/TraderConfigView.xaml | 7 +- 8 files changed, 184 insertions(+), 35 deletions(-) diff --git a/src/DayzServerTools.Application/ViewModels/TraderCategoryViewModel.cs b/src/DayzServerTools.Application/ViewModels/TraderCategoryViewModel.cs index 622d548..f22e02b 100644 --- a/src/DayzServerTools.Application/ViewModels/TraderCategoryViewModel.cs +++ b/src/DayzServerTools.Application/ViewModels/TraderCategoryViewModel.cs @@ -1,4 +1,5 @@ -using System.Collections.ObjectModel; +using System.Collections; +using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.DependencyInjection; @@ -16,6 +17,9 @@ public partial class TraderCategoryViewModel : ObservableObject private readonly IDialogFactory _dialogFactory; [ObservableProperty] private TraderCategory model; + [ObservableProperty] + [NotifyCanExecuteChangedFor(nameof(CopyItemsCommand), nameof(MoveItemsCommand))] + private IList selectedItems; public string Name { @@ -24,33 +28,40 @@ public string Name } public ObservableCollection Items => model.TraderItems; - public IRelayCommand CopyItemsCommand { get; } - public IRelayCommand MoveItemsCommand { get; } + public IRelayCommand CopyItemsCommand { get; } + public IRelayCommand MoveItemsCommand { get; } public TraderCategoryViewModel(TraderCategory model) { _dialogFactory = Ioc.Default.GetService(); this.model = model; - CopyItemsCommand = new RelayCommand(CopyItems); - MoveItemsCommand = new RelayCommand(MoveItems); + CopyItemsCommand = new RelayCommand(CopyItems, () => CanExecuteBatchCommand()); + MoveItemsCommand = new RelayCommand(MoveItems, () => CanExecuteBatchCommand()); } public TraderCategoryViewModel() : this(new TraderCategory()) { } - private void CopyItems(object cmdParam) + protected bool CanExecuteBatchCommand() => SelectedItems is not null; + protected void CopyItems() { - var list = (System.Collections.IList)cmdParam; - var items = list.Cast(); + if (SelectedItems is null) + { + return; + } + var items = SelectedItems.Cast(); var dialog = _dialogFactory.CreateExportDialog(); dialog.Store = new TraderItemsExportStore(items, true); dialog.ShowDialog(); } - private void MoveItems(object cmdParam) + protected void MoveItems() { - var list = (System.Collections.IList)cmdParam; - var items = new List(list.Cast()); + if (SelectedItems is null) + { + return; + } + var items = SelectedItems.Cast(); var dialog = _dialogFactory.CreateExportDialog(); dialog.Store = new TraderItemsExportStore(items, true); diff --git a/src/DayzServerTools.Application/ViewModels/TraderConfigViewModel.cs b/src/DayzServerTools.Application/ViewModels/TraderConfigViewModel.cs index db5f7b7..f25590b 100644 --- a/src/DayzServerTools.Application/ViewModels/TraderConfigViewModel.cs +++ b/src/DayzServerTools.Application/ViewModels/TraderConfigViewModel.cs @@ -1,7 +1,7 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; + using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; using DayzServerTools.Application.ViewModels.Base; using DayzServerTools.Application.Models; @@ -13,6 +13,9 @@ namespace DayzServerTools.Application.ViewModels { public partial class TraderConfigViewModel : ProjectFileViewModel, IDisposable { + [ObservableProperty] + private TraderViewModel selectedTrader; + public ObservableCollection Traders { get; } = new(); public CurrencyCategory CurrencyCategory { diff --git a/src/DayzServerTools.Application/ViewModels/TraderViewModel.cs b/src/DayzServerTools.Application/ViewModels/TraderViewModel.cs index 0cabf79..67a7e85 100644 --- a/src/DayzServerTools.Application/ViewModels/TraderViewModel.cs +++ b/src/DayzServerTools.Application/ViewModels/TraderViewModel.cs @@ -13,6 +13,9 @@ public partial class TraderViewModel : ObservableObject, IDisposable [ObservableProperty] [NotifyPropertyChangedFor(nameof(Name), nameof(Categories))] private Trader model = new(); + [ObservableProperty] + [NotifyCanExecuteChangedFor(nameof(RemoveCategoryCommand))] + private TraderCategoryViewModel selectedCategory; public string Name { @@ -32,10 +35,26 @@ public TraderViewModel(Trader trader) ); AddCategoryCommand = new RelayCommand(AddCategory); - RemoveCategoryCommand = new RelayCommand(RemoveCategory); + RemoveCategoryCommand = new RelayCommand(RemoveCategory, CanRemoveCategory); Categories.CollectionChanged += CategoriesCollectionChanged; } + protected void AddCategory(string categoryName) + => Categories.Add(new(new TraderCategory() { CategoryName = categoryName })); + protected bool CanRemoveCategory(TraderCategoryViewModel category) + => category is not null || SelectedCategory is not null; + protected void RemoveCategory(TraderCategoryViewModel category) + { + if (category is not null) + { + Categories.Remove(category); + } + else if (SelectedCategory is not null) + { + Categories.Remove(SelectedCategory); + SelectedCategory = null; + } + } private void CategoriesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { @@ -58,12 +77,6 @@ private void CategoriesCollectionChanged(object sender, NotifyCollectionChangedE } } - public void AddCategory(string categoryName) - => Categories.Add(new(new TraderCategory() { CategoryName = categoryName })); - - public void RemoveCategory(TraderCategoryViewModel category) - => Categories.Remove(category); - public void Dispose() { Categories.CollectionChanged -= CategoriesCollectionChanged; diff --git a/src/DayzServerTools.Application/ViewModels/WorkspaceViewModel.cs b/src/DayzServerTools.Application/ViewModels/WorkspaceViewModel.cs index 1d8c11c..7831784 100644 --- a/src/DayzServerTools.Application/ViewModels/WorkspaceViewModel.cs +++ b/src/DayzServerTools.Application/ViewModels/WorkspaceViewModel.cs @@ -35,7 +35,8 @@ public partial class WorkspaceViewModel : TabbedViewModel [NotifyCanExecuteChangedFor(nameof(LoadUserDefinitionsCommand))] private UserDefinitions userDefinitions = null; [ObservableProperty] - [NotifyPropertyChangedFor(nameof(ActiveFileIsUserDefinitions), nameof(ActiveFileIsItemTypes))] + [NotifyPropertyChangedFor(nameof(ActiveFileIsUserDefinitions), nameof(ActiveFileIsItemTypes), + nameof(ActiveFileIsTraderConfig))] private IProjectFileTab activeFile; private object activePane; @@ -53,6 +54,7 @@ public object ActivePane } public bool ActiveFileIsUserDefinitions => ActiveFile is UserDefinitionsViewModel; public bool ActiveFileIsItemTypes => ActiveFile is ItemTypesViewModel; + public bool ActiveFileIsTraderConfig => ActiveFile is TraderConfigViewModel; public ErrorsPaneViewModel ErrorsPaneViewModel => _errorsPaneViewModel; [ObservableProperty] private ObservableCollection usages = new(); diff --git a/src/DayzServerTools.Windows/Controls/TraderCategoryControl.xaml b/src/DayzServerTools.Windows/Controls/TraderCategoryControl.xaml index 049a607..c0e6a8f 100644 --- a/src/DayzServerTools.Windows/Controls/TraderCategoryControl.xaml +++ b/src/DayzServerTools.Windows/Controls/TraderCategoryControl.xaml @@ -13,7 +13,7 @@ CommandParameter="{Binding}"/> - + - + + Command="{Binding CopyItemsCommand}"/> + Command="{Binding MoveItemsCommand}"/> @@ -69,6 +64,6 @@ - + diff --git a/src/DayzServerTools.Windows/Resources/IconsDictionary.xaml b/src/DayzServerTools.Windows/Resources/IconsDictionary.xaml index 081f04c..d9e9ef8 100644 --- a/src/DayzServerTools.Windows/Resources/IconsDictionary.xaml +++ b/src/DayzServerTools.Windows/Resources/IconsDictionary.xaml @@ -124,6 +124,38 @@ + + + + + + + 0.75 + + + + + + + + + + + + + + + + + + + + + + + @@ -244,6 +276,31 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -424,6 +481,31 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/DayzServerTools.Windows/Views/MainWindow.xaml b/src/DayzServerTools.Windows/Views/MainWindow.xaml index 5b440e2..2b03185 100644 --- a/src/DayzServerTools.Windows/Views/MainWindow.xaml +++ b/src/DayzServerTools.Windows/Views/MainWindow.xaml @@ -14,6 +14,15 @@ WindowState="Maximized" d:Height="800" d:Width="1200"> +