diff --git a/Torch/Torch.csproj b/Torch/Torch.csproj
index b10ede3..703a964 100644
--- a/Torch/Torch.csproj
+++ b/Torch/Torch.csproj
@@ -273,6 +273,9 @@
DictionaryEditor.xaml
+
+ EmbeddedCollectionEditor.xaml
+
ObjectCollectionEditor.xaml
@@ -303,6 +306,10 @@
MSBuild:Compile
Designer
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/Torch/Views/EmbeddedCollectionEditor.xaml b/Torch/Views/EmbeddedCollectionEditor.xaml
new file mode 100644
index 0000000..fac4d11
--- /dev/null
+++ b/Torch/Views/EmbeddedCollectionEditor.xaml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Torch/Views/EmbeddedCollectionEditor.xaml.cs b/Torch/Views/EmbeddedCollectionEditor.xaml.cs
new file mode 100644
index 0000000..ff5a859
--- /dev/null
+++ b/Torch/Views/EmbeddedCollectionEditor.xaml.cs
@@ -0,0 +1,126 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using NLog;
+using NLog.Fluent;
+
+namespace Torch.Views
+{
+ ///
+ /// Interaction logic for EmbeddedCollectionEditor.xaml
+ ///
+ public partial class EmbeddedCollectionEditor : UserControl
+ {
+ public EmbeddedCollectionEditor()
+ {
+ InitializeComponent();
+ DataContextChanged += OnDataContextChanged;
+ }
+
+ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
+ {
+ var c = dependencyPropertyChangedEventArgs.NewValue as ICollection;
+ //var c = DataContext as ICollection;
+ if (c != null)
+ Edit(c);
+ }
+
+ private static readonly Dictionary MethodCache = new Dictionary();
+ private static readonly MethodInfo EditMethod;
+
+
+ static EmbeddedCollectionEditor()
+ {
+ var m = typeof(EmbeddedCollectionEditor).GetMethods();
+ EditMethod = m.First(mt => mt.Name == "Edit" && mt.GetGenericArguments().Length == 1);
+ }
+
+ public void Edit(ICollection collection)
+ {
+ if (collection == null)
+ {
+ MessageBox.Show("Cannot load null collection.", "Edit Error");
+ return;
+ }
+
+ var gt = collection.GetType().GenericTypeArguments[0];
+
+ //substitute for 'where T : new()'
+ if (gt.GetConstructor(Type.EmptyTypes) == null)
+ {
+ MessageBox.Show("Unsupported collection type. Type must have paramaterless ctor.", "Edit Error");
+ return;
+ }
+
+ if (!MethodCache.TryGetValue(gt, out MethodInfo gm))
+ {
+ gm = EditMethod.MakeGenericMethod(gt);
+ MethodCache.Add(gt, gm);
+ }
+
+ gm.Invoke(this, new object[] {collection});
+ }
+
+ public void Edit(ICollection collection) where T : new()
+ {
+ var oc = collection as ObservableCollection ?? new ObservableCollection(collection);
+
+ AddButton.Click += (sender, args) =>
+ {
+ var t = new T();
+ oc.Add(t);
+ ElementList.SelectedItem = t;
+ };
+
+ RemoveButton.Click += RemoveButton_OnClick;
+ ElementList.SelectionChanged += ElementsList_OnSelected;
+
+ ElementList.ItemsSource = oc;
+ oc.CollectionChanged += (sender, args) => RefreshList();
+
+ if (!(collection is ObservableCollection))
+ {
+ collection.Clear();
+ foreach (var o in oc)
+ collection.Add(o);
+ }
+ }
+
+ private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ //this is kinda shitty, but item count is normally small, and it prevents CollectionModifiedExceptions
+ var l = (ObservableCollection)ElementList.ItemsSource;
+ var r = new List(ElementList.SelectedItems.Cast());
+ foreach (var item in r)
+ l.Remove(item);
+ if (l.Any())
+ ElementList.SelectedIndex = 0;
+ }
+
+ private void ElementsList_OnSelected(object sender, RoutedEventArgs e)
+ {
+ var item = (sender as ListBox)?.SelectedItem;
+ PGrid.DataContext = item;
+ }
+
+ private void RefreshList()
+ {
+ ElementList.Items.Refresh();
+ }
+ }
+}
+
diff --git a/Torch/Views/ObjectCollectionEditor.xaml b/Torch/Views/ObjectCollectionEditor.xaml
index 45f1a68..dfc88d6 100644
--- a/Torch/Views/ObjectCollectionEditor.xaml
+++ b/Torch/Views/ObjectCollectionEditor.xaml
@@ -6,24 +6,5 @@
xmlns:local="clr-namespace:Torch.Views"
mc:Ignorable="d"
Height="370" Width="400" Title="Edit Collection">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/Torch/Views/ObjectCollectionEditor.xaml.cs b/Torch/Views/ObjectCollectionEditor.xaml.cs
index 6d21ec9..f32c315 100644
--- a/Torch/Views/ObjectCollectionEditor.xaml.cs
+++ b/Torch/Views/ObjectCollectionEditor.xaml.cs
@@ -25,90 +25,18 @@ namespace Torch.Views
///
public partial class ObjectCollectionEditor : Window
{
- private static readonly Dictionary MethodCache = new Dictionary();
- private static readonly MethodInfo EditMethod;
-
public ObjectCollectionEditor()
{
InitializeComponent();
}
- static ObjectCollectionEditor()
- {
- var m = typeof(ObjectCollectionEditor).GetMethods();
- EditMethod = m.First(mt => mt.Name == "Edit" && mt.GetGenericArguments().Length == 1);
- }
-
public void Edit(ICollection collection, string title)
{
- if (collection == null)
- {
- MessageBox.Show("Cannot load null collection.", "Edit Error");
- return;
- }
-
- var gt = collection.GetType().GenericTypeArguments[0];
-
- //substitute for 'where T : new()'
- if (gt.GetConstructor(Type.EmptyTypes) == null)
- {
- MessageBox.Show("Unsupported collection type. Type must have paramaterless ctor.", "Edit Error");
- return;
- }
-
- if (!MethodCache.TryGetValue(gt, out MethodInfo gm))
- {
- gm = EditMethod.MakeGenericMethod(gt);
- MethodCache.Add(gt, gm);
- }
-
- gm.Invoke(this, new object[] {collection, title});
- }
-
- public void Edit(ICollection collection, string title) where T : new()
- {
- var oc = collection as ObservableCollection ?? new ObservableCollection(collection);
-
- AddButton.Click += (sender, args) =>
- {
- var t = new T();
- oc.Add(t);
- ElementList.SelectedItem = t;
- };
-
- RemoveButton.Click += RemoveButton_OnClick;
- ElementList.SelectionChanged += ElementsList_OnSelected;
-
- ElementList.ItemsSource = oc;
-
+ Editor.Edit(collection);
Title = title;
WindowStartupLocation = WindowStartupLocation.CenterOwner;
ShowDialog();
-
- if (!(collection is ObservableCollection))
- {
- collection.Clear();
- foreach (var o in oc)
- collection.Add(o);
- }
- }
-
- private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
- {
- //this is kinda shitty, but item count is normally small, and it prevents CollectionModifiedExceptions
- var l = (ObservableCollection)ElementList.ItemsSource;
- var r = new List(ElementList.SelectedItems.Cast());
- foreach (var item in r)
- l.Remove(item);
- if (l.Any())
- ElementList.SelectedIndex = 0;
- }
-
- private void ElementsList_OnSelected(object sender, RoutedEventArgs e)
- {
- var item = (sender as ListBox)?.SelectedItem;
- PGrid.DataContext = item;
}
}
}