bugfixes when content property is used in property mode
This commit is contained in:
Родитель
d07893f2ad
Коммит
9b17211b1a
|
@ -24,7 +24,7 @@ using ICSharpCode.WpfDesign.Extensions;
|
|||
namespace ICSharpCode.WpfDesign.Designer.Extensions
|
||||
{
|
||||
[ExtensionServer(typeof(PrimarySelectionExtensionServer))]
|
||||
[ExtensionFor(typeof (UIElement))]
|
||||
[ExtensionFor(typeof(object))]
|
||||
[Extension(Order = 10)]
|
||||
public class DefaultCommandsContextMenuExtension : SelectionAdornerProvider
|
||||
{
|
||||
|
|
|
@ -101,11 +101,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
|
|||
|
||||
public virtual void LeaveContainer(PlacementOperation operation)
|
||||
{
|
||||
if (ExtendedItem.ContentProperty.IsCollection) {
|
||||
foreach (var info in operation.PlacedItems) {
|
||||
if (ExtendedItem.ContentProperty.IsCollection)
|
||||
{
|
||||
foreach (var info in operation.PlacedItems)
|
||||
{
|
||||
ExtendedItem.ContentProperty.CollectionElements.Remove(info.Item);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtendedItem.ContentProperty.Reset();
|
||||
}
|
||||
}
|
||||
|
@ -133,9 +137,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
|
|||
|
||||
if (ExtendedItem.Component is Expander)
|
||||
{
|
||||
if (!((Expander) ExtendedItem.Component).IsExpanded)
|
||||
if (!((Expander)ExtendedItem.Component).IsExpanded)
|
||||
{
|
||||
((Expander) ExtendedItem.Component).IsExpanded = true;
|
||||
((Expander)ExtendedItem.Component).IsExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,15 +166,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
|
|||
|
||||
public virtual void EnterContainer(PlacementOperation operation)
|
||||
{
|
||||
if (ExtendedItem.ContentProperty.IsCollection) {
|
||||
foreach (var info in operation.PlacedItems) {
|
||||
if (ExtendedItem.ContentProperty.IsCollection)
|
||||
{
|
||||
foreach (var info in operation.PlacedItems)
|
||||
{
|
||||
ExtendedItem.ContentProperty.CollectionElements.Add(info.Item);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ExtendedItem.ContentProperty.SetValue(operation.PlacedItems[0].Item);
|
||||
}
|
||||
if (operation.Type == PlacementType.AddItem) {
|
||||
foreach (var info in operation.PlacedItems) {
|
||||
if (operation.Type == PlacementType.AddItem)
|
||||
{
|
||||
foreach (var info in operation.PlacedItems)
|
||||
{
|
||||
SetPosition(info);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ICSharpCode.WpfDesign.Extensions;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows;
|
||||
using ICSharpCode.WpfDesign.Designer.Controls;
|
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.Extensions
|
||||
{
|
||||
[ExtensionFor(typeof(object))]
|
||||
public class OnlyDeletePlacementBehavior : BehaviorExtension, IPlacementBehavior
|
||||
{
|
||||
static OnlyDeletePlacementBehavior()
|
||||
{ }
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
if (ExtendedItem.Component is Panel || ExtendedItem.Component is Control || ExtendedItem.Component is Border || ExtendedItem.Component is Viewbox)
|
||||
return;
|
||||
|
||||
ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this);
|
||||
}
|
||||
|
||||
public virtual bool CanPlace(IEnumerable<DesignItem> childItems, PlacementType type, PlacementAlignment position)
|
||||
{
|
||||
return type == PlacementType.Delete;
|
||||
}
|
||||
|
||||
public virtual void BeginPlacement(PlacementOperation operation)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void EndPlacement(PlacementOperation operation)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)
|
||||
{
|
||||
return new Rect();
|
||||
}
|
||||
|
||||
public Rect GetPositionRelativeToContainer(PlacementOperation operation, DesignItem item)
|
||||
{
|
||||
return new Rect();
|
||||
}
|
||||
|
||||
public virtual void BeforeSetPosition(PlacementOperation operation)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool CanPlaceItem(PlacementInformation info)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void SetPosition(PlacementInformation info)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual bool CanLeaveContainer(PlacementOperation operation)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void LeaveContainer(PlacementOperation operation)
|
||||
{
|
||||
foreach (var item in operation.PlacedItems) {
|
||||
if (item.Item.ParentProperty.IsCollection) {
|
||||
item.Item.ParentProperty.CollectionElements.Remove(item.Item);
|
||||
}
|
||||
else {
|
||||
item.Item.ParentProperty.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static InfoTextEnterArea infoTextEnterArea;
|
||||
|
||||
public virtual bool CanEnterContainer(PlacementOperation operation, bool shouldAlwaysEnter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual void EnterContainer(PlacementOperation operation)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual Point PlacePoint(Point point)
|
||||
{
|
||||
return new Point();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls">
|
||||
|
||||
<UserControl.Resources>
|
||||
|
||||
<Style TargetType="ToggleButton" x:Key="eyeStyle">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
|
@ -73,8 +72,8 @@
|
|||
<HierarchicalDataTemplate DataType="{x:Type Default:OutlineNode}"
|
||||
ItemsSource="{Binding Children}">
|
||||
<DockPanel>
|
||||
<ToggleButton Style="{StaticResource lockedStyle}" DockPanel.Dock="Right" Width="20" Margin="0,0,5,0" IsChecked="{Binding IsDesignTimeLocked}" />
|
||||
<ToggleButton Style="{StaticResource eyeStyle}" DockPanel.Dock="Right" Width="20" Margin="0,0,5,0" IsChecked="{Binding IsDesignTimeVisible}" />
|
||||
<ToggleButton Visibility="{Binding IsVisualNode}" Style="{StaticResource lockedStyle}" DockPanel.Dock="Right" Width="20" Margin="0,0,5,0" IsChecked="{Binding IsDesignTimeLocked}" />
|
||||
<ToggleButton Visibility="{Binding IsVisualNode}" Style="{StaticResource eyeStyle}" DockPanel.Dock="Right" Width="20" Margin="0,0,5,0" IsChecked="{Binding IsDesignTimeVisible}" />
|
||||
<Default:IconItem Icon="../Images/Tag.png" Text="{Binding Name}" />
|
||||
</DockPanel>
|
||||
</HierarchicalDataTemplate>
|
||||
|
|
|
@ -20,6 +20,9 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ICSharpCode.WpfDesign.Designer.OutlineView
|
||||
{
|
||||
|
@ -64,7 +67,8 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
|
|||
Children.Clear();
|
||||
|
||||
foreach (var prp in DesignItem.AllSetProperties) {
|
||||
if (prp.Name != DesignItem.ContentPropertyName) {
|
||||
if (prp.Name != DesignItem.ContentPropertyName)
|
||||
{
|
||||
if (prp.Value != null) {
|
||||
var propertyNode = PropertyOutlineNode.Create(prp.Name);
|
||||
var node = OutlineNode.Create(prp.Value);
|
||||
|
@ -79,7 +83,12 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
|
|||
UpdateChildrenCore(content.CollectionElements);
|
||||
} else {
|
||||
if (content.Value != null) {
|
||||
UpdateChildrenCore(new[] { content.Value });
|
||||
if (!UpdateChildrenCore(new[] {content.Value})) {
|
||||
var propertyNode = PropertyOutlineNode.Create(content.Name);
|
||||
var node = OutlineNode.Create(content.Value);
|
||||
propertyNode.Children.Add(node);
|
||||
Children.Add(propertyNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,30 +108,39 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
|
|||
}
|
||||
}
|
||||
|
||||
void UpdateChildrenCore(IEnumerable<DesignItem> items, int index = -1)
|
||||
bool UpdateChildrenCore(IEnumerable<DesignItem> items, int index = -1)
|
||||
{
|
||||
var retVal = false;
|
||||
foreach (var item in items) {
|
||||
if (ModelTools.CanSelectComponent(item)) {
|
||||
if (Children.All(x => x.DesignItem != item)) {
|
||||
var node = OutlineNode.Create(item);
|
||||
if (index>-1)
|
||||
if (index > -1) {
|
||||
Children.Insert(index++, node);
|
||||
else
|
||||
retVal = true;
|
||||
}
|
||||
else {
|
||||
Children.Add(node);
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var content = item.ContentProperty;
|
||||
if (content != null) {
|
||||
if (content.IsCollection) {
|
||||
UpdateChildrenCore(content.CollectionElements);
|
||||
retVal = true;
|
||||
} else {
|
||||
if (content.Value != null) {
|
||||
UpdateChildrenCore(new[] { content.Value });
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ using System.Collections.ObjectModel;
|
|||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using ICSharpCode.WpfDesign.Designer.Xaml;
|
||||
using ICSharpCode.WpfDesign.XamlDom;
|
||||
|
||||
|
@ -41,6 +43,11 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
|
|||
|
||||
private string _name;
|
||||
|
||||
public Visibility IsVisualNode
|
||||
{
|
||||
get { return this.DesignItem.Component is Visual ? Visibility.Visible : Visibility.Collapsed; }
|
||||
}
|
||||
|
||||
protected OutlineNodeBase(DesignItem designItem)
|
||||
{
|
||||
DesignItem = designItem;
|
||||
|
@ -197,12 +204,12 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
|
|||
|
||||
void DesignItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == DesignItem.ContentPropertyName) {
|
||||
//if (e.PropertyName == DesignItem.ContentPropertyName) {
|
||||
if (!_collectionWasChanged) {
|
||||
UpdateChildren();
|
||||
}
|
||||
_collectionWasChanged = false;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
private void CollectionElements_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
|
@ -211,8 +218,6 @@ namespace ICSharpCode.WpfDesign.Designer.OutlineView
|
|||
UpdateChildrenCollectionChanged(e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool CanInsert(IEnumerable<IOutlineNode> nodes, IOutlineNode after, bool copy)
|
||||
{
|
||||
var placementBehavior = DesignItem.GetBehavior<IPlacementBehavior>();
|
||||
|
|
|
@ -113,15 +113,6 @@
|
|||
</Border>
|
||||
</Grid>
|
||||
<ItemsPresenter x:Name="itemsHost" />
|
||||
<!-- <DockPanel.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Command="ApplicationCommands.Cut" />
|
||||
<MenuItem Command="ApplicationCommands.Copy" />
|
||||
<MenuItem Command="ApplicationCommands.Paste" />
|
||||
<Separator />
|
||||
<MenuItem Command="ApplicationCommands.Delete" />
|
||||
</ContextMenu>
|
||||
</DockPanel.ContextMenu>-->
|
||||
<DockPanel.ToolTip>
|
||||
<ToolTip Background="White">
|
||||
<Rectangle Width="50" Height="50">
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
<Link>GlobalAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Extensions\BorderForMouseOver.cs" />
|
||||
<Compile Include="Extensions\OnlyDeletePlacementBehavior.cs" />
|
||||
<Compile Include="OutlineView\PropertyOutlineNode.cs" />
|
||||
<Compile Include="PropertyGrid\Editors\ColorEditor\ColorEditorPopup.xaml.cs">
|
||||
<DependentUpon>ColorEditorPopup.xaml</DependentUpon>
|
||||
|
|
|
@ -125,7 +125,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
|
|||
/// <param name="item"></param>
|
||||
/// <param name="onlyFromSameNamescope"></param>
|
||||
/// <returns></returns>
|
||||
private XamlObject GetRootXamlObject(XamlObject item, bool onlyFromSameNamescope = false)
|
||||
internal static XamlObject GetRootXamlObject(XamlObject item, bool onlyFromSameNamescope = false)
|
||||
{
|
||||
var root = item;
|
||||
while (root.ParentObject != null)
|
||||
|
@ -144,7 +144,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
|
|||
/// <param name="item"></param>
|
||||
/// <param name="onlyFromSameNamescope"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<XamlObject> GetAllChildXamlObjects(XamlObject item, bool onlyFromSameNamescope = false)
|
||||
internal static IEnumerable<XamlObject> GetAllChildXamlObjects(XamlObject item, bool onlyFromSameNamescope = false)
|
||||
{
|
||||
foreach (var prop in item.Properties)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче