feature<DiffViewer, CommitViewer>: override default behaviour while using Ctrl+C to copy selected lines in DataGrid

This commit is contained in:
leo 2020-12-16 16:02:13 +08:00
parent b81cf63b6f
commit d1f64b1d12
2 changed files with 32 additions and 0 deletions

View file

@ -446,6 +446,21 @@ namespace SourceGit.UI {
grid.FrozenColumnCount = 1; grid.FrozenColumnCount = 1;
grid.ContextMenuOpening += OnPreviewContextMenuOpening; grid.ContextMenuOpening += OnPreviewContextMenuOpening;
grid.RowStyle = FindResource("Style.DataGridRow.NoBringIntoView") as Style; grid.RowStyle = FindResource("Style.DataGridRow.NoBringIntoView") as Style;
grid.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (o, e) => {
var items = (o as DataGrid).SelectedItems;
if (items.Count == 0) return;
var builder = new StringBuilder();
foreach (var item in items) {
var line = item as Git.Commit.Line;
if (line == null) continue;
builder.Append(line.Content);
builder.AppendLine();
}
Clipboard.SetText(builder.ToString());
}));
var colLineNumber = new DataGridTextColumn(); var colLineNumber = new DataGridTextColumn();
colLineNumber.IsReadOnly = true; colLineNumber.IsReadOnly = true;

View file

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
using System.Windows.Threading; using System.Windows.Threading;
@ -425,6 +426,22 @@ namespace SourceGit.UI {
grid.FrozenColumnCount = lineNumbers.Length; grid.FrozenColumnCount = lineNumbers.Length;
grid.ContextMenuOpening += OnTextChangeContextMenuOpening; grid.ContextMenuOpening += OnTextChangeContextMenuOpening;
grid.RowStyle = FindResource("Style.DataGridRow.NoBringIntoView") as Style; grid.RowStyle = FindResource("Style.DataGridRow.NoBringIntoView") as Style;
grid.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (o, e) => {
var items = (o as DataGrid).SelectedItems;
if (items.Count == 0) return;
var builder = new StringBuilder();
foreach (var item in items) {
var block = item as ChangeBlock;
if (block == null) continue;
if (!block.IsContent) continue;
builder.Append(block.Content);
builder.AppendLine();
}
Clipboard.SetText(builder.ToString());
}));
foreach (var number in lineNumbers) { foreach (var number in lineNumbers) {
var colLineNumber = new DataGridTextColumn(); var colLineNumber = new DataGridTextColumn();