Bulk operations

This commit is contained in:
jliddev
2020-10-01 15:41:25 -05:00
parent adafdf128e
commit 887f35d065
6 changed files with 90 additions and 7 deletions

View File

@@ -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",

View File

@@ -29,6 +29,8 @@ namespace WowUp.WPF.ViewModels
private readonly ISessionService _sessionService;
private List<Addon> _addons;
private bool _disableUpdateLoad;
private IEnumerable<Addon> _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<AddonListItemViewModel> DisplayAddons { get; set; }
public ObservableCollection<WowClientType> 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>();
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<AddonListItemViewModel> 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;
}

View File

@@ -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">
<UserControl.Resources>
@@ -247,10 +248,21 @@
HorizontalGridLinesBrush="{StaticResource Dark2}"
RowHeaderWidth="0"
BorderThickness="0"
SelectionMode="Extended"
VirtualizingPanel.ScrollUnit="Pixel"
SelectionChanged="AddonGrid_SelectionChanged"
BorderBrush="Transparent"
Sorting="AddonGrid_Sorting">
<DataGrid.Resources>
<ContextMenu x:Key="MultiRowMenu"
DataContext="{Binding DataContext, Source={x:Reference AddonsViewControl}}"
Style="{StaticResource DarkMenu}">
<MenuItem Header="{Binding MultiRowMenuTitle}" IsEnabled="False" />
<MenuItem Header="Auto Update"
IsCheckable="True"
IsChecked="{Binding MultiRowMenuAutoUpdateCheck}"
Command="{Binding AutoUpdateCheckedCommand}" />
</ContextMenu>
<ContextMenu x:Key="RowMenu"
Style="{StaticResource DarkMenu}"
DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">
@@ -326,12 +338,15 @@
</DataGrid.Resources>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow" >
<Setter Property="ContextMenu" Value="{StaticResource RowMenu}" />
<Setter Property="ContextMenu" Value="{Binding DataContext.ActiveContextMenu, RelativeSource={RelativeSource AncestorType=UserControl}}" />
<Setter Property="Background" Value="{StaticResource Dark3}"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource Dark1}" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{StaticResource Purple4}" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
@@ -388,8 +403,7 @@
<DataTemplate>
<Border Padding="5">
<StackPanel Orientation="Horizontal" >
<TextBlock
Text="{Binding DataContext.LatestVersionHeaderText, RelativeSource={RelativeSource AncestorType=DataGrid}}"
<TextBlock Text="{Binding DataContext.LatestVersionHeaderText, RelativeSource={RelativeSource AncestorType=DataGrid}}"
TextWrapping="Wrap"
Style="{StaticResource labelTableHeader}" />
<Image Width="20"

View File

@@ -1,4 +1,7 @@
using System.Windows.Controls;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using WowUp.WPF.Extensions;
using WowUp.WPF.ViewModels;
@@ -46,7 +49,15 @@ namespace WowUp.WPF.Views
private void UserControl_Initialized(object sender, System.EventArgs e)
{
_viewModel.MultiRowMenu = (ContextMenu)AddonGrid.Resources["MultiRowMenu"];
_viewModel.RowMenu = (ContextMenu)AddonGrid.Resources["RowMenu"];
_viewModel.ViewInitializedCommand.Execute(e);
}
private void AddonGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItems = ((DataGrid)sender).SelectedItems.Cast<AddonListItemViewModel>();
_viewModel.OnDataGridSelectionChange(selectedItems);
}
}
}

View File

@@ -9,6 +9,7 @@
<Color x:Key="Purple1Color">#6B69D6</Color>
<Color x:Key="Purple2Color">#504FA1</Color>
<Color x:Key="Purple3Color">#383773</Color>
<Color x:Key="Purple4Color">#282836</Color>
<Color x:Key="White1Color">#FFFFFF</Color>
<Color x:Key="White2Color">#DDDDDD</Color>
<Color x:Key="White3Color">#CCCCCC</Color>
@@ -45,6 +46,7 @@
<SolidColorBrush x:Key="Purple1">#6B69D6</SolidColorBrush>
<SolidColorBrush x:Key="Purple2">#504FA1</SolidColorBrush>
<SolidColorBrush x:Key="Purple3">#383773</SolidColorBrush>
<SolidColorBrush x:Key="Purple4">#282836</SolidColorBrush>
<SolidColorBrush x:Key="Blue1Brush">#315891</SolidColorBrush>
<SolidColorBrush x:Key="Blue2Brush">#24416c</SolidColorBrush>
<SolidColorBrush x:Key="Highlight1Brush">#01BAEF</SolidColorBrush>

View File

@@ -10,7 +10,7 @@
<PackageId>WowUp</PackageId>
<Authors>Jliddev</Authors>
<Product>WowUp</Product>
<Version>1.18.0-beta.4</Version>
<Version>1.18.0-beta.5</Version>
<ApplicationIcon>wowup_logo_512np_RRT_icon.ico</ApplicationIcon>
<Copyright>jliddev</Copyright>
<PackageProjectUrl>https://wowup.io</PackageProjectUrl>