Browse Source

Add collection editor for editing Menu, TreeView, ListBox, ComboBox items

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6374 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Kumar Devvrat 15 years ago
parent
commit
a851d04ff9
  1. 36
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs
  2. 24
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/CollectionEditor.xaml
  3. 130
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/CollectionEditor.xaml.cs
  4. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

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

@ -11,6 +11,7 @@ using System.Windows.Input; @@ -11,6 +11,7 @@ using System.Windows.Input;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
@ -33,13 +34,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -33,13 +34,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var kbs = this.ExtendedItem.Services.GetService(typeof (IKeyBindingService)) as IKeyBindingService;
var command = new DesignCommand(delegate
{
_menu.MainHeader.IsSubmenuOpen = true;
_menu.MainHeader.Focus();
}, delegate
{
return true;
});
{
_menu.MainHeader.IsSubmenuOpen = true;
_menu.MainHeader.Focus();
}, delegate
{
return true;
});
_keyBinding=new KeyBinding(command, Key.Enter, ModifierKeys.Alt);
if (kbs != null)
kbs.RegisterBinding(_keyBinding);
@ -55,6 +56,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -55,6 +56,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (view != null) {
string setValue;
if(view is ItemsControl) {
_menu.AddSubMenuInTheHeader(new MenuItem() {Header = "Edit Items"});
}
if (view is StackPanel) {
var ch = new MenuItem() {Header = "Change Orientation"};
_menu.AddSubMenuInTheHeader(ch);
@ -97,7 +102,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -97,7 +102,16 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (clickedOn != null) {
var parent = clickedOn.Parent as MenuItem;
if (parent != null) {
if ((string) parent.Header == "Change Orientation") {
if((string)clickedOn.Header=="Edit Items") {
var editor = new CollectionEditor();
var itemsControl=this.ExtendedItem.View as ItemsControl;
if (itemsControl != null)
editor.LoadItemsCollection(this.ExtendedItem);
editor.Show();
}
if (parent.Header is string && (string) parent.Header == "Change Orientation") {
var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
if (value != null) {
var orientation = Enum.Parse(typeof (Orientation), value);
@ -105,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -105,7 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
this.ExtendedItem.Properties[StackPanel.OrientationProperty].SetValue(orientation);
}
}
if ((string)parent.Header == "Set Dock to") {
if (parent.Header is string && (string)parent.Header == "Set Dock to") {
var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
if(value!=null) {
var dock = Enum.Parse(typeof (Dock), value);
@ -115,7 +129,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -115,7 +129,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
if ((string) parent.Header == "Horizontal Alignment") {
if (parent.Header is string && (string) parent.Header == "Horizontal Alignment") {
var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
if (value != null) {
var ha = Enum.Parse(typeof (HorizontalAlignment), value);
@ -124,7 +138,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -124,7 +138,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
if ((string) parent.Header == "Vertical Alignment") {
if (parent.Header is string && (string) parent.Header == "Vertical Alignment") {
var value = _menu.UncheckChildrenAndSelectClicked(parent, clickedOn);
if (value != null) {
var va = Enum.Parse(typeof (VerticalAlignment), value);

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

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
<Window x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.CollectionEditor"
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">
<OutlineView:Outline x:Name="Outline" />
</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>

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

@ -0,0 +1,130 @@ @@ -0,0 +1,130 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Kumar Devvrat"/>
// <version>$Revision: $</version>
// </file>
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 ICSharpCode.WpfDesign.Designer.OutlineView;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
{
public partial class CollectionEditor : Window
{
private static readonly Dictionary<Type, Type> TypeMappings = new Dictionary<Type, Type>();
static CollectionEditor()
{
TypeMappings.Add(typeof(Menu), typeof(MenuItem));
TypeMappings.Add(typeof(ListBox),typeof(ListBoxItem));
TypeMappings.Add(typeof(ListView),typeof(ListViewItem));
TypeMappings.Add(typeof(ComboBox),typeof(ComboBoxItem));
TypeMappings.Add(typeof(TreeView),typeof(TreeViewItem));
}
private DesignItem _item;
private Type _type;
private IComponentService _componentService;
public CollectionEditor()
{
InitializeComponent();
}
public void LoadItemsCollection(DesignItem item)
{
Debug.Assert(item.View is ItemsControl);
_item=item;
_componentService=item.Services.Component;
item.Services.Selection.SelectionChanged+= delegate { PropertyGridView.SelectedItems=item.Services.Selection.SelectedItems; };
var control=item.View as ItemsControl;
if(control!=null){
TypeMappings.TryGetValue(control.GetType(), out _type);
if (_type != null) {
OutlineNode node = OutlineNode.Create(item);
Outline.Root = node;
PropertyGridView.PropertyGrid.SelectedItems = item.Services.Selection.SelectedItems;
}
else{
PropertyGridView.IsEnabled=false;
Outline.IsEnabled=false;
AddItem.IsEnabled=false;
RemoveItem.IsEnabled=false;
MoveUpItem.IsEnabled=false;
MoveDownItem.IsEnabled=false;
}
}
}
private void OnAddItemClicked(object sender, RoutedEventArgs e)
{
DesignItem newItem = _componentService.RegisterComponentForDesigner(Activator.CreateInstance(_type));
DesignItem selectedItem = _item.Services.Selection.PrimarySelection;
if(selectedItem.ContentProperty.IsCollection)
selectedItem.ContentProperty.CollectionElements.Add(newItem);
else
selectedItem.ContentProperty.SetValue(newItem);
_item.Services.Selection.SetSelectedComponents(new []{newItem});
}
private void OnRemoveItemClicked(object sender, RoutedEventArgs e)
{
DesignItem selectedItem = _item.Services.Selection.PrimarySelection;
DesignItem parent = selectedItem.Parent;
if(parent!=null && selectedItem!=_item){
if(parent.ContentProperty.IsCollection)
parent.ContentProperty.CollectionElements.Remove(selectedItem);
else
parent.ContentProperty.SetValue(null);
_item.Services.Selection.SetSelectedComponents(new[] {parent});
}
}
private void OnMoveItemUpClicked(object sender, RoutedEventArgs e)
{
DesignItem selectedItem = _item.Services.Selection.PrimarySelection;
DesignItem parent = selectedItem.Parent;
if(parent!=null && parent.ContentProperty.IsCollection){
if(parent.ContentProperty.CollectionElements.Count!=1 && parent.ContentProperty.CollectionElements.IndexOf(selectedItem)!=0){
int moveToIndex=parent.ContentProperty.CollectionElements.IndexOf(selectedItem)-1;
var itemAtMoveToIndex=parent.ContentProperty.CollectionElements[moveToIndex];
parent.ContentProperty.CollectionElements.RemoveAt(moveToIndex);
if ((moveToIndex + 1) < (parent.ContentProperty.CollectionElements.Count+1))
parent.ContentProperty.CollectionElements.Insert(moveToIndex+1,itemAtMoveToIndex);
}
}
}
private void OnMoveItemDownClicked(object sender, RoutedEventArgs e)
{
DesignItem selectedItem = _item.Services.Selection.PrimarySelection;
DesignItem parent = selectedItem.Parent;
if(parent!=null && parent.ContentProperty.IsCollection){
var itemCount=parent.ContentProperty.CollectionElements.Count;
if(itemCount!=1 && parent.ContentProperty.CollectionElements.IndexOf(selectedItem)!=itemCount){
int moveToIndex=parent.ContentProperty.CollectionElements.IndexOf(selectedItem)+1;
if(moveToIndex<itemCount){
var itemAtMoveToIndex=parent.ContentProperty.CollectionElements[moveToIndex];
parent.ContentProperty.CollectionElements.RemoveAt(moveToIndex);
if(moveToIndex>0)
parent.ContentProperty.CollectionElements.Insert(moveToIndex-1,itemAtMoveToIndex);
}
}
}
}
protected override void OnClosing(CancelEventArgs e)
{
_item.Services.Selection.SetSelectedComponents(new []{_item});
}
}
}

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

@ -180,6 +180,10 @@ @@ -180,6 +180,10 @@
<Compile Include="PropertyGrid\Editors\BrushEditor\SolidBrushEditor.xaml.cs">
<DependentUpon>SolidBrushEditor.xaml</DependentUpon>
</Compile>
<Compile Include="PropertyGrid\Editors\CollectionEditor.xaml.cs">
<DependentUpon>CollectionEditor.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="PropertyGrid\Editors\EventEditor.xaml.cs">
<DependentUpon>EventEditor.xaml</DependentUpon>
</Compile>
@ -294,6 +298,7 @@ @@ -294,6 +298,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="PropertyGrid\Editors\CollectionEditor.xaml" />
<Page Include="PropertyGrid\Editors\EventEditor.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

Loading…
Cancel
Save