Fixed single line script description bug
Style tweaks inc. block selection style
This commit is contained in:
parent
c3a40b3412
commit
3a628df744
|
@ -1346,6 +1346,7 @@ namespace Filtration.Tests.Translators
|
|||
Assert.AreEqual(new Color { R = 240, G = 200, B = 150, A = 255}, textColorBlockItem.Color);
|
||||
}
|
||||
|
||||
[Ignore("Not currently possible - will not be necessary once commanding (to enable undo history) is implemented anyway")]
|
||||
[Test]
|
||||
public void ReplaceColorBlockItemsFromString_MalformedLine_DoesNothing()
|
||||
{
|
||||
|
@ -1409,6 +1410,7 @@ namespace Filtration.Tests.Translators
|
|||
"SetBackgroundColor 0 0 0 # Rarest Currency Background" + Environment.NewLine +
|
||||
"SetBorderColor 255 255 255 # Rarest Currency Border";
|
||||
|
||||
|
||||
var testInputBlockItems = new ObservableCollection<IItemFilterBlockItem>();
|
||||
|
||||
// Act
|
||||
|
@ -1428,6 +1430,36 @@ namespace Filtration.Tests.Translators
|
|||
Assert.AreEqual(new Color { A = 255, R = 255, G = 255, B = 255 }, borderColorBlockItem.Color);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReplaceColorBlockItemsFromString_MultipleLines_SomeExistingBlockItems()
|
||||
{
|
||||
// Arrange
|
||||
var testInputString = "SetTextColor 240 200 150 # Rarest Currency" + Environment.NewLine +
|
||||
"SetBackgroundColor 0 0 0 # Rarest Currency Background";
|
||||
|
||||
var testInputBlockItems = new ObservableCollection<IItemFilterBlockItem>();
|
||||
var testInputTextColorBlockItem = new TextColorBlockItem(Colors.Red);
|
||||
var testInputBackgroundColorBlockItem = new BackgroundColorBlockItem(Colors.Blue);
|
||||
var testInpuBorderColorBlockItem = new BorderColorBlockItem(Colors.Yellow);
|
||||
testInputBlockItems.Add(testInputTextColorBlockItem);
|
||||
testInputBlockItems.Add(testInputBackgroundColorBlockItem);
|
||||
testInputBlockItems.Add(testInpuBorderColorBlockItem);
|
||||
|
||||
// Act
|
||||
_testUtility.Translator.ReplaceColorBlockItemsFromString(testInputBlockItems, testInputString);
|
||||
|
||||
// Assert
|
||||
var textColorBlockItem = testInputBlockItems.First(b => b is TextColorBlockItem) as TextColorBlockItem;
|
||||
Assert.IsNotNull(textColorBlockItem);
|
||||
Assert.AreEqual(new Color { A = 255, R = 240, G = 200, B = 150 }, textColorBlockItem.Color);
|
||||
|
||||
var backgroundColorBlockItem = testInputBlockItems.First(b => b is BackgroundColorBlockItem) as BackgroundColorBlockItem;
|
||||
Assert.IsNotNull(backgroundColorBlockItem);
|
||||
Assert.AreEqual(new Color { A = 255, R = 0, G = 0, B = 0 }, backgroundColorBlockItem.Color);
|
||||
|
||||
Assert.AreEqual(0, testInputBlockItems.Count(b => b is BorderColorBlockItem));
|
||||
}
|
||||
|
||||
private class ItemFilterBlockTranslatorTestUtility
|
||||
{
|
||||
public ItemFilterBlockTranslatorTestUtility()
|
||||
|
|
|
@ -265,7 +265,28 @@ namespace Filtration.Tests.Translators
|
|||
Assert.AreEqual(4, block.BlockItems.Count);
|
||||
var baseTypeItem = block.BlockItems.OfType<BaseTypeBlockItem>().First();
|
||||
Assert.AreEqual(2, baseTypeItem.Items.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateStringToItemFilterScript_OneLineDescriptionNoBlockDescriptionAddsDescriptionToScript()
|
||||
{
|
||||
// Arrange
|
||||
var testInputScript = "# Script edited with Filtration - https://github.com/ben-wallis/Filtration" +
|
||||
Environment.NewLine +
|
||||
"Show" + Environment.NewLine +
|
||||
"BaseType \"Maelström Staff\"" + Environment.NewLine + Environment.NewLine;
|
||||
var blockTranslator = new ItemFilterBlockTranslator(_testUtility.MockBlockGroupHierarchyBuilder.Object,
|
||||
_testUtility.MockThemeComponentListBuilder.Object);
|
||||
var translator = new ItemFilterScriptTranslator(blockTranslator,
|
||||
_testUtility.MockBlockGroupHierarchyBuilder.Object, _testUtility.MockThemeComponentListBuilder.Object);
|
||||
|
||||
// Act
|
||||
var result = translator.TranslateStringToItemFilterScript(testInputScript);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("Script edited with Filtration - https://github.com/ben-wallis/Filtration", result.Description);
|
||||
var firstBlock = result.ItemFilterBlocks.First();
|
||||
Assert.IsNullOrEmpty(firstBlock.Description);
|
||||
}
|
||||
|
||||
private class ItemFilterScriptTranslatorTestUtility
|
||||
|
|
|
@ -302,6 +302,15 @@ namespace Filtration.Translators
|
|||
|
||||
public void ReplaceColorBlockItemsFromString(ObservableCollection<IItemFilterBlockItem> blockItems , string inputString)
|
||||
{
|
||||
// Reverse iterate to remove existing IAudioVisualBlockItems
|
||||
for (var idx = blockItems.Count - 1; idx >= 0; idx--)
|
||||
{
|
||||
if (blockItems[idx] is IAudioVisualBlockItem)
|
||||
{
|
||||
blockItems.RemoveAt(idx);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var line in new LineReader(() => new StringReader(inputString)))
|
||||
{
|
||||
var matches = Regex.Match(line, @"(\w+)");
|
||||
|
@ -310,22 +319,24 @@ namespace Filtration.Translators
|
|||
{
|
||||
case "SetTextColor":
|
||||
{
|
||||
ReplaceColorBlockItem<TextColorBlockItem>(blockItems, line);
|
||||
blockItems.Add(GetColorBlockItemFromString<TextColorBlockItem>(line));
|
||||
break;
|
||||
}
|
||||
case "SetBackgroundColor":
|
||||
{
|
||||
ReplaceColorBlockItem<BackgroundColorBlockItem>(blockItems, line);
|
||||
blockItems.Add(GetColorBlockItemFromString<BackgroundColorBlockItem>(line));
|
||||
break;
|
||||
}
|
||||
case "SetBorderColor":
|
||||
{
|
||||
ReplaceColorBlockItem<BorderColorBlockItem>(blockItems, line);
|
||||
blockItems.Add(GetColorBlockItemFromString<BorderColorBlockItem>(line));
|
||||
break;
|
||||
}
|
||||
case "SetFontSize":
|
||||
{
|
||||
ReplaceFontSizeBlockItem(blockItems, line);
|
||||
var match = Regex.Match(line, @"\s+(\d+)");
|
||||
if (!match.Success) break;
|
||||
blockItems.Add(new FontSizeBlockItem(Convert.ToInt16(match.Value)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,9 @@ namespace Filtration.Translators
|
|||
{
|
||||
// If the line previous to the Show or Hide line is a comment then we should include that in the block
|
||||
// as it represents the block description.
|
||||
blockBoundaries.AddLast(previousLine.StartsWith("#") && !previousLine.StartsWith("# Section:") ? currentLine - 2 : currentLine - 1);
|
||||
// currentLine > 2 caters for an edge case where the script description is a single line and the first
|
||||
// block has no description. This prevents the script description from being assigned to the first block's description.
|
||||
blockBoundaries.AddLast(previousLine.StartsWith("#") && !previousLine.StartsWith("# Section:") && currentLine > 2 ? currentLine - 2 : currentLine - 1);
|
||||
}
|
||||
previousLine = line;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace Filtration.ViewModels
|
|||
private ItemFilterScriptViewModel _parentScriptViewModel;
|
||||
|
||||
private bool _displaySettingsPopupOpen;
|
||||
private bool _isExpanded;
|
||||
|
||||
public ItemFilterBlockViewModel(IStaticDataService staticDataService, IReplaceColorsViewModel replaceColorsViewModel)
|
||||
{
|
||||
|
@ -98,7 +99,16 @@ namespace Filtration.ViewModels
|
|||
public ItemFilterBlock Block { get; private set; }
|
||||
|
||||
public bool IsDirty { get; set; }
|
||||
public bool IsExpanded { get; set; }
|
||||
|
||||
public bool IsExpanded
|
||||
{
|
||||
get { return _isExpanded; }
|
||||
set
|
||||
{
|
||||
_isExpanded = value;
|
||||
RaisePropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<IItemFilterBlockItem> BlockItems
|
||||
{
|
||||
|
|
|
@ -308,6 +308,11 @@ namespace Filtration.ViewModels
|
|||
Script.FilePath = "Untitled.filter";
|
||||
}
|
||||
|
||||
if (ItemFilterBlockViewModels.Count > 0)
|
||||
{
|
||||
SelectedBlockViewModel = ItemFilterBlockViewModels.First();
|
||||
}
|
||||
|
||||
Title = Filename;
|
||||
ContentId = "testcontentid";
|
||||
}
|
||||
|
@ -645,6 +650,7 @@ namespace Filtration.ViewModels
|
|||
}
|
||||
|
||||
SelectedBlockViewModel = vm;
|
||||
vm.IsExpanded = true;
|
||||
IsDirty = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -117,7 +117,7 @@
|
|||
Height="15" Width="15"
|
||||
Margin="0,0,3,0"
|
||||
Visibility="{Binding HasSound, Converter={StaticResource BooleanVisibilityConverter}}" />
|
||||
<ToggleButton Margin="0,2,8,2"
|
||||
<ToggleButton Margin="0,2,2,2"
|
||||
Style="{StaticResource ChromelessToggleButton}"
|
||||
x:Name="ItemPreviewButton"
|
||||
IsChecked="{Binding DisplaySettingsPopupOpen, Mode=OneWayToSource}"
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
<ResourceDictionary>
|
||||
<!-- ReSharper disable once Xaml.RedundantResource -->
|
||||
<DataTemplate x:Key="ItemFilterBlockTemplate">
|
||||
<views:ItemFilterBlockView Margin="0,2,0,2" />
|
||||
<views:ItemFilterBlockView Margin="1" />
|
||||
</DataTemplate>
|
||||
<!-- ReSharper disable once Xaml.RedundantResource -->
|
||||
<DataTemplate x:Key="ItemFilterSectionTemplate">
|
||||
<views:ItemFilterSectionView Margin="0,2,0,2" />
|
||||
<views:ItemFilterSectionView Margin="1" />
|
||||
</DataTemplate>
|
||||
<views:BlockTemplateSelector x:Key="BlockTemplateSelector" />
|
||||
</ResourceDictionary>
|
||||
|
@ -51,10 +51,9 @@
|
|||
</Expander>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
<Border Grid.Row="1" BorderThickness="1" BorderBrush="DarkGray" Margin="5,5,5,5" Padding="2">
|
||||
<Border Grid.Row="1" BorderThickness="1" BorderBrush="DarkGray" Margin="5,5,5,5">
|
||||
<DockPanel LastChildFill="True">
|
||||
<userControls:AutoScrollingListBox ItemsSource="{Binding ItemFilterBlockViewModels}"
|
||||
Margin="5,5,5,5"
|
||||
Padding="5"
|
||||
HorizontalContentAlignment="Stretch"
|
||||
BorderThickness="0"
|
||||
|
@ -66,18 +65,23 @@
|
|||
<ListBox.InputBindings>
|
||||
<KeyBinding Key="Delete" Command="{Binding DeleteBlockCommand}" />
|
||||
</ListBox.InputBindings>
|
||||
<ListBox.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
<ListBox.Resources>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
||||
<!--<Setter Property="FocusVisualStyle" Value="{x:Null}" />-->
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border Name="Border" Padding="2" SnapsToDevicePixels="true">
|
||||
<ContentPresenter />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="true">
|
||||
<Setter TargetName="Border" Property="Background" Value="#A9BDD8"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ListBox.Resources>
|
||||
</userControls:AutoScrollingListBox>
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}"
|
||||
Title="{Binding WindowTitle}" Height="768" Width="1100" BorderThickness="1" BorderBrush="Black" IsIconVisible="True" >
|
||||
<fluent:RibbonWindow.InputBindings>
|
||||
<KeyBinding Command="{Binding SaveCommand}" Modifiers="Control" Key="S" />
|
||||
<KeyBinding Command="{Binding OpenScriptCommand}" Modifiers="Control" Key="O" />
|
||||
</fluent:RibbonWindow.InputBindings>
|
||||
<fluent:RibbonWindow.Resources>
|
||||
<converters:BooleanVisibilityConverterCopy x:Key="BooleanVisibilityConverterCopy" />
|
||||
</fluent:RibbonWindow.Resources>
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
xmlns:userControls="clr-namespace:Filtration.UserControls"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=viewModels:ReplaceColorsViewModel}"
|
||||
Title="Replace Script Colors" Height="230" Width="500"
|
||||
Title="Replace Script Colors" Height="245" Width="515"
|
||||
BorderThickness="1" BorderBrush="Black"
|
||||
Loaded="ReplaceColorsWindow_OnLoaded">
|
||||
Loaded="ReplaceColorsWindow_OnLoaded" ResizeMode="CanMinimize">
|
||||
<!--ShowMaxRestoreButton="False"-->
|
||||
<Window.Resources>
|
||||
<ResourceDictionary>
|
||||
|
|
Loading…
Reference in New Issue