Skip to content

Commit

Permalink
Fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitz committed Oct 31, 2019
1 parent 2cd52f7 commit 30c6cf6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 45 deletions.
10 changes: 5 additions & 5 deletions Shared/Util/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ public class NonEmptyListConverter : ReadOnlyMultiConverterBase {
public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) => values.OfType<IEnumerable<object>>().FirstOrDefault(x => x != null && x.Any());
}

public class HasItemsVisibilityConverter : ReadOnlyConverterBase {
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
(value as IEnumerable).Cast<object>().Any() ? Visibility.Visible : Visibility.Collapsed;
}

public class InvertVisibilityConverter : ReadOnlyConverterBase {
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
((Visibility)value) == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
}

public class HasValuesVisibilityConverter : ReadOnlyMultiConverterBase {
public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) =>
values.All(x => x is string s && !s.IsNullOrWhitespace()) ? Visibility.Visible : Visibility.Hidden;
}
}
89 changes: 52 additions & 37 deletions Shared/VisualizerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<my1:NodeForegroundConverter x:Key="NodeForegroundConverter" />
<my1:NodeFontWeightConverter x:Key="NodeFontWeightConverter" />
<my1:NonEmptyListConverter x:Key="NonEmptyListConverter" />
<my1:HasItemsVisibilityConverter x:Key="HasItemsVisibilityConverter" />
<my1:InvertVisibilityConverter x:Key="InvertVisibilityConverter" />
<my1:HasValuesVisibilityConverter x:Key="HasValuesVisibilityConverter" />

<Style TargetType="DataGrid">
<Setter Property="IsReadOnly" Value="True" />
Expand Down Expand Up @@ -50,7 +50,12 @@
<DockPanel DockPanel.Dock="Left" Height="{Binding ActualHeight,RelativeSource={RelativeSource AncestorType=DockPanel,AncestorLevel=1}}" Margin="0,0,12,0" VirtualizingStackPanel.VirtualizationMode="Standard">
<TextBlock Text="Tokens:" Style="{StaticResource LabelStyle}" />
<Grid>
<DataGrid Name="tokens" ItemsSource="{Binding Tokens}" VirtualizingStackPanel.VirtualizationMode="Standard" Visibility="{Binding Tokens, Converter={StaticResource HasItemsVisibilityConverter}}">
<DataGrid Name="tokens" ItemsSource="{Binding Tokens}" VirtualizingStackPanel.VirtualizationMode="Standard">
<DataGrid.Visibility>
<MultiBinding Converter="{StaticResource HasValuesVisibilityConverter}">
<Binding Path="Model.Config.SelectedLexerName" Mode="OneWay" />
</MultiBinding>
</DataGrid.Visibility>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Foreground" Value="{Binding Model.IsError, Converter={StaticResource ErrorColorConverter},Mode=OneWay}" />
Expand All @@ -63,7 +68,7 @@
</b:EventTrigger>
</b:Interaction.Triggers>
</DataGrid>
<TextBlock Margin="50,0,50,0" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" Text="No tokens. Choose a lexer class from the settings" Foreground="DarkGray" Visibility="{Binding Visibility, ElementName=tokens,Mode=OneWay, Converter={StaticResource InvertVisibilityConverter}}" />
<TextBlock Margin="50,0,50,0" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" Text="No tokens. Choose the lexer class from the settings." Foreground="DarkGray" Visibility="{Binding Visibility, ElementName=tokens,Mode=OneWay, Converter={StaticResource InvertVisibilityConverter}}" />
</Grid>
</DockPanel>

Expand Down Expand Up @@ -218,39 +223,49 @@
</Grid>

<TextBlock Text="Parse tree view:" Style="{StaticResource LabelStyle}" />
<TreeView Name="treeview" ItemsSource="{Binding Root,Converter={StaticResource RootConverter}}" MinHeight="200" MinWidth="200">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children, Mode=OneTime}">
<TextBlock Text="{Binding Model.Caption}" FontWeight="{Binding Model.NodeType, Converter={StaticResource NodeFontWeightConverter}}">
<TextBlock.Foreground>
<MultiBinding Converter="{StaticResource NodeForegroundConverter}">
<Binding Path="Model.NodeType" />
<Binding Path="Model.FilterState" />
</MultiBinding>
</TextBlock.Foreground>
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Scope to this" Click="SetRootNode" />
<MenuItem Header="Scope to this in new window/" Click="OpenRootNewWindow" />
<MenuItem Header="Copy watch expression" Click="CopyWatchExpression" />
<MenuItem Header="Expand recursively" Click="ExpandAll" />
<MenuItem Header="Collapse recursively" Click="CollapseAll" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
<b:Interaction.Triggers>
<b:EventTrigger EventName="SelectedItemChanged">
<b:InvokeCommandAction Command="{Binding ChangeSelection}" CommandParameter="{Binding SelectedItem, ElementName=treeview }" />
</b:EventTrigger>
</b:Interaction.Triggers>
</TreeView>
<Grid>
<TreeView Name="treeview" ItemsSource="{Binding Root,Converter={StaticResource RootConverter}}" MinHeight="200" MinWidth="200">
<TreeView.Visibility>
<MultiBinding Converter="{StaticResource HasValuesVisibilityConverter}">
<Binding Path="Model.Config.SelectedLexerName" />
<Binding Path="Model.Config.SelectedParserName" />
<Binding Path="Model.Config.ParseTokensWithRule" />
</MultiBinding>
</TreeView.Visibility>
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Children, Mode=OneTime}">
<TextBlock Text="{Binding Model.Caption}" FontWeight="{Binding Model.NodeType, Converter={StaticResource NodeFontWeightConverter}}">
<TextBlock.Foreground>
<MultiBinding Converter="{StaticResource NodeForegroundConverter}">
<Binding Path="Model.NodeType" />
<Binding Path="Model.FilterState" />
</MultiBinding>
</TextBlock.Foreground>
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Scope to this" Click="SetRootNode" />
<MenuItem Header="Scope to this in new window/" Click="OpenRootNewWindow" />
<MenuItem Header="Copy watch expression" Click="CopyWatchExpression" />
<MenuItem Header="Expand recursively" Click="ExpandAll" />
<MenuItem Header="Collapse recursively" Click="CollapseAll" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
<b:Interaction.Triggers>
<b:EventTrigger EventName="SelectedItemChanged">
<b:InvokeCommandAction Command="{Binding ChangeSelection}" CommandParameter="{Binding SelectedItem, ElementName=treeview }" />
</b:EventTrigger>
</b:Interaction.Triggers>
</TreeView>
<TextBlock Margin="50,0,50,0" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" Text="No tree nodes. Choose the lexer class, the parser class, and the parse method from the settings." Foreground="DarkGray" Visibility="{Binding Visibility, ElementName=treeview,Mode=OneWay, Converter={StaticResource InvertVisibilityConverter}}" />
</Grid>

</DockPanel>
5 changes: 2 additions & 3 deletions Shared/VisualizerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ public VisualizerControl() {
private VisualizerDataViewModel data => (VisualizerDataViewModel)DataContext;

private void LoadDataContext() {
if (_objectProvider == null || config == null) { return; }
var response = _objectProvider.TransferObject(config) as VisualizerData;
if (response == null) {
if (_objectProvider is null || config is null) { return; }
if (!(_objectProvider.TransferObject(config) is VisualizerData response)) {
throw new InvalidOperationException("Unspecified error while serializing/deserializing");
}
DataContext = new VisualizerDataViewModel(response);
Expand Down

0 comments on commit 30c6cf6

Please sign in to comment.