Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6374 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
4 changed files with 184 additions and 11 deletions
@ -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> |
@ -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}); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue