Browse Source

Open Collection Editor from PropertyGrid for Properties which implement ICollection

(Resources, Children, Items, ...)
pull/449/head
jkuehner 12 years ago
parent
commit
5a181c135f
  1. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs
  2. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BoolEditor.xaml
  3. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FlatCollectionEditor.xaml.cs
  4. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml
  5. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml.cs
  6. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  7. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/EditorManager.cs
  8. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs

@ -163,6 +163,8 @@ namespace ICSharpCode.WpfDesign.Designer @@ -163,6 +163,8 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.AddPopularProperty(typeof(Binding), "ElementName");
Metadata.AddPopularProperty(typeof(Binding), "Converter");
Metadata.AddPopularProperty(typeof(Binding), "XPath");
Metadata.AddPopularProperty(typeof(ItemsControl), "Items");
Metadata.AddValueRange(Block.LineHeightProperty, double.Epsilon, double.MaxValue);
Metadata.AddValueRange(Canvas.BottomProperty, double.MinValue, double.MaxValue);
@ -219,7 +221,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -219,7 +221,7 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.HideProperty(typeof(UIElement), "RenderSize");
Metadata.HideProperty(FrameworkElement.NameProperty);
Metadata.HideProperty(typeof(FrameworkElement), "Resources");
//Metadata.HideProperty(typeof(FrameworkElement), "Resources");
Metadata.HideProperty(typeof(Window), "Owner");
//Metadata.DisablePlacement(typeof(Button));

1
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BoolEditor.xaml

@ -3,5 +3,6 @@ @@ -3,5 +3,6 @@
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
IsChecked="{Binding Value}"
Focusable="False"
>
</CheckBox>

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

@ -57,18 +57,28 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors @@ -57,18 +57,28 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
this.Owner = Application.Current.MainWindow;
}
public Type GetItemsSourceType(Type t)
{
Type tp = t.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(ICollection<>));
return (tp != null ) ? tp.GetGenericArguments()[0] : null;
}
public void LoadItemsCollection(DesignItemProperty itemProperty)
{
_itemProperty = itemProperty;
_componentService=_itemProperty.DesignItem.Services.Component;
TypeMappings.TryGetValue(_itemProperty.ReturnType, out _type);
_type = _type ?? GetItemsSourceType(_itemProperty.ReturnType);
if (_type == null) {
PropertyGridView.IsEnabled=false;
ListBox.IsEnabled=false;
//PropertyGridView.IsEnabled=false;
//ListBox.IsEnabled=false;
AddItem.IsEnabled=false;
RemoveItem.IsEnabled=false;
MoveUpItem.IsEnabled=false;
MoveDownItem.IsEnabled=false;
//RemoveItem.IsEnabled=false;
//MoveUpItem.IsEnabled=false;
//MoveDownItem.IsEnabled=false;
}
ListBox.ItemsSource = _itemProperty.CollectionElements;

17
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<UserControl
x:Class="ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.OpenCollectionEditor" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TextBlock
Margin="0,0,20,0"
Text="{Binding Value}" VerticalAlignment="Center" />
<Button
Width="15"
Margin="0,0,1,0"
HorizontalAlignment="Right"
VerticalAlignment="Stretch"
Content="..."
Focusable="False"
Click="open_Click" />
</Grid>
</UserControl>

38
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/OpenCollectionEditor.xaml.cs

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
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.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.PropertyGrid;
//using Xceed.Wpf.Toolkit;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
{
[TypeEditor(typeof(ICollection))]
public partial class OpenCollectionEditor : UserControl
{
public OpenCollectionEditor()
{
InitializeComponent();
}
void open_Click(object sender, RoutedEventArgs e)
{
var node = this.DataContext as PropertyNode;
var editor = new FlatCollectionEditor();
editor.LoadItemsCollection(node.FirstProperty);
editor.ShowDialog();
}
}
}

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

@ -93,6 +93,9 @@ @@ -93,6 +93,9 @@
<DependentUpon>FlatCollectionEditor.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="PropertyGrid\Editors\OpenCollectionEditor.xaml.cs">
<DependentUpon>OpenCollectionEditor.xaml</DependentUpon>
</Compile>
<Compile Include="Translations.cs" />
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Controls\AdornerLayer.cs" />
@ -252,6 +255,7 @@ @@ -252,6 +255,7 @@
<ItemGroup>
<Page Include="Extensions\RightClickContextMenu.xaml" />
<Page Include="PropertyGrid\Editors\FlatCollectionEditor.xaml" />
<Page Include="PropertyGrid\Editors\OpenCollectionEditor.xaml" />
<Page Include="ThumbnailView\ThumbnailView.xaml" />
<ProjectReference Include="..\..\..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/EditorManager.cs

@ -51,6 +51,13 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -51,6 +51,13 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
}
type = type.BaseType;
}
foreach (var t in typeEditors) {
if (t.Key.IsAssignableFrom(property.ReturnType)) {
return (FrameworkElement)Activator.CreateInstance(t.Value);
}
}
if (editorType == null) {
var standardValues = Metadata.GetStandardValues(property.ReturnType);
if (standardValues != null) {

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyGrid/TypeHelper.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -93,7 +94,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -93,7 +94,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(element))
{
if (!p.IsBrowsable) continue;
if (p.IsReadOnly) continue;
if (p.IsReadOnly && !typeof(ICollection).IsAssignableFrom(p.PropertyType)) continue;
if (hiddenPropertiesOnWindow.Contains(p.Name)) continue;
if (p.Attributes.OfType<ObsoleteAttribute>().Count() != 0) continue;
yield return p;
@ -103,7 +104,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid @@ -103,7 +104,7 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
{
foreach(PropertyDescriptor p in TypeDescriptor.GetProperties(element)){
if (!p.IsBrowsable) continue;
if (p.IsReadOnly) continue;
if (p.IsReadOnly && !typeof(ICollection).IsAssignableFrom(p.PropertyType)) continue;
if (p.Attributes.OfType<ObsoleteAttribute>().Count()!=0) continue;
yield return p;
}

Loading…
Cancel
Save