Added partial support for Advanced BlockGroups
This commit is contained in:
parent
08a193dc6b
commit
08d9cf277b
|
@ -51,5 +51,22 @@ namespace Filtration.Tests.Models
|
|||
// Assert
|
||||
Assert.IsFalse(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HasParentInBlockGroupHierarchy_ReturnsCorrectResult()
|
||||
{
|
||||
// Arrange
|
||||
var testInputRootBlockGroup = new ItemFilterBlockGroup("Root Block Group", null);
|
||||
var testInputSubBlockGroup = new ItemFilterBlockGroup("Sub Block Group", testInputRootBlockGroup);
|
||||
var testInputSubSubBlockGroup = new ItemFilterBlockGroup("Sub Sub Block Group", testInputSubBlockGroup);
|
||||
|
||||
var block = new ItemFilterBlock {BlockGroup = testInputSubSubBlockGroup};
|
||||
|
||||
// Act
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(true, block.HasBlockGroupInParentHierarchy(testInputRootBlockGroup, block.BlockGroup));
|
||||
Assert.AreEqual(true, block.HasBlockGroupInParentHierarchy(testInputSubBlockGroup, block.BlockGroup));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,10 @@ namespace Filtration.Tests.Translators
|
|||
{
|
||||
// Arrange
|
||||
var inputString = "Show # TestBlockGroup" + Environment.NewLine;
|
||||
var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null);
|
||||
|
||||
// Act
|
||||
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Verifiable();
|
||||
_testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny<IEnumerable<string>>())).Returns(inputBlockGroup).Verifiable();
|
||||
var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString);
|
||||
|
||||
// Assert
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Filtration.Converters
|
||||
{
|
||||
internal class BlockGroupAdvancedColorConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var advanced = (bool) value;
|
||||
|
||||
return advanced ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Black);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -107,6 +107,8 @@
|
|||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Converters\ActiveDocumentConverter.cs" />
|
||||
<Compile Include="Converters\BlockGroupAdvancedColorConverter.cs" />
|
||||
<Compile Include="Converters\BlockGroupVisibilityConverter.cs" />
|
||||
<Compile Include="Converters\BlockItemTypeToStringConverter.cs" />
|
||||
<Compile Include="Converters\BooleanInverterConverter.cs" />
|
||||
<Compile Include="Converters\BooleanToBlockActionInverseConverter.cs" />
|
||||
|
@ -372,6 +374,7 @@
|
|||
<Resource Include="Resources\Icons\block_group_browser_icon.png" />
|
||||
<Resource Include="Resources\Icons\clear_filter_icon.png" />
|
||||
<Resource Include="Resources\Icons\filter_icon.png" />
|
||||
<Resource Include="Resources\Icons\show_advanced_icon.png" />
|
||||
<Content Include="Resources\ItemBaseTypes.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
@ -12,10 +12,11 @@ namespace Filtration.Models
|
|||
private bool? _isChecked;
|
||||
private bool _reentrancyCheck;
|
||||
|
||||
public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent)
|
||||
public ItemFilterBlockGroup(string groupName, ItemFilterBlockGroup parent, bool advanced = false)
|
||||
{
|
||||
GroupName = groupName;
|
||||
ParentGroup = parent;
|
||||
Advanced = advanced;
|
||||
ChildGroups = new ObservableCollection<ItemFilterBlockGroup>();
|
||||
}
|
||||
|
||||
|
@ -43,6 +44,8 @@ namespace Filtration.Models
|
|||
return outputString;
|
||||
}
|
||||
|
||||
public bool Advanced { get; private set; }
|
||||
|
||||
public bool? IsChecked
|
||||
{
|
||||
get
|
||||
|
@ -91,7 +94,7 @@ namespace Filtration.Models
|
|||
|
||||
private void UpdateChildrenCheckState()
|
||||
{
|
||||
foreach (var childGroup in ChildGroups.Where(c => IsChecked != null))
|
||||
foreach (var childGroup in ChildGroups.Where(c => IsChecked != null && !c.Advanced))
|
||||
{
|
||||
childGroup.IsChecked = IsChecked;
|
||||
}
|
||||
|
@ -114,6 +117,28 @@ namespace Filtration.Models
|
|||
return null;
|
||||
}
|
||||
|
||||
public ItemFilterBlockGroup Search(Func<ItemFilterBlockGroup, bool> predicate)
|
||||
{
|
||||
// if node is a leaf
|
||||
if (ChildGroups == null || ChildGroups.Count == 0)
|
||||
{
|
||||
return predicate(this) ? this : null;
|
||||
}
|
||||
|
||||
var results = ChildGroups
|
||||
.Select(i => i.Search(predicate))
|
||||
.Where(i => i != null).ToList();
|
||||
|
||||
if (results.Any())
|
||||
{
|
||||
var result = (ItemFilterBlockGroup)MemberwiseClone();
|
||||
result.ChildGroups = new ObservableCollection<ItemFilterBlockGroup>(results);
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 305 B |
|
@ -33,6 +33,10 @@ namespace Filtration.Translators
|
|||
{
|
||||
var inputGroups = groupStrings.ToList();
|
||||
var firstGroup = inputGroups.First().Trim();
|
||||
if (firstGroup.StartsWith("~"))
|
||||
{
|
||||
firstGroup = firstGroup.Substring(1);
|
||||
}
|
||||
|
||||
ItemFilterBlockGroup matchingChildItemGroup = null;
|
||||
if (startItemGroup.ChildGroups.Count(g => g.GroupName == firstGroup) > 0)
|
||||
|
@ -42,7 +46,7 @@ namespace Filtration.Translators
|
|||
|
||||
if (matchingChildItemGroup == null)
|
||||
{
|
||||
var newItemGroup = new ItemFilterBlockGroup(inputGroups.First().Trim(), startItemGroup);
|
||||
var newItemGroup = CreateBlockGroup(inputGroups.First().Trim(), startItemGroup);
|
||||
startItemGroup.ChildGroups.Add(newItemGroup);
|
||||
inputGroups = inputGroups.Skip(1).ToList();
|
||||
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, newItemGroup) : newItemGroup;
|
||||
|
@ -50,5 +54,23 @@ namespace Filtration.Translators
|
|||
inputGroups = inputGroups.Skip(1).ToList();
|
||||
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, matchingChildItemGroup) : matchingChildItemGroup;
|
||||
}
|
||||
|
||||
private ItemFilterBlockGroup CreateBlockGroup(string groupNameString, ItemFilterBlockGroup parentGroup)
|
||||
{
|
||||
var advanced = false;
|
||||
|
||||
if (groupNameString.StartsWith("~"))
|
||||
{
|
||||
groupNameString = groupNameString.Substring(1);
|
||||
advanced = true;
|
||||
}
|
||||
|
||||
if (parentGroup.Advanced)
|
||||
{
|
||||
advanced = true;
|
||||
}
|
||||
|
||||
return new ItemFilterBlockGroup(groupNameString, parentGroup, advanced);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ using Filtration.Models;
|
|||
using Filtration.Services;
|
||||
using Filtration.Translators;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
using GalaSoft.MvvmLight.Messaging;
|
||||
using Clipboard = System.Windows.Clipboard;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
|
@ -27,6 +28,7 @@ namespace Filtration.ViewModels
|
|||
IEnumerable<IItemFilterBlockViewModel> ItemFilterSectionViewModels { get; }
|
||||
Predicate<IItemFilterBlockViewModel> BlockFilterPredicate { get; set; }
|
||||
bool IsDirty { get; }
|
||||
bool ShowAdvanced { get; }
|
||||
string Description { get; set; }
|
||||
string DisplayName { get; }
|
||||
|
||||
|
@ -67,6 +69,7 @@ namespace Filtration.ViewModels
|
|||
_persistenceService = persistenceService;
|
||||
_itemFilterBlockViewModels = new ObservableCollection<IItemFilterBlockViewModel>();
|
||||
|
||||
ToggleShowAdvancedCommand = new RelayCommand<bool>(OnToggleShowAdvancedCommand);
|
||||
ClearFilterCommand = new RelayCommand(OnClearFilterCommand, () => BlockFilterPredicate != null);
|
||||
CloseCommand = new RelayCommand(OnCloseCommand);
|
||||
DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => SelectedBlockViewModel != null);
|
||||
|
@ -80,6 +83,7 @@ namespace Filtration.ViewModels
|
|||
PasteBlockCommand = new RelayCommand(OnPasteBlockCommand, () => SelectedBlockViewModel != null);
|
||||
}
|
||||
|
||||
public RelayCommand<bool> ToggleShowAdvancedCommand { get; private set; }
|
||||
public RelayCommand ClearFilterCommand { get; private set; }
|
||||
public RelayCommand CloseCommand { get; private set; }
|
||||
public RelayCommand DeleteBlockCommand { get; private set; }
|
||||
|
@ -150,6 +154,16 @@ namespace Filtration.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public bool ShowAdvanced
|
||||
{
|
||||
get { return _showAdvanced; }
|
||||
private set
|
||||
{
|
||||
_showAdvanced = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public IItemFilterBlockViewModel SelectedBlockViewModel
|
||||
{
|
||||
get { return _selectedBlockViewModel; }
|
||||
|
@ -223,6 +237,7 @@ namespace Filtration.ViewModels
|
|||
}
|
||||
|
||||
private bool _filenameIsFake;
|
||||
private bool _showAdvanced;
|
||||
|
||||
public void Initialise(ItemFilterScript itemFilterScript, bool newScript)
|
||||
{
|
||||
|
@ -384,6 +399,12 @@ namespace Filtration.ViewModels
|
|||
_avalonDockWorkspaceViewModel.CloseDocument(this);
|
||||
}
|
||||
|
||||
private void OnToggleShowAdvancedCommand(bool showAdvanced)
|
||||
{
|
||||
ShowAdvanced = !ShowAdvanced;
|
||||
Messenger.Default.Send(new NotificationMessage<bool>(ShowAdvanced, "ShowAdvancedToggled"));
|
||||
}
|
||||
|
||||
private void OnClearFilterCommand()
|
||||
{
|
||||
BlockFilterPredicate = null;
|
||||
|
|
|
@ -19,4 +19,5 @@
|
|||
<Image Source="/Filtration;component/Resources/Icons/replace_colors_icon.png" x:Key="ReplaceColorsIcon" x:Shared="false" />
|
||||
<Image Source="/Filtration;component/Resources/Icons/clear_filter_icon.png" x:Key="ClearFilterIcon" x:Shared="False" />
|
||||
<Image Source="/Filtration;component/Resources/Icons/filter_icon.png" x:Key="FilterIcon" x:Shared="False" />
|
||||
<Image Source="/Filtration;component/Resources/Icons/show_advanced_icon.png" x:Key="ShowAdvancedIcon" x:Shared="False" />
|
||||
</ResourceDictionary>
|
|
@ -61,6 +61,7 @@
|
|||
</ToolBar>
|
||||
<ToolBar>
|
||||
<Button ToolTip="Clear Filter" Command="{Binding ClearFilterCommand}" Content="{StaticResource ClearFilterIcon}" />
|
||||
<!--<ToggleButton ToolTip="Show Advanced Block Groups" Command="{Binding ToggleShowAdvancedCommand}" CommandParameter="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}" Content="{StaticResource ShowAdvancedIcon}" />-->
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
<userControls:AutoScrollingListBox ItemsSource="{Binding ItemFilterBlockViewModels}"
|
||||
|
|
|
@ -5,13 +5,15 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:models="clr-namespace:Filtration.Models"
|
||||
xmlns:viewModels="clr-namespace:Filtration.ViewModels"
|
||||
xmlns:converters="clr-namespace:Filtration.Converters"
|
||||
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
|
||||
xmlns:behaviors="clr-namespace:Filtration.Views.Behaviors"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=viewModels:BlockGroupBrowserViewModel}"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<UserControl.Resources>
|
||||
|
||||
<converters:BlockGroupAdvancedColorConverter x:Key="BlockGroupAdvancedColorConverter" />
|
||||
<converters:BlockGroupVisibilityConverter x:Key="BlockGroupVisibilityConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
@ -22,7 +24,7 @@
|
|||
<Button Height="20" Command="{Binding FilterToSelectedBlockGroupCommand}" Content="{StaticResource FilterIcon}" ToolTip="Filter to Selected Block Group" />
|
||||
</ToolBar>
|
||||
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding BlockGroups}">
|
||||
<TreeView Grid.Row="1" ItemsSource="{Binding BlockGroups}" Name="TreeView">
|
||||
<i:Interaction.Behaviors>
|
||||
<behaviors:BindableSelectedItemBehavior SelectedItem="{Binding SelectedBlockGroup, Mode=OneWayToSource}" />
|
||||
</i:Interaction.Behaviors>
|
||||
|
@ -30,7 +32,7 @@
|
|||
<HierarchicalDataTemplate DataType="{x:Type models:ItemFilterBlockGroup}" ItemsSource="{Binding ChildGroups}">
|
||||
<WrapPanel>
|
||||
<CheckBox IsThreeState="True" IsChecked="{Binding IsChecked}" Click="BlockGroupCheckBox_Clicked" />
|
||||
<TextBlock Text="{Binding GroupName}" />
|
||||
<TextBlock Text="{Binding GroupName}" Foreground="{Binding Advanced, Converter={StaticResource BlockGroupAdvancedColorConverter}}" />
|
||||
</WrapPanel>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
|
|
Loading…
Reference in New Issue