Skip to content

Commit 8ebf4d7

Browse files
committed
ux: use AvaloniaEdit.TextEditor to display release update detail info
1 parent c6afc6a commit 8ebf4d7

File tree

2 files changed

+69
-7
lines changed

2 files changed

+69
-7
lines changed

src/Views/SelfUpdate.axaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@
5252
</Border>
5353
</StackPanel>
5454

55-
<TextBox IsReadOnly="True"
56-
TextWrapping="Wrap"
57-
ScrollViewer.VerticalScrollBarVisibility="Auto"
58-
MaxWidth="500" MaxHeight="400"
59-
Margin="0,8" Padding="0"
60-
VerticalContentAlignment="Top"
61-
Text="{Binding Body}"/>
55+
<Border Width="500" MaxHeight="400"
56+
Margin="0,8"
57+
Background="{DynamicResource Brush.Contents}"
58+
BorderThickness="1"
59+
BorderBrush="{DynamicResource Brush.Border2}">
60+
<v:UpdateInfoView/>
61+
</Border>
6262

6363
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
6464
<Button Classes="flat primary"

src/Views/SelfUpdate.axaml.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,70 @@
1+
using System;
2+
3+
using Avalonia;
14
using Avalonia.Controls;
5+
using Avalonia.Controls.Primitives;
26
using Avalonia.Interactivity;
37

8+
using AvaloniaEdit.Document;
9+
using AvaloniaEdit.Editing;
10+
using AvaloniaEdit.TextMate;
11+
using AvaloniaEdit;
12+
413
namespace SourceGit.Views
514
{
15+
public class UpdateInfoView : TextEditor
16+
{
17+
protected override Type StyleKeyOverride => typeof(TextEditor);
18+
19+
public UpdateInfoView() : base(new TextArea(), new TextDocument())
20+
{
21+
IsReadOnly = true;
22+
ShowLineNumbers = false;
23+
WordWrap = true;
24+
HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
25+
VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
26+
27+
TextArea.TextView.Margin = new Thickness(4, 0);
28+
TextArea.TextView.Options.EnableHyperlinks = false;
29+
TextArea.TextView.Options.EnableEmailHyperlinks = false;
30+
31+
}
32+
33+
protected override void OnLoaded(RoutedEventArgs e)
34+
{
35+
base.OnLoaded(e);
36+
37+
if (_textMate == null)
38+
{
39+
_textMate = Models.TextMateHelper.CreateForEditor(this);
40+
Models.TextMateHelper.SetGrammarByFileName(_textMate, "README.md");
41+
}
42+
}
43+
44+
protected override void OnUnloaded(RoutedEventArgs e)
45+
{
46+
base.OnUnloaded(e);
47+
48+
if (_textMate != null)
49+
{
50+
_textMate.Dispose();
51+
_textMate = null;
52+
}
53+
54+
GC.Collect();
55+
}
56+
57+
protected override void OnDataContextChanged(EventArgs e)
58+
{
59+
base.OnDataContextChanged(e);
60+
61+
if (DataContext is Models.Version ver)
62+
Text = ver.Body;
63+
}
64+
65+
private TextMate.Installation _textMate = null;
66+
}
67+
668
public partial class SelfUpdate : ChromelessWindow
769
{
870
public SelfUpdate()

0 commit comments

Comments
 (0)