Implemented syntax highlighting for the message body in subscriber tabs

This commit is contained in:
Mark van Renswoude 2022-01-03 17:44:20 +01:00
parent 79776fd813
commit 5fc5c1be12
3 changed files with 29 additions and 14 deletions

View File

@ -29,11 +29,10 @@
<Border Style="{StaticResource ControlBorder}" Name="EditorBorder">
<avalonedit:TextEditor
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
Name="Editor"
SyntaxHighlighting="{Binding SyntaxHighlighting}"
Style="{StaticResource Payload}"
/>
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
Name="Editor"
SyntaxHighlighting="{Binding SyntaxHighlighting}"
Style="{StaticResource Payload}" />
</Border>
</DockPanel>
</UserControl>

View File

@ -6,6 +6,7 @@
xmlns:ui="clr-namespace:PettingZoo.UI"
xmlns:res="clr-namespace:PettingZoo.UI.Tab.Subscriber"
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
@ -25,7 +26,8 @@
HorizontalContentAlignment="Stretch"
ItemsSource="{Binding Messages}"
SelectedItem="{Binding Path=SelectedMessage, Mode=TwoWay}"
ui:ListBox.AutoScroll="True">
ui:ListBox.AutoScroll="True"
x:Name="ReferenceControlForBorder">
<ListBox.Resources>
<ui:BindingProxy x:Key="ContextMenuProxy" Data="{Binding}" />
</ListBox.Resources>
@ -95,14 +97,11 @@
<Border Grid.Column="0" Grid.Row="1" Style="{StaticResource SidePanel}">
<DockPanel>
<Label DockPanel.Dock="Top" Style="{StaticResource HeaderLabel}" Content="{x:Static res:SubscriberViewStrings.PanelTitleBody}"/>
<!-- TODO use AvalonEdit with syntax highlighting depending on content type -->
<TextBox
Text="{Binding SelectedMessageBody, Mode=OneWay}"
BorderThickness="0"
IsReadOnly="True"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"/>
<Border Style="{StaticResource ControlBorder}" Name="EditorBorder">
<avalonedit:TextEditor
Name="Editor"
Style="{StaticResource Payload}" />
</Border>
</DockPanel>
</Border>
<GridSplitter HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="2" Height="5" ResizeDirection="Rows"/>

View File

@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ICSharpCode.AvalonEdit.Highlighting;
namespace PettingZoo.UI.Tab.Subscriber
{
@ -14,6 +15,22 @@ namespace PettingZoo.UI.Tab.Subscriber
DataContext = viewModel;
InitializeComponent();
// TODO wrap all this nonsense (which is a duplicate from PayloadEditorControl) in a UserControl
// should contain the border, one- or two-way Document binding and the automatic syntax highlighting based on a bound content-type
EditorBorder.BorderBrush = ReferenceControlForBorder.BorderBrush;
Editor.Options.IndentationSize = 2;
viewModel.PropertyChanged += (_, args) =>
{
if (args.PropertyName != nameof(viewModel.SelectedMessageBody))
return;
Editor.Document.Text = viewModel.SelectedMessageBody;
Editor.SyntaxHighlighting = (viewModel.SelectedMessage?.Properties.ContentType ?? "") == "application/json"
? HighlightingManager.Instance.GetDefinition(@"Json")
: null;
};
if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
Background = Brushes.Transparent;