2024-03-17 18:37:06 -07:00
|
|
|
using System;
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
using Avalonia;
|
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Controls.Primitives;
|
|
|
|
using Avalonia.Interactivity;
|
|
|
|
using Avalonia.Media;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
using AvaloniaEdit;
|
|
|
|
using AvaloniaEdit.Document;
|
|
|
|
using AvaloniaEdit.Editing;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
|
|
|
namespace SourceGit.Views
|
|
|
|
{
|
|
|
|
public class RevisionTextFileView : TextEditor
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
protected override Type StyleKeyOverride => typeof(TextEditor);
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public RevisionTextFileView() : base(new TextArea(), new TextDocument())
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
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);
|
2024-04-09 20:02:33 -07:00
|
|
|
TextArea.TextView.Options.EnableHyperlinks = false;
|
|
|
|
TextArea.TextView.Options.EnableEmailHyperlinks = false;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnLoaded(RoutedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnLoaded(e);
|
|
|
|
|
|
|
|
TextArea.TextView.ContextRequested += OnTextViewContextRequested;
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnUnloaded(RoutedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnUnloaded(e);
|
|
|
|
|
|
|
|
TextArea.TextView.ContextRequested -= OnTextViewContextRequested;
|
|
|
|
GC.Collect();
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
protected override void OnDataContextChanged(EventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
base.OnDataContextChanged(e);
|
|
|
|
|
|
|
|
var source = DataContext as Models.RevisionTextFile;
|
2024-03-17 18:37:06 -07:00
|
|
|
if (source != null)
|
2024-02-05 23:08:37 -08:00
|
|
|
Text = source.Content;
|
2024-06-07 01:32:06 -07:00
|
|
|
else
|
|
|
|
Text = string.Empty;
|
2024-02-05 23:08:37 -08:00
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e)
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
var selected = SelectedText;
|
2024-03-31 01:54:29 -07:00
|
|
|
if (string.IsNullOrEmpty(selected))
|
|
|
|
return;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
var icon = new Avalonia.Controls.Shapes.Path();
|
|
|
|
icon.Width = 10;
|
|
|
|
icon.Height = 10;
|
|
|
|
icon.Stretch = Stretch.Uniform;
|
|
|
|
icon.Data = App.Current?.FindResource("Icons.Copy") as StreamGeometry;
|
|
|
|
|
|
|
|
var copy = new MenuItem();
|
|
|
|
copy.Header = App.Text("Copy");
|
|
|
|
copy.Icon = icon;
|
2024-03-17 18:37:06 -07:00
|
|
|
copy.Click += (o, ev) =>
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
App.CopyText(selected);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
var menu = new ContextMenu();
|
|
|
|
menu.Items.Add(copy);
|
2024-05-23 06:24:22 -07:00
|
|
|
|
|
|
|
TextArea.TextView.OpenContextMenu(menu);
|
2024-02-05 23:08:37 -08:00
|
|
|
e.Handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
public partial class RevisionFiles : UserControl
|
|
|
|
{
|
|
|
|
public RevisionFiles()
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
}
|