7 changed files with 248 additions and 5 deletions
@ -0,0 +1,85 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<Window |
||||||
|
x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FlatCollectionEditor" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:OutlineView="clr-namespace:ICSharpCode.WpfDesign.Designer.OutlineView" xmlns:PropertyGrid="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid" |
||||||
|
Height="438" |
||||||
|
Width="750" |
||||||
|
Title="Edit Items" |
||||||
|
WindowStartupLocation="CenterScreen" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||||
|
mc:Ignorable="d"> |
||||||
|
<Grid> |
||||||
|
<Grid.ColumnDefinitions> |
||||||
|
<ColumnDefinition |
||||||
|
Width="3*" /> |
||||||
|
<ColumnDefinition |
||||||
|
Width="100" /> |
||||||
|
<ColumnDefinition |
||||||
|
Width="4*" /> |
||||||
|
</Grid.ColumnDefinitions> |
||||||
|
<Border |
||||||
|
BorderBrush="Black" |
||||||
|
BorderThickness="0.75" |
||||||
|
Margin="10" |
||||||
|
SnapsToDevicePixels="True"> |
||||||
|
<ListBox |
||||||
|
x:Name="ListBox" |
||||||
|
SelectionChanged="ListBox_SelectionChanged"> |
||||||
|
<ListBox.ItemTemplate> |
||||||
|
<DataTemplate> |
||||||
|
<TextBlock |
||||||
|
Text="{Binding ComponentType.Name}" /> |
||||||
|
</DataTemplate> |
||||||
|
</ListBox.ItemTemplate> |
||||||
|
</ListBox> |
||||||
|
</Border> |
||||||
|
<Button |
||||||
|
Content="Add" |
||||||
|
Click="OnAddItemClicked" |
||||||
|
Grid.Column="1" |
||||||
|
Height="23" |
||||||
|
HorizontalAlignment="Left" |
||||||
|
Margin="0,12,0,0" |
||||||
|
Name="AddItem" |
||||||
|
VerticalAlignment="Top" |
||||||
|
Width="75" /> |
||||||
|
<Button |
||||||
|
Content="Remove" |
||||||
|
Click="OnRemoveItemClicked" |
||||||
|
Grid.Column="1" |
||||||
|
Height="23" |
||||||
|
HorizontalAlignment="Left" |
||||||
|
Margin="0,42,0,0" |
||||||
|
Name="RemoveItem" |
||||||
|
VerticalAlignment="Top" |
||||||
|
Width="75" /> |
||||||
|
<Button |
||||||
|
Content="Move Up" |
||||||
|
Click="OnMoveItemUpClicked" |
||||||
|
Grid.Column="1" |
||||||
|
Height="23" |
||||||
|
HorizontalAlignment="Left" |
||||||
|
Margin="0,72,0,0" |
||||||
|
Name="MoveUpItem" |
||||||
|
VerticalAlignment="Top" |
||||||
|
Width="75" /> |
||||||
|
<Button |
||||||
|
Content="Move Down" |
||||||
|
Click="OnMoveItemDownClicked" |
||||||
|
Grid.Column="1" |
||||||
|
Height="23" |
||||||
|
HorizontalAlignment="Left" |
||||||
|
Margin="0,102,0,0" |
||||||
|
Name="MoveDownItem" |
||||||
|
VerticalAlignment="Top" |
||||||
|
Width="75" /> |
||||||
|
<Border |
||||||
|
BorderBrush="Black" |
||||||
|
BorderThickness="0.75" |
||||||
|
Margin="10" |
||||||
|
Grid.Column="2" |
||||||
|
SnapsToDevicePixels="True"> |
||||||
|
<PropertyGrid:PropertyGridView |
||||||
|
x:Name="PropertyGridView" |
||||||
|
Margin="0.5" /> |
||||||
|
</Border> |
||||||
|
</Grid> |
||||||
|
</Window> |
||||||
@ -0,0 +1,111 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Diagnostics; |
||||||
|
using System.Text; |
||||||
|
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.Linq; |
||||||
|
using ICSharpCode.WpfDesign.Designer.OutlineView; |
||||||
|
|
||||||
|
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors |
||||||
|
{ |
||||||
|
public partial class FlatCollectionEditor : Window |
||||||
|
{ |
||||||
|
private static readonly Dictionary<Type, Type> TypeMappings = new Dictionary<Type, Type>(); |
||||||
|
static FlatCollectionEditor() |
||||||
|
{ |
||||||
|
TypeMappings.Add(typeof(ListBox),typeof(ListBoxItem)); |
||||||
|
TypeMappings.Add(typeof(ListView),typeof(ListViewItem)); |
||||||
|
TypeMappings.Add(typeof(ComboBox),typeof(ComboBoxItem)); |
||||||
|
TypeMappings.Add(typeof(TabControl),typeof(TabItem)); |
||||||
|
TypeMappings.Add(typeof(ColumnDefinitionCollection),typeof(ColumnDefinition)); |
||||||
|
TypeMappings.Add(typeof(RowDefinitionCollection),typeof(RowDefinition)); |
||||||
|
} |
||||||
|
|
||||||
|
private DesignItemProperty _itemProperty; |
||||||
|
private IComponentService _componentService; |
||||||
|
private Type _type; |
||||||
|
|
||||||
|
public FlatCollectionEditor() |
||||||
|
{ |
||||||
|
InitializeComponent(); |
||||||
|
|
||||||
|
this.Owner = Application.Current.MainWindow; |
||||||
|
} |
||||||
|
|
||||||
|
public void LoadItemsCollection(DesignItemProperty itemProperty) |
||||||
|
{ |
||||||
|
_itemProperty = itemProperty; |
||||||
|
_componentService=_itemProperty.DesignItem.Services.Component; |
||||||
|
TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type); |
||||||
|
if (_type == null) { |
||||||
|
PropertyGridView.IsEnabled=false; |
||||||
|
ListBox.IsEnabled=false; |
||||||
|
AddItem.IsEnabled=false; |
||||||
|
RemoveItem.IsEnabled=false; |
||||||
|
MoveUpItem.IsEnabled=false; |
||||||
|
MoveDownItem.IsEnabled=false; |
||||||
|
} |
||||||
|
|
||||||
|
ListBox.ItemsSource = _itemProperty.CollectionElements; |
||||||
|
} |
||||||
|
|
||||||
|
private void OnAddItemClicked(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type)); |
||||||
|
_itemProperty.CollectionElements.Add(newItem); |
||||||
|
} |
||||||
|
|
||||||
|
private void OnRemoveItemClicked(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
var selItem = ListBox.SelectedItem as DesignItem; |
||||||
|
if (selItem != null) |
||||||
|
_itemProperty.CollectionElements.Remove(selItem); |
||||||
|
} |
||||||
|
|
||||||
|
private void OnMoveItemUpClicked(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
DesignItem selectedItem = ListBox.SelectedItem as DesignItem; |
||||||
|
if (selectedItem!=null) { |
||||||
|
if(_itemProperty.CollectionElements.Count!=1 && _itemProperty.CollectionElements.IndexOf(selectedItem)!=0){ |
||||||
|
int moveToIndex=_itemProperty.CollectionElements.IndexOf(selectedItem)-1; |
||||||
|
var itemAtMoveToIndex=_itemProperty.CollectionElements[moveToIndex]; |
||||||
|
_itemProperty.CollectionElements.RemoveAt(moveToIndex); |
||||||
|
if ((moveToIndex + 1) < (_itemProperty.CollectionElements.Count+1)) |
||||||
|
_itemProperty.CollectionElements.Insert(moveToIndex+1,itemAtMoveToIndex); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void OnMoveItemDownClicked(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
DesignItem selectedItem = ListBox.SelectedItem as DesignItem; |
||||||
|
if (selectedItem!=null) { |
||||||
|
var itemCount=_itemProperty.CollectionElements.Count; |
||||||
|
if(itemCount!=1 && _itemProperty.CollectionElements.IndexOf(selectedItem)!=itemCount){ |
||||||
|
int moveToIndex=_itemProperty.CollectionElements.IndexOf(selectedItem)+1; |
||||||
|
if(moveToIndex<itemCount){ |
||||||
|
var itemAtMoveToIndex=_itemProperty.CollectionElements[moveToIndex]; |
||||||
|
_itemProperty.CollectionElements.RemoveAt(moveToIndex); |
||||||
|
if(moveToIndex>0) |
||||||
|
_itemProperty.CollectionElements.Insert(moveToIndex-1,itemAtMoveToIndex); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) |
||||||
|
{ |
||||||
|
PropertyGridView.PropertyGrid.SelectedItems = ListBox.SelectedItems.Cast<DesignItem>(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue