|
| 1 | +using System; |
| 2 | + |
| 3 | +using Avalonia; |
1 | 4 | using Avalonia.Controls;
|
| 5 | +using Avalonia.Controls.Primitives; |
2 | 6 | using Avalonia.Interactivity;
|
3 | 7 |
|
| 8 | +using AvaloniaEdit.Document; |
| 9 | +using AvaloniaEdit.Editing; |
| 10 | +using AvaloniaEdit.TextMate; |
| 11 | +using AvaloniaEdit; |
| 12 | + |
4 | 13 | namespace SourceGit.Views
|
5 | 14 | {
|
| 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 | + |
6 | 68 | public partial class SelfUpdate : ChromelessWindow
|
7 | 69 | {
|
8 | 70 | public SelfUpdate()
|
|
0 commit comments