Make comment blocks expandable & improve parsing
This commit is contained in:
parent
281c7d85e1
commit
961805272d
|
@ -75,6 +75,7 @@ namespace Filtration.Parser.Services
|
|||
}
|
||||
|
||||
lines[i] = lines[i].TrimStart('#');
|
||||
lines[i] = lines[i].TrimStart(' ');
|
||||
lines[i] = lines[i].Replace("#", " # ");
|
||||
var spaceOrEndOfLinePos = lines[i].IndexOf(" ", StringComparison.Ordinal) > 0 ? lines[i].IndexOf(" ", StringComparison.Ordinal) : lines[i].Length;
|
||||
var lineOption = lines[i].Substring(0, spaceOrEndOfLinePos);
|
||||
|
@ -108,11 +109,49 @@ namespace Filtration.Parser.Services
|
|||
return lines.Aggregate((c, n) => c + Environment.NewLine + n);
|
||||
}
|
||||
|
||||
public static string ConvertCommentedToDisabled(string inputString)
|
||||
{
|
||||
var lines = Regex.Split(inputString, "\r\n|\r|\n");
|
||||
var parsingCommented = false;
|
||||
for (var i = 0; i < lines.Length; i++)
|
||||
{
|
||||
if (!parsingCommented)
|
||||
{
|
||||
if (lines[i].StartsWith("# Show") || lines[i].StartsWith("#Show"))
|
||||
{
|
||||
parsingCommented = true;
|
||||
lines[i] = "#Disabled Block Start" + Environment.NewLine + lines[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!lines[i].StartsWith("#"))
|
||||
{
|
||||
parsingCommented = false;
|
||||
lines[i - 1] += Environment.NewLine + "#Disabled Block End";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(parsingCommented)
|
||||
{
|
||||
lines[lines.Length - 1] += Environment.NewLine + "#Disabled Block End";
|
||||
}
|
||||
|
||||
return string.Join(Environment.NewLine, lines);
|
||||
}
|
||||
|
||||
public IItemFilterScript TranslateStringToItemFilterScript(string inputString)
|
||||
{
|
||||
var script = _itemFilterScriptFactory.Create();
|
||||
_blockGroupHierarchyBuilder.Initialise(script.ItemFilterBlockGroups.First());
|
||||
|
||||
//NeverSink's Indepth Loot Filter parsing
|
||||
if (inputString.Contains("NeverSink's Indepth Loot Filter"))
|
||||
{
|
||||
inputString = ConvertCommentedToDisabled(inputString);
|
||||
}
|
||||
|
||||
|
||||
inputString = inputString.Replace("\t", "");
|
||||
if (inputString.Contains("#Disabled Block Start"))
|
||||
{
|
||||
|
@ -265,6 +304,13 @@ namespace Filtration.Parser.Services
|
|||
}
|
||||
}
|
||||
|
||||
//NeverSink's Indepth Loot Filter parsing
|
||||
if (outputString.Contains("NeverSink's Indepth Loot Filter"))
|
||||
{
|
||||
outputString = Regex.Replace(outputString, "(\r)?\n#Disabled Block Start*(\r)?\n", Environment.NewLine);
|
||||
outputString = Regex.Replace(outputString, "(\r)?\n#Disabled Block End*(\r)?\n", Environment.NewLine);
|
||||
}
|
||||
|
||||
return outputString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Filtration.ObjectModel;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
using System;
|
||||
|
||||
namespace Filtration.ViewModels
|
||||
{
|
||||
|
@ -47,10 +48,24 @@ namespace Filtration.ViewModels
|
|||
ItemFilterCommentBlock.Comment = value;
|
||||
IsDirty = true;
|
||||
RaisePropertyChanged();
|
||||
RaisePropertyChanged("Header");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Header
|
||||
{
|
||||
get
|
||||
{
|
||||
string[] commentLines = ItemFilterCommentBlock.Comment.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
if (commentLines[0].StartsWith(@"============") || commentLines[0].StartsWith(@"------------"))
|
||||
{
|
||||
commentLines[0] = commentLines[1];
|
||||
}
|
||||
return commentLines[0].TrimStart(' ');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsExpanded
|
||||
{
|
||||
|
|
|
@ -76,7 +76,18 @@
|
|||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column ="0" Text="{Binding Comment, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Center" TextWrapping="Wrap" MinWidth="150"/>
|
||||
|
||||
<Expander Grid.Column="1"
|
||||
Style="{StaticResource ExpanderRightAlignStyle}"
|
||||
x:Name="BlockExpander">
|
||||
|
||||
<Expander.Header>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0" VerticalAlignment="Center" MinWidth="150" Content="{Binding Header, Mode=OneWay}"></Label>
|
||||
<Button Grid.Column="1" Command="{Binding ToggleSectionCommand}"
|
||||
Width="25"
|
||||
Height="25"
|
||||
|
@ -100,6 +111,16 @@
|
|||
<Image Source="/Filtration;component/Resources/Icons/collapse_icon.png" VerticalAlignment="Center" HorizontalAlignment="Center" />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Expander.Header>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBox Grid.Column ="0" Text="{Binding Comment, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" VerticalAlignment="Center" TextWrapping="Wrap" MinWidth="150"/>
|
||||
</Grid>
|
||||
</Expander>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
Loading…
Reference in New Issue