Skip to content

Commit

Permalink
Fixes #23; fixes #37; window size/position is now fixed;
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitz committed Nov 4, 2019
1 parent d0b6179 commit e8bc561
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Shared/Models/VisualizerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ T createInstance<T>(string typename, object[] args = null) =>
break;
case IParseTree tree1:
tree = tree1;
Source = tree.GetText();
Source = tree.GetPositionedText();
break;
default:
throw new ArgumentException("Unhandled type");
Expand Down
14 changes: 7 additions & 7 deletions Shared/Util/Extensions/IParseTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public static IEnumerable<IParseTree> Descendants(this IParseTree tree) {

public static string GetPositionedText(this IParseTree tree, char filler = ' ') {
var sb = new StringBuilder();
foreach (var descendant in tree.Descendants()) {

foreach (var descendant in tree.Descendants().OfType<TerminalNodeImpl>()) {
var fillerCharCount = descendant.Payload.StartIndex - sb.Length;
if (fillerCharCount > 0) {
sb.Append(filler, fillerCharCount);
}
sb.Append(descendant.Payload.Text);
}
// get string length of tree, from last node
// create string with length of string length
// create string builder from string
// walk tree, filling in each node
throw new NotImplementedException();
return sb.ToString();
}
}
}
5 changes: 5 additions & 0 deletions Shared/ViewModels/ParseTreeNodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

namespace ParseTreeVisualizer {
public class ParseTreeNodeViewModel : Selectable<ParseTreeNode> {
public static ParseTreeNodeViewModel Create(ParseTreeNode model) =>
model is null ?
null :
new ParseTreeNodeViewModel(model);

public ParseTreeNodeViewModel(ParseTreeNode model) : base(model) =>
Children = (model?.Children.Select(x => new ParseTreeNodeViewModel(x)) ?? Enumerable.Empty<ParseTreeNodeViewModel>()).ToList().AsReadOnly();

Expand Down
12 changes: 10 additions & 2 deletions Shared/ViewModels/VisualizerDataViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ public int SourceSelectionLength {
public ReadOnlyCollection<TokenViewModel> Tokens { get; }

public VisualizerDataViewModel(VisualizerData visualizerData) : base(visualizerData) {
Root = new ParseTreeNodeViewModel(visualizerData.Root);
Tokens = visualizerData.Tokens.OrderBy(x => x.Index).Select(x => new TokenViewModel(x)).ToList().AsReadOnly();
Root = ParseTreeNodeViewModel.Create(visualizerData.Root);
Tokens = visualizerData.Tokens?.OrderBy(x => x.Index).Select(x => new TokenViewModel(x)).ToList().AsReadOnly();

if (!(Root is null)) {
if (visualizerData.Config.HasTreeFilter()) {
Root.SetSubtreeExpanded(true);
} else {
Root.IsExpanded = true;
}
}
}

private bool inUpdateSelection;
Expand Down
19 changes: 11 additions & 8 deletions Shared/VisualizerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<Setter Property="DockPanel.Dock" Value="Top"/>
<Setter Property="Margin" Value="0,0,0,3" />
</Style>
<Style TargetType="TextBlock" x:Key="TextTrimmedTextbox">
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
<Setter Property="ToolTip" Value="{Binding Text,RelativeSource={RelativeSource Self}}" />
</Style>

<my1:ComboBoxTemplateSelector x:Key="ComboBoxTemplateSelector">
<my1:ComboBoxTemplateSelector.DropdownItemsTemplate>
Expand Down Expand Up @@ -69,7 +73,7 @@

<DockPanel DockPanel.Dock="Bottom" Margin="0,12,0,0">
<TextBlock Text="Source:" Style="{StaticResource LabelStyle}" />
<my:BindableSelectionTextBox x:Name="source" Height="200" Text="{Binding Model.Source, Mode=OneTime}" IsReadOnly="True" BindableSelectionStart="{Binding SourceSelectionStart}" BindableSelectionLength="{Binding SourceSelectionLength}">
<my:BindableSelectionTextBox x:Name="source" Height="200" Text="{Binding Model.Source, Mode=OneTime}" IsReadOnly="True" BindableSelectionStart="{Binding SourceSelectionStart, Mode=TwoWay}" BindableSelectionLength="{Binding SourceSelectionLength, Mode=TwoWay}" TextWrapping="Wrap">
<b:Interaction.Triggers>
<b:EventTrigger EventName="SelectionChanged">
<b:InvokeCommandAction Command="{Binding ChangeSelection}" CommandParameter="{Binding}" />
Expand All @@ -85,19 +89,13 @@
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Custom" Binding="{Binding Custom, Mode=OneWay}" />
<DataGridTextColumn Header="Name" Binding="{Binding Key, Mode=OneWay}" />
<DataGridTextColumn Header="Value" Binding="{Binding Value, TargetNullValue=null, Mode=OneWay}" MaxWidth="150" >
<DataGridTextColumn Header="Value" Binding="{Binding Value, TargetNullValue=null, Mode=OneWay}" Width="150" ElementStyle="{StaticResource TextTrimmedTextbox}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Foreground" Value="{Binding Value, Converter={StaticResource NullConverter}}" />
<Setter Property="FontStyle" Value="{Binding Value, Converter={StaticResource NullConverter}}" />
<Setter Property="ToolTip" Value="{Binding Value}" />
</Style>
</DataGridTextColumn.CellStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
Expand Down Expand Up @@ -251,6 +249,11 @@
<Style TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Style.Resources>
<Style TargetType="ItemsPresenter">
<Setter Property="Margin" Value="-6,0,0,0" />
</Style>
</Style.Resources>
</Style>
</TreeView.ItemContainerStyle>
<b:Interaction.Triggers>
Expand Down
12 changes: 5 additions & 7 deletions Shared/VisualizerControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public VisualizerControl() {
)) {
e.Cancel = true;
}
if (e.PropertyName == nameof(TokenViewModel.Text)) {
e.Column.Width = 150;
(e.Column as DataGridTextColumn).ElementStyle = FindResource("TextTrimmedTextbox") as Style;
}
};

// scrolls the tree view item into view when selected
Expand Down Expand Up @@ -50,8 +55,6 @@ public VisualizerControl() {
tokens.ScrollIntoView(firstSelected);
};
data.Root.IsExpanded = true;
source.LostFocus += (s1, e1) => e1.Handled = true;
source.Focus();
source.SelectionChanged += (s1, e1) => {
Expand All @@ -72,11 +75,6 @@ private void LoadDataContext() {
throw new InvalidOperationException("Unspecified error while serializing/deserializing");
}
DataContext = new VisualizerDataViewModel(response);
if (Config.HasTreeFilter()) {
data.Root.SetSubtreeExpanded(true);
} else {
data.Root.IsExpanded = true;
}
config = data.Model.Config;
Config.Write();

Expand Down
5 changes: 4 additions & 1 deletion Shared/VisualizerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public VisualizerWindow() {
// if we could find out which is the current monitor, that would be better
var workingAreas = Monitor.AllMonitors.Select(x => x.WorkingArea).ToList();
MaxWidth = workingAreas.Min(x => x.Width) * .90;
MaxHeight = workingAreas.Min(x => x.Height) * .90;
MinWidth = MaxWidth;
MaxHeight= workingAreas.Min(x => x.Height) * .90;
MinHeight = MaxHeight;


PreviewKeyDown += (s, e) => {
if (e.Key == Key.Escape) { Close(); }
Expand Down

0 comments on commit e8bc561

Please sign in to comment.