Browse Source

Flat Collection Editor

pull/58/head
jkuehner 12 years ago
parent
commit
3332f96d72
  1. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs
  2. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/CollectionEditor.xaml.cs
  3. 30
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml
  4. 121
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs
  5. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs

@ -57,6 +57,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -57,6 +57,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
_menu.AddSubMenuInTheHeader(new MenuItem() {Header = "Edit Items"});
}
if(view is Grid) {
_menu.AddSubMenuInTheHeader(new MenuItem() {Header = "Edit Rows"});
_menu.AddSubMenuInTheHeader(new MenuItem() {Header = "Edit Columns"});
}
if (view is StackPanel) {
var ch = new MenuItem() {Header = "Change Orientation"};
_menu.AddSubMenuInTheHeader(ch);
@ -108,6 +113,22 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -108,6 +113,22 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
editor.Show();
}
if((string)clickedOn.Header=="Edit Rows") {
var editor = new FlatCollectionEditor();
var gd=this.ExtendedItem.View as Grid;
if (gd != null)
editor.LoadItemsCollection(this.ExtendedItem.Properties["RowDefinitions"]);
editor.Show();
}
if((string)clickedOn.Header=="Edit Columns") {
var editor = new FlatCollectionEditor();
var gd=this.ExtendedItem.View as Grid;
if (gd != null)
editor.LoadItemsCollection(this.ExtendedItem.Properties["ColumnDefinitions"]);
editor.Show();
}
if (parent.Header is string && (string) parent.Header == "Change Orientation") {
var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
if (value != null) {

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/CollectionEditor.xaml.cs

@ -27,8 +27,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors @@ -27,8 +27,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
TypeMappings.Add(typeof(ComboBox),typeof(ComboBoxItem));
TypeMappings.Add(typeof(TreeView),typeof(TreeViewItem));
TypeMappings.Add(typeof(TabControl),typeof(TabItem));
TypeMappings.Add(typeof(ColumnDefinitionCollection),typeof(ColumnDefinition));
TypeMappings.Add(typeof(RowDefinitionCollection),typeof(RowDefinition));
}
private DesignItem _item;
@ -37,6 +35,8 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors @@ -37,6 +35,8 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
public CollectionEditor()
{
InitializeComponent();
this.Owner = Application.Current.MainWindow;
}
public void LoadItemsCollection(DesignItem item)

30
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
<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">
<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>

121
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs

@ -0,0 +1,121 @@ @@ -0,0 +1,121 @@
// 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.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);
refreshList();
}
private void OnRemoveItemClicked(object sender, RoutedEventArgs e)
{
var selItem = ListBox.SelectedItem as DesignItem;
if (selItem != null)
_itemProperty.CollectionElements.Remove(selItem);
refreshList();
}
void refreshList()
{
ListBox.ItemsSource = null;
ListBox.ItemsSource = _itemProperty.CollectionElements;
ListBox.Items.Refresh();
}
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>();
}
}
}

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

@ -81,6 +81,10 @@ @@ -81,6 +81,10 @@
</Compile>
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Extensions\RenderTransformOriginExtension.cs" />
<Compile Include="PropertyGrid\Editors\FlatCollectionEditor.xaml.cs">
<DependentUpon>FlatCollectionEditor.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Translations.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Controls\AdornerLayer.cs" />
@ -238,6 +242,7 @@ @@ -238,6 +242,7 @@
<Resource Include="Images\Tag.png" />
</ItemGroup>
<ItemGroup>
<Page Include="PropertyGrid\Editors\FlatCollectionEditor.xaml" />
<Page Include="ThumbnailView\ThumbnailView.xaml" />
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>

Loading…
Cancel
Save