mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-23 01:36:57 -08:00
code_style: move RevisionTextFileView
Some checks are pending
Some checks are pending
This commit is contained in:
parent
e033a93dd8
commit
620f411e99
2 changed files with 110 additions and 110 deletions
|
@ -1,7 +1,117 @@
|
|||
using System;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
using AvaloniaEdit;
|
||||
using AvaloniaEdit.Document;
|
||||
using AvaloniaEdit.Editing;
|
||||
using AvaloniaEdit.TextMate;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class RevisionTextFileView : TextEditor
|
||||
{
|
||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||
|
||||
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
|
||||
{
|
||||
IsReadOnly = true;
|
||||
ShowLineNumbers = true;
|
||||
WordWrap = false;
|
||||
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
|
||||
VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
|
||||
|
||||
TextArea.LeftMargins[0].Margin = new Thickness(8, 0);
|
||||
TextArea.TextView.Margin = new Thickness(4, 0);
|
||||
TextArea.TextView.Options.EnableHyperlinks = false;
|
||||
TextArea.TextView.Options.EnableEmailHyperlinks = false;
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
||||
UpdateTextMate();
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnUnloaded(e);
|
||||
|
||||
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
||||
|
||||
if (_textMate != null)
|
||||
{
|
||||
_textMate.Dispose();
|
||||
_textMate = null;
|
||||
}
|
||||
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
protected override void OnDataContextChanged(EventArgs e)
|
||||
{
|
||||
base.OnDataContextChanged(e);
|
||||
|
||||
if (DataContext is Models.RevisionTextFile source)
|
||||
{
|
||||
UpdateTextMate();
|
||||
Text = source.Content;
|
||||
}
|
||||
else
|
||||
{
|
||||
Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
var selected = SelectedText;
|
||||
if (string.IsNullOrEmpty(selected))
|
||||
return;
|
||||
|
||||
var copy = new MenuItem() { Header = App.Text("Copy") };
|
||||
copy.Click += (_, ev) =>
|
||||
{
|
||||
App.CopyText(selected);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
if (this.FindResource("Icons.Copy") is Geometry geo)
|
||||
{
|
||||
copy.Icon = new Avalonia.Controls.Shapes.Path()
|
||||
{
|
||||
Width = 10,
|
||||
Height = 10,
|
||||
Stretch = Stretch.Uniform,
|
||||
Data = geo,
|
||||
};
|
||||
}
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(copy);
|
||||
menu.Open(TextArea.TextView);
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void UpdateTextMate()
|
||||
{
|
||||
if (_textMate == null)
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
|
||||
if (DataContext is Models.RevisionTextFile file)
|
||||
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);
|
||||
}
|
||||
|
||||
private TextMate.Installation _textMate = null;
|
||||
}
|
||||
|
||||
public partial class RevisionFileContentViewer : UserControl
|
||||
{
|
||||
public RevisionFileContentViewer()
|
||||
|
|
|
@ -1,118 +1,8 @@
|
|||
using System;
|
||||
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
using AvaloniaEdit;
|
||||
using AvaloniaEdit.Document;
|
||||
using AvaloniaEdit.Editing;
|
||||
using AvaloniaEdit.TextMate;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public class RevisionTextFileView : TextEditor
|
||||
{
|
||||
protected override Type StyleKeyOverride => typeof(TextEditor);
|
||||
|
||||
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
|
||||
{
|
||||
IsReadOnly = true;
|
||||
ShowLineNumbers = true;
|
||||
WordWrap = false;
|
||||
HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
|
||||
VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
|
||||
|
||||
TextArea.LeftMargins[0].Margin = new Thickness(8, 0);
|
||||
TextArea.TextView.Margin = new Thickness(4, 0);
|
||||
TextArea.TextView.Options.EnableHyperlinks = false;
|
||||
TextArea.TextView.Options.EnableEmailHyperlinks = false;
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
|
||||
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
||||
UpdateTextMate();
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnUnloaded(e);
|
||||
|
||||
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
||||
|
||||
if (_textMate != null)
|
||||
{
|
||||
_textMate.Dispose();
|
||||
_textMate = null;
|
||||
}
|
||||
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
protected override void OnDataContextChanged(EventArgs e)
|
||||
{
|
||||
base.OnDataContextChanged(e);
|
||||
|
||||
if (DataContext is Models.RevisionTextFile source)
|
||||
{
|
||||
UpdateTextMate();
|
||||
Text = source.Content;
|
||||
}
|
||||
else
|
||||
{
|
||||
Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
||||
{
|
||||
var selected = SelectedText;
|
||||
if (string.IsNullOrEmpty(selected))
|
||||
return;
|
||||
|
||||
var copy = new MenuItem() { Header = App.Text("Copy") };
|
||||
copy.Click += (_, ev) =>
|
||||
{
|
||||
App.CopyText(selected);
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
if (this.FindResource("Icons.Copy") is Geometry geo)
|
||||
{
|
||||
copy.Icon = new Avalonia.Controls.Shapes.Path()
|
||||
{
|
||||
Width = 10,
|
||||
Height = 10,
|
||||
Stretch = Stretch.Uniform,
|
||||
Data = geo,
|
||||
};
|
||||
}
|
||||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(copy);
|
||||
menu.Open(TextArea.TextView);
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void UpdateTextMate()
|
||||
{
|
||||
if (_textMate == null)
|
||||
_textMate = Models.TextMateHelper.CreateForEditor(this);
|
||||
|
||||
if (DataContext is Models.RevisionTextFile file)
|
||||
Models.TextMateHelper.SetGrammarByFileName(_textMate, file.FileName);
|
||||
}
|
||||
|
||||
private TextMate.Installation _textMate = null;
|
||||
}
|
||||
|
||||
public partial class RevisionFiles : UserControl
|
||||
{
|
||||
public RevisionFiles()
|
||||
|
|
Loading…
Reference in a new issue