-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced hex grid with simpler design, less controls. Fixes #386
- Loading branch information
1 parent
b7188b1
commit 7233fd2
Showing
13 changed files
with
247 additions
and
273 deletions.
There are no files selected for viewing
96 changes: 32 additions & 64 deletions
96
src/ServiceInsight.Desktop/MessageViewers/HexViewer/HexContentView.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,41 @@ | ||
<UserControl x:Class="Particular.ServiceInsight.Desktop.MessageViewers.HexViewer.HexContentView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:Particular.ServiceInsight.Desktop.MessageViewers.HexViewer" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" d:DesignWidth="300"> | ||
|
||
<UserControl.Resources> | ||
<DataTemplate DataType="{x:Type local:HexPart}"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="60"/> | ||
<ColumnDefinition MinWidth="350" Width="520" /> | ||
<ColumnDefinition Width="200"/> | ||
</Grid.ColumnDefinitions> | ||
<TextBlock Text="{Binding LineNumber, Mode=OneWay}" | ||
Margin="5" | ||
FontFamily="{StaticResource MessageBodyFontFamily}" | ||
FontSize="{StaticResource MessageBodyFontSize}" | ||
Foreground="DarkCyan" Grid.Column="0"/> | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
d:DesignHeight="300" | ||
d:DesignWidth="300" | ||
mc:Ignorable="d"> | ||
|
||
<!--Hex display of the byte Representative of the Hex char--> | ||
<ItemsControl ItemsSource="{Binding Numbers}" | ||
Grid.Column="1" | ||
Background="{x:Null}" | ||
BorderThickness="0" | ||
BorderBrush="{x:Null}" | ||
IsHitTestVisible="False" | ||
ScrollViewer.HorizontalScrollBarVisibility="Hidden"> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<StackPanel Orientation="Horizontal" /> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<TextBlock Margin="5" Text="{Binding Hex}" | ||
FontFamily="{StaticResource MessageBodyFontFamily}" | ||
FontSize="{StaticResource MessageBodyFontSize}" | ||
Foreground="Black" /> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
<ScrollViewer> | ||
|
||
<!--Text display of the byte--> | ||
<ItemsControl ItemsSource="{Binding Numbers}" Grid.Column="2" Margin="20,0,0,0" BorderBrush="{x:Null}"> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<StackPanel Orientation="Horizontal" /> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<TextBlock Margin="5" Background="Transparent" Text="{Binding Text}" | ||
FontFamily="{StaticResource MessageBodyFontFamily}" | ||
FontSize="{StaticResource MessageBodyFontSize}" | ||
Foreground="Gray" /> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
<local:HexControl Data="{Binding SelectedMessage}"> | ||
<local:HexControl.HexLineStyle> | ||
<Style TargetType="TextBlock"> | ||
<Setter Property="Margin" Value="5" /> | ||
<Setter Property="FontFamily" Value="{StaticResource MessageBodyFontFamily}" /> | ||
<Setter Property="FontSize" Value="{StaticResource MessageBodyFontSize}" /> | ||
<Setter Property="Foreground" Value="DarkCyan" /> | ||
</Style> | ||
</local:HexControl.HexLineStyle> | ||
<local:HexControl.HexNumberStyle> | ||
<Style TargetType="TextBlock"> | ||
<Setter Property="Margin" Value="5" /> | ||
<Setter Property="FontFamily" Value="{StaticResource MessageBodyFontFamily}" /> | ||
<Setter Property="FontSize" Value="{StaticResource MessageBodyFontSize}" /> | ||
<Setter Property="Foreground" Value="Black" /> | ||
</Style> | ||
</local:HexControl.HexNumberStyle> | ||
<local:HexControl.HexCharStyle> | ||
<Style TargetType="TextBlock"> | ||
<Setter Property="Margin" Value="5" /> | ||
<Setter Property="FontFamily" Value="{StaticResource MessageBodyFontFamily}" /> | ||
<Setter Property="FontSize" Value="{StaticResource MessageBodyFontSize}" /> | ||
<Setter Property="Foreground" Value="Gray" /> | ||
</Style> | ||
</local:HexControl.HexCharStyle> | ||
</local:HexControl> | ||
|
||
</Grid> | ||
</DataTemplate> | ||
</UserControl.Resources> | ||
|
||
<ScrollViewer> | ||
<ItemsControl x:Name="listBox" | ||
Background="White" | ||
ItemsSource="{Binding HexParts}"/> | ||
</ScrollViewer> | ||
</UserControl> | ||
</UserControl> |
4 changes: 2 additions & 2 deletions
4
src/ServiceInsight.Desktop/MessageViewers/HexViewer/HexContentView.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
namespace Particular.ServiceInsight.Desktop.MessageViewers.HexViewer | ||
{ | ||
public partial class HexContentView : IHexContentView | ||
public partial class HexContentView | ||
{ | ||
public HexContentView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/ServiceInsight.Desktop/MessageViewers/HexViewer/HexControl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
namespace Particular.ServiceInsight.Desktop.MessageViewers.HexViewer | ||
{ | ||
using System; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using ExtensionMethods; | ||
|
||
[TemplatePart(Name = "PART_HEXGRID", Type = typeof(Grid))] | ||
public class HexControl : Control | ||
{ | ||
public static readonly DependencyProperty DataProperty = DependencyProperty.Register( | ||
"Data", typeof(byte[]), typeof(HexControl), new PropertyMetadata(default(byte[]), DataChanged)); | ||
|
||
static void DataChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) | ||
{ | ||
((HexControl)dependencyObject).OnDataChanged(); | ||
} | ||
|
||
public byte[] Data | ||
{ | ||
get { return (byte[])GetValue(DataProperty); } | ||
set { SetValue(DataProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty HexLineStyleProperty = DependencyProperty.Register( | ||
"HexLineStyle", typeof(Style), typeof(HexControl), new PropertyMetadata(default(Style))); | ||
|
||
public Style HexLineStyle | ||
{ | ||
get { return (Style)GetValue(HexLineStyleProperty); } | ||
set { SetValue(HexLineStyleProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty HexNumberStyleProperty = DependencyProperty.Register( | ||
"HexNumberStyle", typeof(Style), typeof(HexControl), new PropertyMetadata(default(Style))); | ||
|
||
public Style HexNumberStyle | ||
{ | ||
get { return (Style)GetValue(HexNumberStyleProperty); } | ||
set { SetValue(HexNumberStyleProperty, value); } | ||
} | ||
|
||
public static readonly DependencyProperty HexCharStyleProperty = DependencyProperty.Register( | ||
"HexCharStyle", typeof(Style), typeof(HexControl), new PropertyMetadata(default(Style))); | ||
|
||
public Style HexCharStyle | ||
{ | ||
get { return (Style)GetValue(HexCharStyleProperty); } | ||
set { SetValue(HexCharStyleProperty, value); } | ||
} | ||
|
||
static HexControl() | ||
{ | ||
DefaultStyleKeyProperty.OverrideMetadata(typeof(HexControl), new FrameworkPropertyMetadata(typeof(HexControl))); | ||
} | ||
|
||
private Grid hexGrid; | ||
|
||
public override void OnApplyTemplate() | ||
{ | ||
hexGrid = GetTemplateChild("PART_HEXGRID") as Grid; | ||
} | ||
|
||
private void OnDataChanged() | ||
{ | ||
if (hexGrid == null || Data == null) | ||
return; | ||
|
||
hexGrid.Children.Clear(); | ||
|
||
var lines = (int)Math.Ceiling(Data.Length / 16.0); | ||
var linePadding = (int)Math.Ceiling(Math.Log10(lines + 1)); | ||
hexGrid.RowDefinitions.Clear(); | ||
for (var i = 0; i < lines; i++) | ||
{ | ||
hexGrid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); | ||
} | ||
|
||
for (var i = 0; i < lines; i++) | ||
{ | ||
var line = new TextBlock { Style = HexLineStyle, Text = (i + 1).ToString().PadLeft(linePadding) }; | ||
Grid.SetColumn(line, 0); | ||
Grid.SetRow(line, i); | ||
hexGrid.Children.Add(line); | ||
} | ||
|
||
for (var i = 0; i < Data.Length; i++) | ||
{ | ||
var x = i % 16; | ||
var y = i / 16; | ||
|
||
var number = new TextBlock { Style = HexNumberStyle, Text = ToHex(Data[i]) }; | ||
Grid.SetColumn(number, x + 1); | ||
Grid.SetRow(number, y); | ||
hexGrid.Children.Add(number); | ||
|
||
var chr = new TextBlock { Style = HexCharStyle, Text = ToText(Data[i]) }; | ||
Grid.SetColumn(chr, x + 18); | ||
Grid.SetRow(chr, y); | ||
hexGrid.Children.Add(chr); | ||
} | ||
} | ||
|
||
static string ToText(byte b) | ||
{ | ||
Func<byte, string> ByteToStringConverter = byteValue => Encoding.UTF8.GetString(new[] { byteValue }); | ||
var c = ByteToStringConverter.TryGetValue(b, " "); | ||
if (c == "\r" || c == "\n" || c == "\t") | ||
{ | ||
return "."; | ||
} | ||
else | ||
{ | ||
return c; | ||
} | ||
} | ||
|
||
static string ToHex(byte b) | ||
{ | ||
return string.Format(b < 0x10 ? "0{0:X000} " : "{0:X000} ", b); | ||
} | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
src/ServiceInsight.Desktop/MessageViewers/HexViewer/HexNumber.cs
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/ServiceInsight.Desktop/MessageViewers/HexViewer/HexPart.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.