Skip to content

Feature: inserting multiple items from clipboard #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion solution/GraphicalDebugging/GeometryWatchControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ private void dataGrid_PreviewKeyDown(object sender, System.Windows.Input.KeyEven
}
else if (e.Key == System.Windows.Input.Key.V && e.KeyboardDevice.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Control))
{
Util.PasteDataGridItemFromClipboard(dataGrid, Geometries);
Util.PasteDataGridItemFromClipboard(dataGrid, Geometries, (name) =>
{
var newItem = new GeometryItem() { Name = name };
newItem.PropertyChanged += GeometryItem_PropertyChanged;
return newItem;
});
UpdateItems(false);
}
}

Expand Down
8 changes: 7 additions & 1 deletion solution/GraphicalDebugging/GraphicalWatchControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ private void dataGrid_PreviewKeyDown(object sender, System.Windows.Input.KeyEven
}
else if (e.Key == System.Windows.Input.Key.V && e.KeyboardDevice.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Control))
{
Util.PasteDataGridItemFromClipboard(dataGrid, Variables);
Util.PasteDataGridItemFromClipboard(dataGrid, Variables, (name) =>
{
var newItem = new GraphicalItem() { Name = name };
newItem.PropertyChanged += GraphicalItem_PropertyChanged;
return newItem;
});
UpdateItems(false);
}
}

Expand Down
8 changes: 7 additions & 1 deletion solution/GraphicalDebugging/PlotWatchControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@ private void dataGrid_PreviewKeyDown(object sender, System.Windows.Input.KeyEven
}
else if (e.Key == System.Windows.Input.Key.V && e.KeyboardDevice.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Control))
{
Util.PasteDataGridItemFromClipboard(dataGrid, Plots);
Util.PasteDataGridItemFromClipboard(dataGrid, Plots, (name) =>
{
var newItem = new PlotItem() { Name = name };
newItem.PropertyChanged += PlotItem_PropertyChanged;
return newItem;
});
UpdateItems(false);
}
}

Expand Down
24 changes: 20 additions & 4 deletions solution/GraphicalDebugging/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
Expand Down Expand Up @@ -509,7 +510,8 @@ public static void EnableDataGridItems<Item>(System.Windows.Controls.DataGrid da
}

public static void PasteDataGridItemFromClipboard<Item>(System.Windows.Controls.DataGrid dataGrid,
System.Collections.ObjectModel.ObservableCollection<Item> itemsCollection)
System.Collections.ObjectModel.ObservableCollection<Item> itemsCollection,
Func<string, VariableItem> newItemCallback)
where Item : VariableItem
{
string text = Clipboard.GetText();
Expand All @@ -522,9 +524,23 @@ public static void PasteDataGridItemFromClipboard<Item>(System.Windows.Controls.
int index = dataGrid.Items.IndexOf(dataGrid.SelectedItems[0]);
if (index < 0 || index >= dataGrid.Items.Count)
return;

Item item = itemsCollection[index];
item.Name = text;

if (text.Contains(Environment.NewLine))
{
// insert new items
var lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < lines.Length; i++)
{
var newItem = newItemCallback(lines[i]);
itemsCollection.Insert(index + i, (Item)newItem);
}
}
else
{
// replace existing item name
Item item = itemsCollection[index];
item.Name = text;
}
}

// https://softwaremechanik.wordpress.com/2013/10/02/how-to-make-all-wpf-datagrid-cells-have-a-single-click-to-edit/
Expand Down