Implemented syntax highlighting for the message body in subscriber tabs
This commit is contained in:
parent
79776fd813
commit
5fc5c1be12
@ -29,11 +29,10 @@
|
|||||||
|
|
||||||
<Border Style="{StaticResource ControlBorder}" Name="EditorBorder">
|
<Border Style="{StaticResource ControlBorder}" Name="EditorBorder">
|
||||||
<avalonedit:TextEditor
|
<avalonedit:TextEditor
|
||||||
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||||
Name="Editor"
|
Name="Editor"
|
||||||
SyntaxHighlighting="{Binding SyntaxHighlighting}"
|
SyntaxHighlighting="{Binding SyntaxHighlighting}"
|
||||||
Style="{StaticResource Payload}"
|
Style="{StaticResource Payload}" />
|
||||||
/>
|
|
||||||
</Border>
|
</Border>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
xmlns:ui="clr-namespace:PettingZoo.UI"
|
xmlns:ui="clr-namespace:PettingZoo.UI"
|
||||||
xmlns:res="clr-namespace:PettingZoo.UI.Tab.Subscriber"
|
xmlns:res="clr-namespace:PettingZoo.UI.Tab.Subscriber"
|
||||||
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
|
xmlns:svgc="http://sharpvectors.codeplex.com/svgc/"
|
||||||
|
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
@ -25,7 +26,8 @@
|
|||||||
HorizontalContentAlignment="Stretch"
|
HorizontalContentAlignment="Stretch"
|
||||||
ItemsSource="{Binding Messages}"
|
ItemsSource="{Binding Messages}"
|
||||||
SelectedItem="{Binding Path=SelectedMessage, Mode=TwoWay}"
|
SelectedItem="{Binding Path=SelectedMessage, Mode=TwoWay}"
|
||||||
ui:ListBox.AutoScroll="True">
|
ui:ListBox.AutoScroll="True"
|
||||||
|
x:Name="ReferenceControlForBorder">
|
||||||
<ListBox.Resources>
|
<ListBox.Resources>
|
||||||
<ui:BindingProxy x:Key="ContextMenuProxy" Data="{Binding}" />
|
<ui:BindingProxy x:Key="ContextMenuProxy" Data="{Binding}" />
|
||||||
</ListBox.Resources>
|
</ListBox.Resources>
|
||||||
@ -95,14 +97,11 @@
|
|||||||
<Border Grid.Column="0" Grid.Row="1" Style="{StaticResource SidePanel}">
|
<Border Grid.Column="0" Grid.Row="1" Style="{StaticResource SidePanel}">
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<Label DockPanel.Dock="Top" Style="{StaticResource HeaderLabel}" Content="{x:Static res:SubscriberViewStrings.PanelTitleBody}"/>
|
<Label DockPanel.Dock="Top" Style="{StaticResource HeaderLabel}" Content="{x:Static res:SubscriberViewStrings.PanelTitleBody}"/>
|
||||||
|
<Border Style="{StaticResource ControlBorder}" Name="EditorBorder">
|
||||||
<!-- TODO use AvalonEdit with syntax highlighting depending on content type -->
|
<avalonedit:TextEditor
|
||||||
<TextBox
|
Name="Editor"
|
||||||
Text="{Binding SelectedMessageBody, Mode=OneWay}"
|
Style="{StaticResource Payload}" />
|
||||||
BorderThickness="0"
|
</Border>
|
||||||
IsReadOnly="True"
|
|
||||||
HorizontalScrollBarVisibility="Auto"
|
|
||||||
VerticalScrollBarVisibility="Auto"/>
|
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</Border>
|
</Border>
|
||||||
<GridSplitter HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="2" Height="5" ResizeDirection="Rows"/>
|
<GridSplitter HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="2" Height="5" ResizeDirection="Rows"/>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using ICSharpCode.AvalonEdit.Highlighting;
|
||||||
|
|
||||||
namespace PettingZoo.UI.Tab.Subscriber
|
namespace PettingZoo.UI.Tab.Subscriber
|
||||||
{
|
{
|
||||||
@ -14,6 +15,22 @@ namespace PettingZoo.UI.Tab.Subscriber
|
|||||||
DataContext = viewModel;
|
DataContext = viewModel;
|
||||||
InitializeComponent();
|
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))
|
if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
|
||||||
Background = Brushes.Transparent;
|
Background = Brushes.Transparent;
|
||||||
|
Loading…
Reference in New Issue
Block a user