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);
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
if (DataContext is Models.RevisionTextFile source)
|
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
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
var copy = new MenuItem() { Header = App.Text("Copy") };
|
|
|
|
copy.Click += (_, ev) =>
|
2024-03-17 18:37:06 -07:00
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
App.CopyText(selected);
|
|
|
|
ev.Handled = true;
|
|
|
|
};
|
|
|
|
|
2024-07-14 00:55:15 -07:00
|
|
|
if (this.FindResource("Icons.Copy") is Geometry geo)
|
|
|
|
{
|
|
|
|
copy.Icon = new Avalonia.Controls.Shapes.Path()
|
|
|
|
{
|
|
|
|
Width = 10,
|
|
|
|
Height = 10,
|
|
|
|
Stretch = Stretch.Uniform,
|
|
|
|
Data = geo,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
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
|
|
|
}
|