Revert "Collection editor improvements. Allows reordering of elements, and actually updates the list when content changes."
This reverts commit 14e16a959f
.
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid Width="Auto" Height="Auto">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
@@ -16,23 +15,17 @@
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="25" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" Width="20">
|
||||
<Button Content="⭱" FontSize="22" Click="TopButton_Click"/>
|
||||
<Button Content="⭡" FontSize="22" Click="UpButton_Click"/>
|
||||
<Button Content="⭣" FontSize="22" Click="DownButton_Click"/>
|
||||
<Button Content="⭳" FontSize="22" Click="BottomButton_Click"/>
|
||||
</StackPanel>
|
||||
<ListBox Grid.Row="0" Grid.Column="1" x:Name="ElementList"
|
||||
<ListBox Grid.Row="0" Grid.Column="0" x:Name="ElementList"
|
||||
HorizontalContentAlignment="Stretch" Margin="0" VerticalContentAlignment="Stretch" />
|
||||
<GridSplitter Grid.Column="2" Grid.Row="0" Width="2" HorizontalAlignment="Left" VerticalAlignment="Stretch"
|
||||
<GridSplitter Grid.Column="1" Grid.Row="0" Width="2" HorizontalAlignment="Left" VerticalAlignment="Stretch"
|
||||
Background="Gray" ShowsPreview="True" VerticalContentAlignment="Stretch" />
|
||||
|
||||
<local:PropertyGrid Grid.Row="0" Grid.Column="2" x:Name="PGrid" Margin="4,0,0,0" />
|
||||
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" x:Name="AddButton" Content="Add"
|
||||
HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" ClipToBounds="False"
|
||||
<local:PropertyGrid Grid.Row="0" Grid.Column="1" x:Name="PGrid" Margin="4,0,0,0" />
|
||||
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="AddButton" Content="Add"
|
||||
HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top"
|
||||
Width="90" />
|
||||
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" x:Name="RemoveButton" Content="Remove"
|
||||
HorizontalAlignment="Left" Margin="100,0,0,0" ClipToBounds="False"
|
||||
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="RemoveButton" Content="Remove"
|
||||
HorizontalAlignment="Left" Margin="100,0,0,0"
|
||||
VerticalAlignment="Top" Width="90" />
|
||||
|
||||
</Grid>
|
||||
|
@@ -2,7 +2,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
@@ -79,15 +78,12 @@ namespace Torch.Views
|
||||
public void Edit<T>(ICollection<T> collection) where T : new()
|
||||
{
|
||||
var oc = collection as ObservableCollection<T> ?? new ObservableCollection<T>(collection);
|
||||
bool not = typeof(INotifyPropertyChanged).IsAssignableFrom(typeof(T));
|
||||
|
||||
AddButton.Click += (sender, args) =>
|
||||
{
|
||||
var t = new T();
|
||||
oc.Add(t);
|
||||
ElementList.SelectedItem = t;
|
||||
if (not)
|
||||
((INotifyPropertyChanged)t).PropertyChanged += (o, eventArgs) => RefreshList();
|
||||
};
|
||||
|
||||
RemoveButton.Click += RemoveButton_OnClick<T>;
|
||||
@@ -95,11 +91,6 @@ namespace Torch.Views
|
||||
|
||||
ElementList.ItemsSource = oc;
|
||||
oc.CollectionChanged += (sender, args) => RefreshList();
|
||||
if (not)
|
||||
{
|
||||
foreach(var t in oc)
|
||||
((INotifyPropertyChanged)t).PropertyChanged += (o, eventArgs) => RefreshList();
|
||||
}
|
||||
|
||||
if (!(collection is ObservableCollection<T>))
|
||||
{
|
||||
@@ -130,34 +121,6 @@ namespace Torch.Views
|
||||
{
|
||||
ElementList.Items.Refresh();
|
||||
}
|
||||
|
||||
private void TopButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var i = ElementList.SelectedItems[0];
|
||||
ElementList.Items.Remove(i);
|
||||
ElementList.Items.Insert(0, i);
|
||||
}
|
||||
private void BottomButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var i = ElementList.SelectedItems[0];
|
||||
ElementList.Items.Remove(i);
|
||||
ElementList.Items.Add(i);
|
||||
}
|
||||
private void UpButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var i = ElementList.SelectedItems[0];
|
||||
var idx = ElementList.SelectedItems.IndexOf(i);
|
||||
ElementList.Items.Remove(i);
|
||||
ElementList.Items.Insert(Math.Max(0, idx), i);
|
||||
}
|
||||
private void DownButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var i = ElementList.SelectedItems[0];
|
||||
var idx = ElementList.SelectedItems.IndexOf(i);
|
||||
ElementList.Items.Remove(i);
|
||||
var mx = ElementList.Items.Count - 1;
|
||||
ElementList.Items.Insert(Math.Min(idx, mx), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user