diff --git a/solution/GraphicalDebugging/GeometryWatchControl.xaml.cs b/solution/GraphicalDebugging/GeometryWatchControl.xaml.cs index 7c5a441..246d287 100644 --- a/solution/GraphicalDebugging/GeometryWatchControl.xaml.cs +++ b/solution/GraphicalDebugging/GeometryWatchControl.xaml.cs @@ -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); } } diff --git a/solution/GraphicalDebugging/GraphicalWatchControl.xaml.cs b/solution/GraphicalDebugging/GraphicalWatchControl.xaml.cs index 69726cb..3a754e5 100644 --- a/solution/GraphicalDebugging/GraphicalWatchControl.xaml.cs +++ b/solution/GraphicalDebugging/GraphicalWatchControl.xaml.cs @@ -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); } } diff --git a/solution/GraphicalDebugging/PlotWatchControl.xaml.cs b/solution/GraphicalDebugging/PlotWatchControl.xaml.cs index d1dd2f7..bccb9fe 100644 --- a/solution/GraphicalDebugging/PlotWatchControl.xaml.cs +++ b/solution/GraphicalDebugging/PlotWatchControl.xaml.cs @@ -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); } } diff --git a/solution/GraphicalDebugging/Util.cs b/solution/GraphicalDebugging/Util.cs index 4ddee34..4d3d3fe 100644 --- a/solution/GraphicalDebugging/Util.cs +++ b/solution/GraphicalDebugging/Util.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Drawing; using System.Drawing.Imaging; using System.Globalization; @@ -509,7 +510,8 @@ public static void EnableDataGridItems(System.Windows.Controls.DataGrid da } public static void PasteDataGridItemFromClipboard(System.Windows.Controls.DataGrid dataGrid, - System.Collections.ObjectModel.ObservableCollection itemsCollection) + System.Collections.ObjectModel.ObservableCollection itemsCollection, + Func newItemCallback) where Item : VariableItem { string text = Clipboard.GetText(); @@ -522,9 +524,23 @@ public static void PasteDataGridItemFromClipboard(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/