Skip to content

Commit

Permalink
Improve project selection while searching filters items.
Browse files Browse the repository at this point in the history
The gropus checked state is now relate to search results and updated also based on search results.
#14
  • Loading branch information
krzysztof-lorenc committed Feb 7, 2020
1 parent 8260a4f commit e564d2f
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions src/Soloplan.WhatsON.GUI/Configuration/Wizard/ProjectViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Soloplan.WhatsON.GUI.Configuration.Wizard
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using Soloplan.WhatsON.Model;

Expand Down Expand Up @@ -77,49 +78,59 @@ public ProjectViewModel(string name, ProjectViewModelList rootList)

public string Description { get; set; }

/// <summary>
/// Gets or sets a value indicating whether this project is visible.
/// </summary>
public bool IsVisible
{
get => this.isVisible;
set
{
this.isVisible = value;
this.OnPropertyChanged();
this.UpdateParentGroupsCheckedState();
}
}

/// <summary>
/// Gets or sets a value indicating whether this project is checked.
/// </summary>
/// <value>
/// <c>true</c> if this project is checked; otherwise, <c>false</c>.
/// </value>
public bool IsChecked
{
get => this.isChecked;
get
{
if (this.rootList.MultiSelectionMode && this.Projects.Count > 0)
{
return this.Projects.Where(p => p.IsVisible).All(p => p.IsChecked);
}

return this.isChecked;
}

set
{
this.isChecked = value;
this.OnPropertyChanged();
if (this.rootList.MultiSelectionMode)
{
foreach (var project in this.Projects)
foreach (var project in this.Projects.Where(p => p.IsVisible))
{
project.IsChecked = value;
}

this.UpdateParentGroupsCheckedState();
}
else
{
this.rootList.UncheckAll(this);
}

this.OnPropertyChanged();
}
}

/// <summary>
/// Gets a value indicating whether this project is checkable - supports checking (some items might be only some grouping items).
/// </summary>
/// <value>
/// <c>true</c> if this project is checkable; otherwise, <c>false</c>.
/// </value>
public bool IsCheckable
{
get
Expand Down Expand Up @@ -187,5 +198,18 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

/// <summary>
/// Updates the checked state of the groups(including parent groups).
/// </summary>
private void UpdateParentGroupsCheckedState()
{
var currentParent = this.Parent;
while (currentParent != null)
{
currentParent.OnPropertyChanged(nameof(this.IsChecked));
currentParent = currentParent.Parent;
}
}
}
}

0 comments on commit e564d2f

Please sign in to comment.