From 887f35d065b9517dd67bfd6220163e49b34cacec Mon Sep 17 00:00:00 2001 From: jliddev Date: Thu, 1 Oct 2020 15:41:25 -0500 Subject: [PATCH] Bulk operations --- WowUp.WPF/Assets/changelog.json | 2 +- WowUp.WPF/ViewModels/AddonsViewViewModel.cs | 58 ++++++++++++++++++++- WowUp.WPF/Views/AddonsView.xaml | 20 +++++-- WowUp.WPF/Views/AddonsView.xaml.cs | 13 ++++- WowUp.WPF/Views/Styles.xaml | 2 + WowUp.WPF/WowUp.WPF.csproj | 2 +- 6 files changed, 90 insertions(+), 7 deletions(-) diff --git a/WowUp.WPF/Assets/changelog.json b/WowUp.WPF/Assets/changelog.json index 863f3f1c..4428b933 100644 --- a/WowUp.WPF/Assets/changelog.json +++ b/WowUp.WPF/Assets/changelog.json @@ -2,7 +2,7 @@ "ChangeLogs": [ { "Version": "1.18.0", - "Description": "Add an 'Open Folder' option to the addon context menu (By Xathz).\nFeatured addons are now sorted by download count." + "Description": "Add an 'Open Folder' option to the addon context menu (By Xathz).\nAdd new ability to manually select your initial WoW client folder if the intial auto detection fails.\nNew ability to perform bulk operations on 'My Addons' page.\nFeatured addons are now sorted by download count." }, { "Version": "1.17.1", diff --git a/WowUp.WPF/ViewModels/AddonsViewViewModel.cs b/WowUp.WPF/ViewModels/AddonsViewViewModel.cs index 59a8a469..eea913c6 100644 --- a/WowUp.WPF/ViewModels/AddonsViewViewModel.cs +++ b/WowUp.WPF/ViewModels/AddonsViewViewModel.cs @@ -29,6 +29,8 @@ namespace WowUp.WPF.ViewModels private readonly ISessionService _sessionService; private List _addons; + private bool _disableUpdateLoad; + private IEnumerable _selectedAddons; private string _busyText; public string BusyText @@ -170,6 +172,27 @@ namespace WowUp.WPF.ViewModels set { SetProperty(ref _selectedClientType, value); } } + private ContextMenu _activeContextMenu; + public ContextMenu ActiveContextMenu + { + get => _activeContextMenu; + set { SetProperty(ref _activeContextMenu, value); } + } + + private string _multiRowMenuTitle; + public string MultiRowMenuTitle + { + get => _multiRowMenuTitle; + set { SetProperty(ref _multiRowMenuTitle, value); } + } + + private bool _multiRowMenuAutoUpdateCheck; + public bool MultiRowMenuAutoUpdateCheck + { + get => _multiRowMenuAutoUpdateCheck; + set { SetProperty(ref _multiRowMenuAutoUpdateCheck, value); } + } + public SearchInputViewModel SearchInputViewModel { get; set; } public Command LoadItemsCommand { get; set; } @@ -181,6 +204,10 @@ namespace WowUp.WPF.ViewModels public Command SelectedWowClientCommand { get; set; } public Command GridSortingCommand { get; set; } public Command ViewInitializedCommand { get; set; } + public Command AutoUpdateCheckedCommand { get; set; } + + public ContextMenu MultiRowMenu { get; set; } + public ContextMenu RowMenu { get; set; } public ObservableCollection DisplayAddons { get; set; } public ObservableCollection ClientTypeNames { get; set; } @@ -244,6 +271,7 @@ namespace WowUp.WPF.ViewModels SelectedWowClientCommand = new Command(async () => await OnSelectedWowClientChanged(SelectedClientType)); GridSortingCommand = new Command((args) => OnGridSorting(args as DataGridSortingEventArgs)); ViewInitializedCommand = new Command(() => OnViewInitialized()); + AutoUpdateCheckedCommand = new Command(() => OnAutoUpdateCheckedCommand()); SearchInputViewModel = serviceProvider.GetService(); SearchInputViewModel.TextChanged += SearchInputViewModel_TextChanged; @@ -261,6 +289,34 @@ namespace WowUp.WPF.ViewModels Initialize(); } + private async void OnAutoUpdateCheckedCommand() + { + _disableUpdateLoad = true; + foreach (var addon in _selectedAddons) + { + addon.AutoUpdateEnabled = MultiRowMenuAutoUpdateCheck; + _addonService.UpdateAddon(addon); + + var listItem = DisplayAddons.FirstOrDefault(item => item.Addon.Id == addon.Id); + listItem.IsAutoUpdated = addon.AutoUpdateEnabled; + } + _disableUpdateLoad = false; + } + + public void OnDataGridSelectionChange(IEnumerable selectedItems) + { + _selectedAddons = selectedItems.Select(item => item.Addon); + MultiRowMenuTitle = selectedItems.Count() > 1 + ? $"{selectedItems.Count()} addons selected" + : string.Empty; + + ActiveContextMenu = selectedItems.Count() > 1 + ? MultiRowMenu + : RowMenu; + + MultiRowMenuAutoUpdateCheck = selectedItems.All(item => item.IsAutoUpdated); + } + private void SessionService_TabChanged(object sender, Type tabType) { SetAddonCountContextText(DisplayAddons.Count); @@ -579,7 +635,7 @@ namespace WowUp.WPF.ViewModels private void AddonUpdated(Addon addon) { - if (IsBusy) + if (IsBusy || _disableUpdateLoad) { return; } diff --git a/WowUp.WPF/Views/AddonsView.xaml b/WowUp.WPF/Views/AddonsView.xaml index 7c61efe1..1b96825b 100644 --- a/WowUp.WPF/Views/AddonsView.xaml +++ b/WowUp.WPF/Views/AddonsView.xaml @@ -9,6 +9,7 @@ xmlns:vw = "clr-namespace:WowUp.WPF.Views" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" + x:Name="AddonsViewControl" Initialized="UserControl_Initialized"> @@ -247,10 +248,21 @@ HorizontalGridLinesBrush="{StaticResource Dark2}" RowHeaderWidth="0" BorderThickness="0" + SelectionMode="Extended" VirtualizingPanel.ScrollUnit="Pixel" + SelectionChanged="AddonGrid_SelectionChanged" BorderBrush="Transparent" Sorting="AddonGrid_Sorting"> + + + + @@ -326,12 +338,15 @@ @@ -388,8 +403,7 @@ - (); + _viewModel.OnDataGridSelectionChange(selectedItems); + } } } diff --git a/WowUp.WPF/Views/Styles.xaml b/WowUp.WPF/Views/Styles.xaml index 817205de..571b5e5f 100644 --- a/WowUp.WPF/Views/Styles.xaml +++ b/WowUp.WPF/Views/Styles.xaml @@ -9,6 +9,7 @@ #6B69D6 #504FA1 #383773 + #282836 #FFFFFF #DDDDDD #CCCCCC @@ -45,6 +46,7 @@ #6B69D6 #504FA1 #383773 + #282836 #315891 #24416c #01BAEF diff --git a/WowUp.WPF/WowUp.WPF.csproj b/WowUp.WPF/WowUp.WPF.csproj index 71815a9b..75301237 100644 --- a/WowUp.WPF/WowUp.WPF.csproj +++ b/WowUp.WPF/WowUp.WPF.csproj @@ -10,7 +10,7 @@ WowUp Jliddev WowUp - 1.18.0-beta.4 + 1.18.0-beta.5 wowup_logo_512np_RRT_icon.ico jliddev https://wowup.io