feat: add collapsible header and groups, card size slider and Crowdin translations
- Add a button that collapses a collection page's header to its title, game count and dynamic badge. The choice is remembered for all collections. - Make each group on a collection page collapsible, with a Collapse all / Expand all button next to Group by. Games hidden by a collapse leave the selection. - Add a card size slider to the collection page toolbar, remembered for all collections. - Match the search box and sort button height to the dropdowns. - Add Crowdin configuration and a workflow that uploads the English strings and opens pull requests with new translations. - Add CONTRIBUTING.md and a Translations section to the README. - Run the build workflow on master instead of main. - Bump the version to 1.3.0 and update the docs, changelog and manifest.
This commit is contained in:
1 parent
b9a6bf891d
commit
089f3e0f23
17 files changed
+494
-30
No files matched your search
@@ -7,7 +7,7 @@
|
||||
<RootNamespace>GameCollections</RootNamespace>
|
||||
<AssemblyName>GameCollections</AssemblyName>
|
||||
<LangVersion>7.3</LangVersion>
|
||||
<Version>1.2.0</Version>
|
||||
<Version>1.3.0</Version>
|
||||
<Product>Game Collections</Product>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
|
||||
@@ -154,6 +154,13 @@
|
||||
<sys:String x:Key="LOCGameCollections_GroupInstallStatus">Install status</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupInstalled">Installed</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_GroupNotInstalled">Not installed</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_CollapseAllGroups">Collapse all</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_ExpandAllGroups">Expand all</sys:String>
|
||||
|
||||
<!-- Collection page layout -->
|
||||
<sys:String x:Key="LOCGameCollections_CollapseHeader">Collapse header</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_ExpandHeader">Expand header</sys:String>
|
||||
<sys:String x:Key="LOCGameCollections_CardSize">Card size</sys:String>
|
||||
|
||||
<!-- Manual order -->
|
||||
<sys:String x:Key="LOCGameCollections_MoveToTop">Move to top</sys:String>
|
||||
|
||||
@@ -12,6 +12,13 @@ namespace GameCollections.Settings
|
||||
private CollectionsViewMode viewMode = CollectionsViewMode.Grid;
|
||||
public CollectionsViewMode ViewMode { get => viewMode; set => SetValue(ref viewMode, value); }
|
||||
|
||||
// Also remembered UI state: the collection page's header and the size of its game cards.
|
||||
private bool collectionHeaderCollapsed;
|
||||
public bool CollectionHeaderCollapsed { get => collectionHeaderCollapsed; set => SetValue(ref collectionHeaderCollapsed, value); }
|
||||
|
||||
private double gameCardWidth = 130;
|
||||
public double GameCardWidth { get => gameCardWidth; set => SetValue(ref gameCardWidth, value); }
|
||||
|
||||
private bool showDynamicCollectionsInDetails = true;
|
||||
public bool ShowDynamicCollectionsInDetails { get => showDynamicCollectionsInDetails; set => SetValue(ref showDynamicCollectionsInDetails, value); }
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace GameCollections.ViewModels
|
||||
{
|
||||
@@ -238,12 +239,74 @@ namespace GameCollections.ViewModels
|
||||
set
|
||||
{
|
||||
manager.SetGroupBy(CollectionId, value);
|
||||
collapsedGroups.Clear();
|
||||
ApplyGrouping();
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(IsGrouped));
|
||||
RaiseReorderChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsGrouped => GroupBy != GameGroupField.None;
|
||||
|
||||
// Names of the groups the user has collapsed. Kept by name so the state survives the
|
||||
// groups being rebuilt when the search or filters change.
|
||||
private readonly HashSet<string> collapsedGroups = new HashSet<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Raised when groups are collapsed or expanded from the view model, so the view can update its expanders.
|
||||
/// </summary>
|
||||
public event EventHandler GroupExpansionChanged;
|
||||
|
||||
private IEnumerable<string> GroupNames => GamesView.Groups?.Cast<CollectionViewGroup>().Select(g => (string)g.Name) ?? Enumerable.Empty<string>();
|
||||
public bool AllGroupsCollapsed => IsGrouped && GroupNames.Any() && GroupNames.All(collapsedGroups.Contains);
|
||||
public string ToggleAllGroupsText => Loc.Get(AllGroupsCollapsed ? "LOCGameCollections_ExpandAllGroups" : "LOCGameCollections_CollapseAllGroups");
|
||||
|
||||
/// <summary>
|
||||
/// Hides the poster, description and buttons, leaving the title, game count and dynamic badge.
|
||||
/// Shared by all collection pages and remembered between sessions.
|
||||
/// </summary>
|
||||
public bool IsHeaderCollapsed
|
||||
{
|
||||
get => root.Settings.Settings.CollectionHeaderCollapsed;
|
||||
set
|
||||
{
|
||||
root.Settings.Settings.CollectionHeaderCollapsed = value;
|
||||
root.Settings.Save();
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(HeaderToggleGlyph));
|
||||
OnPropertyChanged(nameof(HeaderToggleTooltip));
|
||||
}
|
||||
}
|
||||
|
||||
public string HeaderToggleGlyph => IsHeaderCollapsed ? DescendingGlyph : AscendingGlyph;
|
||||
public string HeaderToggleTooltip => Loc.Get(IsHeaderCollapsed ? "LOCGameCollections_ExpandHeader" : "LOCGameCollections_CollapseHeader");
|
||||
|
||||
public const double MinCardWidth = 80;
|
||||
public const double MaxCardWidth = 260;
|
||||
private const double CardAspectRatio = 1.5;
|
||||
|
||||
/// <summary>
|
||||
/// Width of the game cards, set with the size slider. Shared by all collection pages.
|
||||
/// </summary>
|
||||
public double CardWidth
|
||||
{
|
||||
get => Math.Max(MinCardWidth, Math.Min(MaxCardWidth, root.Settings.Settings.GameCardWidth));
|
||||
set
|
||||
{
|
||||
root.Settings.Settings.GameCardWidth = Math.Max(MinCardWidth, Math.Min(MaxCardWidth, value));
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged(nameof(CardHeight));
|
||||
// The slider changes the value many times a second, so the settings file is written once it settles.
|
||||
cardSizeSaveTimer.Stop();
|
||||
cardSizeSaveTimer.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public double CardHeight => CardWidth * CardAspectRatio;
|
||||
|
||||
private readonly DispatcherTimer cardSizeSaveTimer;
|
||||
|
||||
public bool IsEmpty => Games.Count == 0;
|
||||
public bool HasNoResults => !IsEmpty && GamesView.Count == 0;
|
||||
// With groups, a game can be in the view several times but is still one game.
|
||||
@@ -260,6 +323,8 @@ namespace GameCollections.ViewModels
|
||||
public RelayCommand PlaySelectedCommand { get; }
|
||||
public RelayCommand RefreshCommand { get; }
|
||||
public RelayCommand OpenInCollectionsCommand { get; }
|
||||
public RelayCommand ToggleHeaderCommand { get; }
|
||||
public RelayCommand ToggleAllGroupsCommand { get; }
|
||||
|
||||
public CollectionDetailsViewModel(IPlayniteAPI playniteApi, CollectionManager manager, CollectionsRootViewModel root, CollectionCardViewModel header)
|
||||
{
|
||||
@@ -268,6 +333,13 @@ namespace GameCollections.ViewModels
|
||||
this.root = root;
|
||||
Header = header;
|
||||
|
||||
cardSizeSaveTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(500) };
|
||||
cardSizeSaveTimer.Tick += (s, e) =>
|
||||
{
|
||||
cardSizeSaveTimer.Stop();
|
||||
root.Settings.Save();
|
||||
};
|
||||
|
||||
GamesView = new ListCollectionView(Games) { Filter = FilterGame };
|
||||
ApplySort();
|
||||
ApplyGrouping();
|
||||
@@ -289,6 +361,8 @@ namespace GameCollections.ViewModels
|
||||
PlaySelectedCommand = new RelayCommand(PlaySelected);
|
||||
RefreshCommand = new RelayCommand(() => manager.RefreshCollection(CollectionId));
|
||||
OpenInCollectionsCommand = new RelayCommand(() => root.ShowInCollectionsSection(CollectionId));
|
||||
ToggleHeaderCommand = new RelayCommand(() => IsHeaderCollapsed = !IsHeaderCollapsed);
|
||||
ToggleAllGroupsCommand = new RelayCommand(ToggleAllGroups);
|
||||
|
||||
Reload();
|
||||
}
|
||||
@@ -448,6 +522,54 @@ namespace GameCollections.ViewModels
|
||||
return selected.Contains(tile) ? selected : new List<CollectionGameViewModel> { tile };
|
||||
}
|
||||
|
||||
public bool IsGroupCollapsed(object groupName)
|
||||
{
|
||||
return groupName is string name && collapsedGroups.Contains(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records a group being collapsed or expanded by its own header.
|
||||
/// </summary>
|
||||
public void SetGroupCollapsed(object groupName, bool collapsed)
|
||||
{
|
||||
if (!(groupName is string name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (collapsed)
|
||||
{
|
||||
collapsedGroups.Add(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
collapsedGroups.Remove(name);
|
||||
}
|
||||
|
||||
RaiseGroupStateChanged();
|
||||
}
|
||||
|
||||
private void ToggleAllGroups()
|
||||
{
|
||||
if (AllGroupsCollapsed)
|
||||
{
|
||||
collapsedGroups.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
collapsedGroups.UnionWith(GroupNames);
|
||||
}
|
||||
|
||||
GroupExpansionChanged?.Invoke(this, EventArgs.Empty);
|
||||
RaiseGroupStateChanged();
|
||||
}
|
||||
|
||||
private void RaiseGroupStateChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(AllGroupsCollapsed));
|
||||
OnPropertyChanged(nameof(ToggleAllGroupsText));
|
||||
}
|
||||
|
||||
private void RaiseReorderChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(CanReorder));
|
||||
@@ -535,6 +657,7 @@ namespace GameCollections.ViewModels
|
||||
OnPropertyChanged(nameof(IsEmpty));
|
||||
OnPropertyChanged(nameof(HasNoResults));
|
||||
OnPropertyChanged(nameof(VisibleCountText));
|
||||
RaiseGroupStateChanged();
|
||||
}
|
||||
|
||||
private class GameTileComparer : IComparer
|
||||
|
||||
@@ -34,11 +34,14 @@ namespace GameCollections.ViewModels
|
||||
public GameSortField GameSortField { get; set; } = GameSortField.CollectionOrder;
|
||||
public bool GameSortDescending { get; set; }
|
||||
|
||||
public GameCollectionsSettingsViewModel Settings { get; }
|
||||
|
||||
public CollectionsRootViewModel(IPlayniteAPI playniteApi, CollectionManager manager, DialogService dialogs, GameCollectionsSettingsViewModel settings)
|
||||
{
|
||||
this.playniteApi = playniteApi;
|
||||
this.manager = manager;
|
||||
this.dialogs = dialogs;
|
||||
Settings = settings;
|
||||
Home = new CollectionsHomeViewModel(manager, this, settings);
|
||||
CurrentPage = Home;
|
||||
manager.CollectionsChanged += OnCollectionsChanged;
|
||||
|
||||
@@ -41,8 +41,9 @@
|
||||
</Style>
|
||||
|
||||
<DataTemplate x:Key="GameTemplate" DataType="{x:Type vm:CollectionGameViewModel}">
|
||||
<StackPanel Width="130">
|
||||
<Grid Width="130" Height="195">
|
||||
<!-- Sized by the card size slider on the page. -->
|
||||
<StackPanel Width="{Binding DataContext.CardWidth, RelativeSource={RelativeSource AncestorType=ListBox}}">
|
||||
<Grid Height="{Binding DataContext.CardHeight, RelativeSource={RelativeSource AncestorType=ListBox}}">
|
||||
<local:PosterImage GlyphSize="40" Glyph="" Source="{Binding Cover}" />
|
||||
<!-- Dim games that are not installed, as Playnite's own grid does. -->
|
||||
<Border Background="#80000000" CornerRadius="4" IsHitTestVisible="False"
|
||||
@@ -69,25 +70,38 @@
|
||||
</Button>
|
||||
|
||||
<!-- Collection header -->
|
||||
<!-- Collapsing it leaves only the title, game count and dynamic badge. -->
|
||||
<Grid DockPanel.Dock="Top" Margin="0,15,0,15">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<local:PosterImage Width="140" Height="210" GlyphSize="52" Source="{Binding Header.Poster}" VerticalAlignment="Top" />
|
||||
<StackPanel Grid.Column="1" Margin="20,0,0,0">
|
||||
<local:PosterImage Width="140" Height="210" GlyphSize="52" Source="{Binding Header.Poster}" VerticalAlignment="Top"
|
||||
Margin="0,0,20,0"
|
||||
Visibility="{Binding IsHeaderCollapsed, Converter={StaticResource InverseBoolToVisibility}}" />
|
||||
<Button Grid.Column="2" Style="{StaticResource GcIconButton}" VerticalAlignment="Top" Margin="10,0,0,0"
|
||||
Content="{Binding HeaderToggleGlyph}"
|
||||
Command="{Binding ToggleHeaderCommand}"
|
||||
ToolTip="{Binding HeaderToggleTooltip}"
|
||||
AutomationProperties.Name="{Binding HeaderToggleTooltip}" />
|
||||
<StackPanel Grid.Column="1">
|
||||
<TextBlock Text="{Binding Header.Title}" Style="{StaticResource GcPageTitleText}" TextWrapping="Wrap" />
|
||||
<StackPanel Orientation="Horizontal" Margin="0,8,0,0">
|
||||
<TextBlock Text="" Style="{StaticResource GcGlyph}"
|
||||
Foreground="{DynamicResource GlyphBrush}" Margin="0,0,5,0" />
|
||||
<TextBlock Text="{Binding Header.RatingText}" Style="{StaticResource GcText}" />
|
||||
<TextBlock Text="•" Style="{StaticResource GcMutedText}" Margin="10,0" />
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Visibility="{Binding IsHeaderCollapsed, Converter={StaticResource InverseBoolToVisibility}}">
|
||||
<TextBlock Text="" Style="{StaticResource GcGlyph}"
|
||||
Foreground="{DynamicResource GlyphBrush}" Margin="0,0,5,0" />
|
||||
<TextBlock Text="{Binding Header.RatingText}" Style="{StaticResource GcText}" />
|
||||
<TextBlock Text="•" Style="{StaticResource GcMutedText}" Margin="10,0" />
|
||||
</StackPanel>
|
||||
<TextBlock Text="{Binding Header.GameCountText}" Style="{StaticResource GcMutedText}" />
|
||||
<Border Style="{StaticResource GcBadge}" Margin="10,0,0,0"
|
||||
Visibility="{Binding IsDynamic, Converter={StaticResource BoolToVisibility}}">
|
||||
<TextBlock Text="{DynamicResource LOCGameCollections_DynamicBadge}" Style="{StaticResource GcBadgeText}" />
|
||||
</Border>
|
||||
</StackPanel>
|
||||
<StackPanel Visibility="{Binding IsHeaderCollapsed, Converter={StaticResource InverseBoolToVisibility}}">
|
||||
<TextBlock Text="{Binding RulesSummary}" Style="{StaticResource GcMutedText}"
|
||||
TextWrapping="Wrap" Margin="0,8,0,0"
|
||||
Visibility="{Binding RulesSummary, Converter={StaticResource HasValueToVisibility}}" />
|
||||
@@ -125,26 +139,42 @@
|
||||
</StackPanel>
|
||||
</Button>
|
||||
</WrapPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Toolbar: search, sort, filter -->
|
||||
<!-- Toolbar: search, sort, group, filter. The search box and buttons take the dropdowns'
|
||||
height, which comes from the theme, so the row lines up in any theme. -->
|
||||
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,10">
|
||||
<TextBlock DockPanel.Dock="Right" Text="{Binding VisibleCountText}" Style="{StaticResource GcMutedText}"
|
||||
VerticalAlignment="Top" Margin="10,8,0,0" />
|
||||
VerticalAlignment="Top" Margin="16,8,0,0" />
|
||||
<StackPanel DockPanel.Dock="Right" Orientation="Horizontal" VerticalAlignment="Top" Margin="16,0,0,0"
|
||||
Height="{Binding ActualHeight, ElementName=SortCombo}">
|
||||
<TextBlock Text="{DynamicResource LOCGameCollections_CardSize}" Style="{StaticResource GcText}"
|
||||
VerticalAlignment="Center" Margin="0,0,8,0" />
|
||||
<Slider Width="110" VerticalAlignment="Center"
|
||||
Minimum="{x:Static vm:CollectionDetailsViewModel.MinCardWidth}"
|
||||
Maximum="{x:Static vm:CollectionDetailsViewModel.MaxCardWidth}"
|
||||
SmallChange="10" LargeChange="30"
|
||||
Value="{Binding CardWidth}"
|
||||
ToolTip="{DynamicResource LOCGameCollections_CardSize}"
|
||||
AutomationProperties.Name="{DynamicResource LOCGameCollections_CardSize}" />
|
||||
</StackPanel>
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
<local:SearchBox Width="240" Height="32" Margin="0,0,0,4"
|
||||
<local:SearchBox Width="240" Margin="0,0,0,4" VerticalAlignment="Center"
|
||||
Height="{Binding ActualHeight, ElementName=SortCombo}"
|
||||
Text="{Binding SearchText}"
|
||||
Placeholder="{DynamicResource LOCGameCollections_SearchGames}" />
|
||||
<TextBlock Text="{DynamicResource LOCGameCollections_SortBy}" Style="{StaticResource GcText}"
|
||||
VerticalAlignment="Center" Margin="16,0,8,0" />
|
||||
<ComboBox MinWidth="150" VerticalAlignment="Center"
|
||||
<ComboBox x:Name="SortCombo" MinWidth="150" VerticalAlignment="Center"
|
||||
ItemsSource="{Binding SortOptions}"
|
||||
DisplayMemberPath="Label"
|
||||
SelectedValuePath="Field"
|
||||
SelectedValue="{Binding SortField}"
|
||||
AutomationProperties.Name="{DynamicResource LOCGameCollections_SortBy}" />
|
||||
<Button Style="{StaticResource GcIconButton}" Height="32" Margin="5,0,0,0"
|
||||
<Button Style="{StaticResource GcIconButton}" Margin="5,0,0,0"
|
||||
Height="{Binding ActualHeight, ElementName=SortCombo}"
|
||||
Content="{Binding SortDirectionGlyph}"
|
||||
Command="{Binding ToggleSortDirectionCommand}"
|
||||
ToolTip="{Binding SortDirectionTooltip}"
|
||||
@@ -157,6 +187,11 @@
|
||||
SelectedValuePath="Field"
|
||||
SelectedValue="{Binding GroupBy}"
|
||||
AutomationProperties.Name="{DynamicResource LOCGameCollections_GroupBy}" />
|
||||
<Button Style="{StaticResource GcButton}" Margin="5,0,0,0" Padding="10,0"
|
||||
Height="{Binding ActualHeight, ElementName=SortCombo}"
|
||||
Content="{Binding ToggleAllGroupsText}"
|
||||
Command="{Binding ToggleAllGroupsCommand}"
|
||||
Visibility="{Binding IsGrouped, Converter={StaticResource BoolToVisibility}}" />
|
||||
<CheckBox VerticalAlignment="Center" Margin="16,0,0,0"
|
||||
IsChecked="{Binding InstalledOnly}"
|
||||
Content="{DynamicResource LOCGameCollections_InstalledOnly}" />
|
||||
@@ -183,17 +218,33 @@
|
||||
SizeChanged="GamesList_SizeChanged"
|
||||
AutomationProperties.Name="{Binding Header.Title}">
|
||||
<ListBox.GroupStyle>
|
||||
<!-- Each group is an expander so it can be collapsed. Its state is kept by the
|
||||
view model and applied in GroupExpander_Loaded. -->
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,8,0,8">
|
||||
<TextBlock Text="{Binding Name}" Style="{StaticResource GcItemTitleText}"
|
||||
FontSize="{DynamicResource FontSizeLarge}" />
|
||||
<TextBlock Text="{Binding ItemCount}" Style="{StaticResource GcMutedText}"
|
||||
VerticalAlignment="Center" Margin="8,0,0,0" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
<GroupStyle.ContainerStyle>
|
||||
<Style TargetType="GroupItem">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="GroupItem">
|
||||
<Expander IsExpanded="True" Margin="0,0,0,8"
|
||||
Loaded="GroupExpander_Loaded"
|
||||
Expanded="GroupExpander_Toggled"
|
||||
Collapsed="GroupExpander_Toggled">
|
||||
<Expander.Header>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,4,0,4">
|
||||
<TextBlock Text="{Binding Name}" Style="{StaticResource GcItemTitleText}"
|
||||
FontSize="{DynamicResource FontSizeLarge}" />
|
||||
<TextBlock Text="{Binding ItemCount}" Style="{StaticResource GcMutedText}"
|
||||
VerticalAlignment="Center" Margin="8,0,0,0" />
|
||||
</StackPanel>
|
||||
</Expander.Header>
|
||||
<ItemsPresenter Margin="0,8,0,0" />
|
||||
</Expander>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</GroupStyle.ContainerStyle>
|
||||
</GroupStyle>
|
||||
</ListBox.GroupStyle>
|
||||
<ListBox.ItemsPanel>
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
@@ -35,7 +36,7 @@ namespace GameCollections.Views
|
||||
};
|
||||
|
||||
GamesList.SelectionChanged += (s, e) => SyncSelection();
|
||||
DataContextChanged += (s, e) => SyncSelection();
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
Loaded += OnLoaded;
|
||||
Unloaded += (s, e) => coverTimer.Stop();
|
||||
}
|
||||
@@ -56,6 +57,78 @@ namespace GameCollections.Views
|
||||
ScheduleCoverRequest();
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.OldValue is CollectionDetailsViewModel oldViewModel)
|
||||
{
|
||||
oldViewModel.GroupExpansionChanged -= OnGroupExpansionChanged;
|
||||
}
|
||||
|
||||
if (e.NewValue is CollectionDetailsViewModel newViewModel)
|
||||
{
|
||||
newViewModel.GroupExpansionChanged += OnGroupExpansionChanged;
|
||||
}
|
||||
|
||||
SyncSelection();
|
||||
}
|
||||
|
||||
private void GroupExpander_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Groups are rebuilt whenever the search or filters change, so each one takes its state from the view model.
|
||||
var expander = (Expander)sender;
|
||||
if (ViewModel != null)
|
||||
{
|
||||
expander.IsExpanded = !ViewModel.IsGroupCollapsed((expander.DataContext as CollectionViewGroup)?.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void GroupExpander_Toggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var expander = (Expander)sender;
|
||||
if (e.OriginalSource != expander || ViewModel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ViewModel.SetGroupCollapsed((expander.DataContext as CollectionViewGroup)?.Name, !expander.IsExpanded);
|
||||
if (expander.IsExpanded)
|
||||
{
|
||||
ScheduleCoverRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
Dispatcher.BeginInvoke(new Action(DeselectHiddenGames), DispatcherPriority.Loaded);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGroupExpansionChanged(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var expander in FindDescendants<Expander>(GamesList))
|
||||
{
|
||||
GroupExpander_Loaded(expander, null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops games that are only in collapsed groups from the selection, so Delete or Enter
|
||||
/// never acts on a game the user can't see.
|
||||
/// </summary>
|
||||
private void DeselectHiddenGames()
|
||||
{
|
||||
if (GamesList.SelectedItems.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var items = new List<ListBoxItem>();
|
||||
CollectItems(GamesList, items);
|
||||
var shown = new HashSet<object>(items.Where(i => i.IsVisible).Select(i => i.DataContext));
|
||||
foreach (var game in GamesList.SelectedItems.Cast<object>().Where(g => !shown.Contains(g)).ToList())
|
||||
{
|
||||
GamesList.SelectedItems.Remove(game);
|
||||
}
|
||||
}
|
||||
|
||||
private void SyncSelection()
|
||||
{
|
||||
if (ViewModel != null)
|
||||
@@ -364,6 +437,23 @@ namespace GameCollections.Views
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<T> FindDescendants<T>(DependencyObject parent) where T : DependencyObject
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(parent, i);
|
||||
if (child is T match)
|
||||
{
|
||||
yield return match;
|
||||
}
|
||||
|
||||
foreach (var nested in FindDescendants<T>(child))
|
||||
{
|
||||
yield return nested;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static T FindDescendant<T>(DependencyObject parent) where T : DependencyObject
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Id: GameCollections_3f6b8d2e-5c41-4a7e-9e0b-6d2f1a8c7b54
|
||||
Name: Game Collections
|
||||
Author: X4Lo
|
||||
Version: 1.2.0
|
||||
Version: 1.3.0
|
||||
Module: GameCollections.dll
|
||||
Type: GenericPlugin
|
||||
Icon: icon.png
|
||||
|
||||
Reference in new issue
Block a user