Browse Source

Merge pull request #58 from jogibear9988/master

Flat Collection editor for Grid ColumnDefinitions/RowDefinitions
pull/61/merge
Siegfried Oleg Pammer 12 years ago
parent
commit
60c043c1d6
  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. 85
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml
  4. 111
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs
  5. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  6. 16
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs
  7. 11
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelPropertyCollection.cs

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)

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

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

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

@ -0,0 +1,111 @@ @@ -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>();
}
}
}

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>

16
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs

@ -7,15 +7,18 @@ using System.Collections.Generic; @@ -7,15 +7,18 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using ICSharpCode.WpfDesign.XamlDom;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Collections.Specialized;
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
sealed class XamlModelCollectionElementsCollection : IList<DesignItem>
sealed class XamlModelCollectionElementsCollection : IList<DesignItem>, INotifyCollectionChanged
{
readonly XamlModelProperty modelProperty;
readonly XamlProperty property;
readonly XamlDesignContext context;
public event NotifyCollectionChangedEventHandler CollectionChanged;
public XamlModelCollectionElementsCollection(XamlModelProperty modelProperty, XamlProperty property)
{
this.modelProperty = modelProperty;
@ -45,6 +48,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -45,6 +48,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
while (this.Count > 0) {
RemoveAt(this.Count - 1);
}
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public bool Contains(DesignItem item)
@ -77,7 +83,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -77,7 +83,9 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
int index = IndexOf(item);
if (index < 0)
return false;
RemoveAt(index);
return true;
}
@ -151,11 +159,17 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -151,11 +159,17 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
{
Debug.Assert(property.CollectionElements[index] == item.XamlObject);
property.CollectionElements.RemoveAt(index);
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
}
void InsertInternal(int index, XamlDesignItem item)
{
property.CollectionElements.Insert(index, item.XamlObject);
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
}
sealed class InsertAction : ITransactionItem

11
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelPropertyCollection.cs

@ -4,22 +4,29 @@ @@ -4,22 +4,29 @@
using System;
using System.Windows;
using ICSharpCode.WpfDesign.XamlDom;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
sealed class XamlModelPropertyCollection : DesignItemPropertyCollection
{
XamlDesignItem _item;
Dictionary<string, XamlModelProperty> propertiesDictionary = new Dictionary<string, XamlModelProperty>();
public XamlModelPropertyCollection(XamlDesignItem item)
{
this._item = item;
}
public override DesignItemProperty GetProperty(string name)
{
return new XamlModelProperty(_item, _item.XamlObject.FindOrCreateProperty(name));
XamlModelProperty property;
if (propertiesDictionary.TryGetValue(name, out property))
return property;
property = new XamlModelProperty(_item, _item.XamlObject.FindOrCreateProperty(name));
propertiesDictionary.Add(name, property);
return property;
}
public override DesignItemProperty GetAttachedProperty(Type ownerType, string name)

Loading…
Cancel
Save