Browse Source

Merge pull request #692 from jogibear9988/master

Multiple fixes for WpfDesigner
pull/716/head
Siegfried Pammer 10 years ago
parent
commit
f88ae80e23
  1. 30
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/UserControlPointsObjectThumb.cs
  2. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  3. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  4. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  5. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  6. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs
  7. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs
  8. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs
  9. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs
  10. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs
  11. 245
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/UserControlPointsObjectExtension.cs
  12. 69
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs
  13. 89
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  14. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  15. 13
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
  16. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs
  17. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs
  18. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs
  19. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelPropertyCollection.cs
  20. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs
  21. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  22. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  23. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs
  24. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

30
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/UserControlPointsObjectThumb.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// 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 ICSharpCode.WpfDesign.UIExtensions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
public class UserControlPointsObjectThumb : DesignerThumb
{
public DependencyProperty DependencyProperty { get; set; }
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -219,6 +219,8 @@ namespace ICSharpCode.WpfDesign.Designer @@ -219,6 +219,8 @@ namespace ICSharpCode.WpfDesign.Designer
#region Properties
public DesignSurface DesignSurface { get; internal set; }
//Set custom HitTestFilterCallbak
public HitTestFilterCallback CustomHitTestFilterBehavior { get; set; }

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -76,14 +76,13 @@ namespace ICSharpCode.WpfDesign.Designer @@ -76,14 +76,13 @@ namespace ICSharpCode.WpfDesign.Designer
this.AddCommandHandler(Commands.AlignCenterCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.AlignRightCommand, () => ModelTools.ArrangeItems(this.DesignContext.Services.Selection.SelectedItems, ArrangeDirection.Right), () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
//Todo
//this.AddCommandHandler(Commands.RotateLeftCommand, () => , () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
//this.AddCommandHandler(Commands.RotateRightCommand, () => , () => this.DesignContext.Services.Selection.SelectedItems.Count() > 1);
this.AddCommandHandler(Commands.RotateLeftCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(-90)), () => this.DesignContext.Services.Selection.PrimarySelection != null);
this.AddCommandHandler(Commands.RotateRightCommand, () => ModelTools.ApplyTransform(this.DesignContext.Services.Selection.PrimarySelection, new RotateTransform(90)), () => this.DesignContext.Services.Selection.PrimarySelection != null);
_sceneContainer = new Border() { AllowDrop = false, UseLayoutRounding = true };
_sceneContainer.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Ideal);
_designPanel = new DesignPanel() {Child = _sceneContainer};
_designPanel = new DesignPanel() {Child = _sceneContainer, DesignSurface = this};
}
internal DesignPanel _designPanel;

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

@ -147,6 +147,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -147,6 +147,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
info.Item.Properties[FrameworkElement.HorizontalAlignmentProperty].Reset();
info.Item.Properties[FrameworkElement.VerticalAlignmentProperty].Reset();
info.Item.Properties[FrameworkElement.MarginProperty].Reset();
if (operation.Type == PlacementType.PasteItem) {
info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(((double)info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance) + PlacementOperation.PasteOffset);
info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(((double)info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance) + PlacementOperation.PasteOffset);
}
}
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

@ -63,8 +63,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -63,8 +63,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
InfoTextEnterArea.Stop(ref infoTextEnterArea);
this.ExtendedItem.Services.Selection.SetSelectedComponents(null);
this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList());
if (operation.Type != PlacementType.Delete)
{
this.ExtendedItem.Services.Selection.SetSelectedComponents(null);
this.ExtendedItem.Services.Selection.SetSelectedComponents(operation.PlacedItems.Select(x => x.Item).ToList());
}
}
public virtual Rect GetPosition(PlacementOperation operation, DesignItem item)

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs

@ -162,6 +162,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -162,6 +162,26 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
enteredIntoNewContainer=true;
grid.UpdateLayout();
base.EnterContainer(operation);
if (operation.Type == PlacementType.PasteItem) {
foreach (PlacementInformation info in operation.PlacedItems) {
var margin = (Thickness)info.Item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance;
var horizontalAlignment = (HorizontalAlignment)info.Item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance;
var verticalAlignment = (VerticalAlignment)info.Item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance;
if (horizontalAlignment == HorizontalAlignment.Left)
margin.Left += PlacementOperation.PasteOffset;
else if (horizontalAlignment == HorizontalAlignment.Right)
margin.Right -= PlacementOperation.PasteOffset;
if (verticalAlignment == VerticalAlignment.Top)
margin.Top += PlacementOperation.PasteOffset;
else if (verticalAlignment == VerticalAlignment.Bottom)
margin.Bottom -= PlacementOperation.PasteOffset;
info.Item.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(margin);
}
}
}
GrayOutDesignerExceptActiveArea grayOut;

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs

@ -107,7 +107,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -107,7 +107,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <param name="alignment"></param>
/// <param name="index">if using a polygon or multipoint adorner this is the index of the point in the Points array</param>
/// <returns></returns>
protected PointTrackerPlacementSupport Place(ref DesignerThumb designerThumb, PlacementAlignment alignment, int index = -1)
protected PointTrackerPlacementSupport Place(DesignerThumb designerThumb, PlacementAlignment alignment, int index = -1)
{
PointTrackerPlacementSupport placement = new PointTrackerPlacementSupport(ExtendedItem.View as Shape, alignment, index);
return placement;

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -56,7 +56,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor)
{
DesignerThumb designerThumb = new DesignerThumb { Alignment = alignment, Cursor = cursor, IsPrimarySelection = true};
AdornerPanel.SetPlacement(designerThumb, Place(ref designerThumb, alignment));
AdornerPanel.SetPlacement(designerThumb, Place(designerThumb, alignment));
adornerPanel.Children.Add(designerThumb);

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -49,7 +49,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index)
{
DesignerThumb designerThumb = new MultiPointThumb { Index = index, Alignment = alignment, Cursor = cursor, IsPrimarySelection = true };
AdornerPlacement ap = Place(ref designerThumb, alignment, index);
AdornerPlacement ap = Place(designerThumb, alignment, index);
(designerThumb as MultiPointThumb).AdornerPlacement = ap;
AdornerPanel.SetPlacement(designerThumb, ap);

32
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
@ -116,29 +117,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -116,29 +117,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
if (!Keyboard.IsKeyDown(Key.LeftCtrl))
destAngle = ((int)destAngle / 15) * 15;
if (destAngle == 0)
{
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Reset();
rtTransform = null;
rotateTransform = null;
}
else
{
if ((rtTransform == null) || !(rtTransform.Component is RotateTransform))
{
if (!this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).IsSet) {
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5,0.5));
}
if (this.rotateTransform == null)
this.rotateTransform = new RotateTransform(0);
this.ExtendedItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(rotateTransform);
rtTransform = this.ExtendedItem.Properties[FrameworkElement.RenderTransformProperty].Value;
}
rtTransform.Properties["Angle"].SetValue(destAngle);
((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true);
}
ModelTools.ApplyTransform(this.ExtendedItem, new RotateTransform() { Angle = destAngle });
}
void drag_Rotate_Completed(ICSharpCode.WpfDesign.Designer.Controls.DragListener drag)
@ -161,6 +140,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -161,6 +140,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var designerItem = this.ExtendedItem.Component as FrameworkElement;
this.rotateTransform = designerItem.RenderTransform as RotateTransform;
if (this.rotateTransform == null) {
var tg = designerItem.RenderTransform as TransformGroup;
if (tg != null) {
this.rotateTransform = tg.Children.FirstOrDefault(x => x is RotateTransform) as RotateTransform;
}
}
}
void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)

245
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/UserControlPointsObjectExtension.cs

@ -0,0 +1,245 @@ @@ -0,0 +1,245 @@
// 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;
using System.Collections.Generic;
using System.Windows;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// Description of UserControlPointsObjectExtension.
/// </summary>
//[ExtensionFor(typeof(Line), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(SelectedElementRectangleExtension), typeof(CanvasPositionExtension), typeof(QuickOperationMenuExtension), typeof(RotateThumbExtension), typeof(RenderTransformOriginExtension), typeof(InPlaceEditorExtension), typeof(SkewThumbExtension) })]
public abstract class UserControlPointsObjectExtension : LineExtensionBase
{
/// <summary>
/// Used instead of Rect to allow negative values on "Width" and "Height" (here called X and Y).
/// </summary>
class Bounds
{
public double X, Y, Left, Top;
}
//
private double CurrentX2;
private double CurrentY2;
private double CurrentLeft;
private double CurrentTop;
private IEnumerable<DependencyProperty> _thumbProperties;
//Size oldSize;
ZoomControl zoom;
public DragListener DragListener {get; private set;}
protected UserControlPointsObjectThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, DependencyProperty property)
{
var designerThumb = new UserControlPointsObjectThumb { Alignment = alignment, Cursor = cursor, IsPrimarySelection = true, DependencyProperty = property};
AdornerPanel.SetPlacement(designerThumb, Place(designerThumb, alignment));
adornerPanel.Children.Add(designerThumb);
DragListener = new DragListener(designerThumb);
DragListener.Started += drag_Started;
DragListener.Changed += drag_Changed;
DragListener.Completed += drag_Completed;
return designerThumb;
}
Bounds CalculateDrawing(double x, double y, double left, double top, double xleft, double xtop)
{
Double theta = (180 / Math.PI) * Math.Atan2(y, x);
double verticaloffset = Math.Abs(90 - Math.Abs(theta));
if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
{
if (Math.Abs(theta) < 45 || Math.Abs(theta) > 135)
{
y = 0;
top = xtop;
}
else if (verticaloffset < 45)
{
x = 0;
left = xleft;
}
}
else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
{
if (verticaloffset < 10)
{
x = 0;
left = xleft;
}
else if (Math.Abs(theta) < 10 || Math.Abs(theta) > 170)
{
y = 0;
top = xtop;
}
}
SetSurfaceInfo(0, 3, Math.Round((180 / Math.PI) * Math.Atan2(y, x), 0).ToString());
return new Bounds { X = Math.Round(x, 1), Y = Math.Round(y, 1), Left = Math.Round(left, 1), Top = Math.Round(top, 1) };
}
#region eventhandlers
protected virtual void drag_Started(DragListener drag)
{
Line al = ExtendedItem.View as Line;
CurrentX2 = al.X2;
CurrentY2 = al.Y2;
CurrentLeft = (double)al.GetValue(Canvas.LeftProperty);
CurrentTop = (double)al.GetValue(Canvas.TopProperty);
var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
zoom = designPanel.TryFindParent<ZoomControl>();
if (resizeBehavior != null)
operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
else
{
changeGroup = this.ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
}
_isResizing = true;
(drag.Target as UserControlPointsObjectThumb).IsPrimarySelection = false;
}
protected virtual void drag_Changed(DragListener drag)
{
Line al = ExtendedItem.View as Line;
var alignment = (drag.Target as UserControlPointsObjectThumb).Alignment;
var info = operation.PlacedItems[0];
double dx = 0;
double dy = 0;
if (zoom != null) {
dx = drag.Delta.X * (1 / zoom.CurrentZoom);
dy = drag.Delta.Y * (1 / zoom.CurrentZoom);
}
double top, left, x, y, xtop, xleft;
if (alignment == PlacementAlignment.TopLeft) {
//normal values
x = CurrentX2 - dx;
y = CurrentY2 - dy;
top = CurrentTop + dy;
left = CurrentLeft + dx;
//values to use when keys are pressed
xtop = CurrentTop + CurrentY2;
xleft = CurrentLeft + CurrentX2;
} else {
x = CurrentX2 + dx;
y = CurrentY2 + dy;
top = xtop = CurrentTop;
left = xleft = CurrentLeft;
}
Bounds position = CalculateDrawing(x, y, left, top, xleft, xtop);
ExtendedItem.Properties.GetProperty(Line.X1Property).SetValue(0);
ExtendedItem.Properties.GetProperty(Line.Y1Property).SetValue(0);
ExtendedItem.Properties.GetProperty(Line.X2Property).SetValue(position.X);
ExtendedItem.Properties.GetProperty(Line.Y2Property).SetValue(position.Y);
if (operation != null) {
var result = info.OriginalBounds;
result.X = position.Left;
result.Y = position.Top;
result.Width = Math.Abs(position.X);
result.Height = Math.Abs(position.Y);
info.Bounds = result.Round();
operation.CurrentContainerBehavior.BeforeSetPosition(operation);
operation.CurrentContainerBehavior.SetPosition(info);
}
(drag.Target as UserControlPointsObjectThumb).InvalidateArrange();
ResetWidthHeightProperties();
}
protected virtual void drag_Completed(DragListener drag)
{
if (operation != null)
{
if (drag.IsCanceled) operation.Abort();
else
{
ResetWidthHeightProperties();
operation.Commit();
}
operation = null;
}
else
{
if (drag.IsCanceled)
changeGroup.Abort();
else
changeGroup.Commit();
changeGroup = null;
}
_isResizing = false;
(drag.Target as UserControlPointsObjectThumb).IsPrimarySelection = true;
HideSizeAndShowHandles();
}
#endregion
/// <summary>
/// is invoked whenever a line is selected on the canvas, remember that the adorners are created for each line object and never destroyed
/// </summary>
protected override void OnInitialized()
{
base.OnInitialized();
FillThumbProperties();
foreach (var prp in _thumbProperties) {
CreateThumb(PlacementAlignment.Center, Cursors.Cross, prp);
}
extendedItemArray[0] = this.ExtendedItem;
Invalidate();
this.ExtendedItem.PropertyChanged += OnPropertyChanged;
resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
UpdateAdornerVisibility();
}
protected abstract IEnumerable<DependencyProperty> FillThumbProperties();
}
}

69
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs

@ -43,6 +43,12 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions @@ -43,6 +43,12 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions
public bool SingleItemProperty { get; set; }
public bool AskWhenMultipleItemsSelected { get; set; }
public IValueConverter Converter { get; set; }
public object ConverterParameter { get; set; }
public UpdateSourceTrigger UpdateSourceTrigger { get; set; }
public DesignItemBinding(string path)
@ -50,6 +56,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions @@ -50,6 +56,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions
this._propertyName = path;
UpdateSourceTrigger = UpdateSourceTrigger.Default;
AskWhenMultipleItemsSelected = true;
}
public override object ProvideValue(IServiceProvider serviceProvider)
@ -63,22 +70,44 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions @@ -63,22 +70,44 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions
return null;
}
public void CreateBindingOnProperty(DependencyProperty targetProperty, FrameworkElement targetObject)
{
_targetProperty = targetProperty;
_targetObject = targetObject;
_targetObject.DataContextChanged += targetObject_DataContextChanged;
targetObject_DataContextChanged(_targetObject, new DependencyPropertyChangedEventArgs());
}
void targetObject_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var ctx = ((FrameworkElement) sender).DataContext as FrameworkElement;
var surface = ctx.TryFindParent<DesignSurface>();
var dcontext = ((FrameworkElement) sender).DataContext;
DesignContext context = null;
FrameworkElement fe = null;
DesignItem designItem = null;
if (dcontext is DesignItem) {
designItem = (DesignItem)dcontext;
context = designItem.Context;
fe = designItem.View as FrameworkElement;
} else if (dcontext is FrameworkElement) {
fe = ((FrameworkElement)dcontext);
var srv = fe.TryFindParent<DesignSurface>();
if (srv != null) {
context = srv.DesignContext;
designItem = context.Services.Component.GetDesignItem(fe);
}
}
if (surface != null)
if (context != null)
{
_binding = new Binding(_propertyName);
_binding.Source = ctx;
_binding.Source = fe;
_binding.UpdateSourceTrigger = UpdateSourceTrigger;
_binding.Mode = BindingMode.TwoWay;
_binding.ConverterParameter = ConverterParameter;
var designItem = surface.DesignContext.Services.Component.GetDesignItem(ctx);
_converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty);
_converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty, AskWhenMultipleItemsSelected, Converter);
_binding.Converter = _converter;
_targetObject.SetBinding(_targetProperty, _binding);
@ -94,33 +123,47 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions @@ -94,33 +123,47 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions
private DesignItem _designItem;
private string _property;
private bool _singleItemProperty;
private bool _askWhenMultipleItemsSelected;
private IValueConverter _converter;
public DesignItemSetConverter(DesignItem desigItem, string property, bool singleItemProperty)
public DesignItemSetConverter(DesignItem desigItem, string property, bool singleItemProperty, bool askWhenMultipleItemsSelected, IValueConverter converter)
{
this._designItem = desigItem;
this._property = property;
this._singleItemProperty = singleItemProperty;
this._converter = converter;
this._askWhenMultipleItemsSelected = askWhenMultipleItemsSelected;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (_converter != null)
return _converter.Convert(value, targetType, parameter, culture);
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var val = value;
if (_converter != null)
val = _converter.ConvertBack(value, targetType, parameter, culture);
var changeGroup = _designItem.OpenGroup("Property: " + _property);
try
{
var property = _designItem.Properties.GetProperty(_property);
property.SetValue(value);
property.SetValue(val);
if (!_singleItemProperty && _designItem.Services.Selection.SelectedItems.Count > 1)
{
var msg = MessageBox.Show("Apply changes to all selected Items","", MessageBoxButton.YesNo);
var msg = MessageBoxResult.Yes;
if (_askWhenMultipleItemsSelected) {
msg = MessageBox.Show("Apply changes to all selected Items","", MessageBoxButton.YesNo);
}
if (msg == MessageBoxResult.Yes)
{
foreach (var item in _designItem.Services.Selection.SelectedItems)
@ -132,7 +175,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions @@ -132,7 +175,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions
catch(Exception)
{ }
if (property != null)
property.SetValue(value);
property.SetValue(val);
}
}
}
@ -144,7 +187,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions @@ -144,7 +187,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions
changeGroup.Abort();
}
return value;
return val;
}
}
}

89
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs

@ -113,6 +113,12 @@ namespace ICSharpCode.WpfDesign.Designer @@ -113,6 +113,12 @@ namespace ICSharpCode.WpfDesign.Designer
foreach (var designItem in items) {
designItem.Name = null;
}
var service = parent.Services.Component as XamlComponentService;
foreach (var item in items) {
service.RaiseComponentRemoved(item);
}
operation.DeleteItemsAndCommit();
} catch {
operation.Abort();
@ -344,6 +350,89 @@ namespace ICSharpCode.WpfDesign.Designer @@ -344,6 +350,89 @@ namespace ICSharpCode.WpfDesign.Designer
return new Tuple<DesignItem, Rect>(newPanel, new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round());
}
public static void ApplyTransform(DesignItem designItem, Transform transform, bool relative = true)
{
var changeGroup = designItem.OpenGroup("Apply Transform");
Transform oldTransform = null;
if (designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).IsSet) {
oldTransform = designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).ValueOnInstance as Transform;
}
if (oldTransform is MatrixTransform) {
var mt = oldTransform as MatrixTransform;
var tg = new TransformGroup();
if (mt.Matrix.OffsetX != 0 && mt.Matrix.OffsetY != 0)
tg.Children.Add(new TranslateTransform(){ X = mt.Matrix.OffsetX, Y = mt.Matrix.OffsetY });
if (mt.Matrix.M11 != 0 && mt.Matrix.M22 != 0)
tg.Children.Add(new ScaleTransform(){ ScaleX = mt.Matrix.M11, ScaleY = mt.Matrix.M22 });
var angle = Math.Atan2(mt.Matrix.M21, mt.Matrix.M11) * 180 / Math.PI;
if (angle != 0)
tg.Children.Add(new RotateTransform(){ Angle = angle });
//if (mt.Matrix.M11 != 0 && mt.Matrix.M22 != 0)
// tg.Children.Add(new SkewTransform(){ ScaleX = mt.Matrix.M11, ScaleY = mt.Matrix.M22 });
} else if (oldTransform != null && oldTransform.GetType() != transform.GetType()) {
var tg = new TransformGroup();
var tgDes = designItem.Services.Component.RegisterComponentForDesigner(tg);
tgDes.ContentProperty.CollectionElements.Add(designItem.Services.Component.GetDesignItem(oldTransform));
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(tg);
oldTransform = tg;
}
if (transform is RotateTransform) {
var rotateTransform = transform as RotateTransform;
if (oldTransform is RotateTransform || oldTransform == null) {
if (rotateTransform.Angle != 0) {
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
var angle = rotateTransform.Angle;
if (relative && oldTransform != null) {
angle = rotateTransform.Angle + ((RotateTransform)oldTransform).Angle;
}
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.AngleProperty).SetValue(angle);
if (rotateTransform.CenterX != 0.0)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterXProperty).SetValue(rotateTransform.CenterX);
if (rotateTransform.CenterY != 0.0)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterYProperty).SetValue(rotateTransform.CenterY);
if (oldTransform == null)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
}
else {
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Reset();
designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).Reset();
}
} else if (oldTransform is TransformGroup) {
var tg = oldTransform as TransformGroup;
var rot = tg.Children.FirstOrDefault(x=> x is RotateTransform);
if (rot != null) {
designItem.Services.Component.GetDesignItem(tg).ContentProperty.CollectionElements.Remove(designItem.Services.Component.GetDesignItem(rot));
}
if (rotateTransform.Angle != 0) {
var des = designItem.Services.Component.GetDesignItem(transform);
if (des == null)
des = designItem.Services.Component.RegisterComponentForDesigner(transform);
designItem.Services.Component.GetDesignItem(tg).ContentProperty.CollectionElements.Add(des);
if (oldTransform == null)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
}
} else {
if (rotateTransform.Angle != 0) {
designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
if (oldTransform == null)
designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
}
}
}
((DesignPanel) designItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(designItem.View, true);
changeGroup.Commit();
}
public static void ArrangeItems(IEnumerable<DesignItem> items, ArrangeDirection arrangeDirection)
{

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

@ -88,6 +88,7 @@ @@ -88,6 +88,7 @@
</Compile>
<Compile Include="ArrangeDirection.cs" />
<Compile Include="Commands.cs" />
<Compile Include="Controls\Thumbs\UserControlPointsObjectThumb.cs" />
<Compile Include="Controls\NullableComboBox.cs" />
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Controls\Thumbs\PointThumb.cs" />
@ -131,6 +132,7 @@ @@ -131,6 +132,7 @@
<Compile Include="Extensions\ArrangeItemsContextMenu.xaml.cs">
<DependentUpon>ArrangeItemsContextMenu.xaml</DependentUpon>
</Compile>
<Compile Include="Extensions\UserControlPointsObjectExtension.cs" />
<Compile Include="Extensions\WrapItemContextMenu.xaml.cs">
<DependentUpon>WrapItemContextMenu.xaml</DependentUpon>
</Compile>

13
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs

@ -56,6 +56,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -56,6 +56,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public event EventHandler<DesignItemEventArgs> ComponentRegistered;
public event EventHandler<DesignItemEventArgs> ComponentRemoved;
// TODO: this must not be a dictionary because there's no way to unregister components
// however, this isn't critical because our design items will stay alive for the lifetime of the
// designer anyway if we don't limit the Undo stack.
@ -164,5 +166,16 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -164,5 +166,16 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
ev(this, new DesignItemPropertyChangedEventArgs(property.DesignItem, property));
}
}
/// <summary>
/// raises the RaiseComponentRemoved Event
/// </summary>
internal void RaiseComponentRemoved(DesignItem item)
{
var ev = this.ComponentRemoved;
if (ev != null) {
ev(this, new DesignItemEventArgs(item));
}
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlDesignItem.cs

@ -260,6 +260,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -260,6 +260,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
get { return _properties; }
}
public override IEnumerable<DesignItemProperty> AllSetProperties {
get { return _xamlObject.Properties.Select(x => new XamlModelProperty(this, x)); }
}
internal void NotifyPropertyChanged(XamlModelProperty property)
{
Debug.Assert(property != null);

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs

@ -179,7 +179,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -179,7 +179,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
var operation = PlacementOperation.TryStartInsertNewComponents(parent, pastedItems, rects.ToList(), PlacementType.PasteItem);
ISelectionService selection = _context.Services.Selection;
selection.SetSelectedComponents(pastedItems);
if(operation!=null)
if(operation != null)
operation.Commit();
}
}

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

@ -180,7 +180,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -180,7 +180,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
void RemoveInternal(int index, XamlDesignItem item)
{
NameScopeHelper.NameChanged(item.XamlObject, item.Name, null);
RemoveFromNamescopeRecursive(item);
Debug.Assert(property.CollectionElements[index] == item.XamlObject);
property.CollectionElements.RemoveAt(index);
@ -196,7 +196,41 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -196,7 +196,41 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index));
NameScopeHelper.NameChanged(item.XamlObject, null, item.Name);
AddToNamescopeRecursive(item);
}
private static void RemoveFromNamescopeRecursive(XamlDesignItem designItem)
{
NameScopeHelper.NameChanged(designItem.XamlObject, designItem.Name, null);
foreach (var p in designItem.Properties)
{
if (p.Value != null) {
RemoveFromNamescopeRecursive((XamlDesignItem)p.Value);
}
else if (p.IsCollection && p.CollectionElements != null) {
foreach (var c in p.CollectionElements) {
RemoveFromNamescopeRecursive((XamlDesignItem)c);
}
}
}
}
private static void AddToNamescopeRecursive(XamlDesignItem designItem)
{
NameScopeHelper.NameChanged(designItem.XamlObject, null, designItem.Name);
foreach (var p in designItem.Properties)
{
if (p.Value != null) {
AddToNamescopeRecursive((XamlDesignItem)p.Value);
}
else if (p.IsCollection && p.CollectionElements != null) {
foreach (var c in p.CollectionElements) {
AddToNamescopeRecursive((XamlDesignItem)c);
}
}
}
}
sealed class InsertAction : ITransactionItem

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

@ -24,6 +24,8 @@ using System.Collections.Generic; @@ -24,6 +24,8 @@ using System.Collections.Generic;
namespace ICSharpCode.WpfDesign.Designer.Xaml
{
using System.Linq;
sealed class XamlModelPropertyCollection : DesignItemPropertyCollection
{
XamlDesignItem _item;
@ -51,7 +53,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -51,7 +53,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
public override System.Collections.Generic.IEnumerator<DesignItemProperty> GetEnumerator()
{
yield break;
foreach (var value in propertiesDictionary.Values)
{
yield return value;
}
}
}
}

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs

@ -254,7 +254,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -254,7 +254,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
xamlContext.XamlEditAction.Paste();
string expectedXaml = "<Button />\n" +
"<sdtcontrols:CustomButton>\n" +
"<sdtcontrols:CustomButton Margin=\"0,0,0,0\">\n" +
" <sdtcontrols:CustomButton.Tag>\n" +
" <Controls0:MyExtension>\n" +
" <Controls0:MyExtension.MyProperty1>\n" +
@ -315,6 +315,13 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -315,6 +315,13 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
selection.SetSelectedComponents(new[] {grid});
xamlContext.XamlEditAction.Paste();
// Verify xaml document to be copied
expectedXaml = "<Grid.Resources>\n" +
" <Controls0:ExampleClass x:Key=\"res1\" />\n" +
"</Grid.Resources>\n" +
"<Button />\n" +
"<sdtcontrols:CustomButton Tag=\"{StaticResource res1}\" Margin=\"0,0,0,0\" />\n";
AssertGridDesignerOutput(expectedXaml, grid.Context,
"xmlns:Controls0=\"clr-namespace:ICSharpCode.WpfDesign.Tests.Designer;assembly=ICSharpCode.WpfDesign.Tests\"",
"xmlns:sdtcontrols=\"http://sharpdevelop.net/WpfDesign/Tests/Controls\"");

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -248,8 +248,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -248,8 +248,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
try {
ValueOnInstance = PropertyValue.GetValueFor(propertyInfo);
if (this.parentObject.XamlSetTypeConverter != null)
if (this.parentObject.XamlSetTypeConverter != null && propertyValue is XamlTextValue) {
this.ParentObject.XamlSetTypeConverter(this.parentObject.Instance, new XamlSetTypeConverterEventArgs(this.SystemXamlMemberForProperty, null, ((XamlTextValue) propertyValue).Text, this.parentObject.OwnerDocument.GetTypeDescriptorContext(this.parentObject), null));
}
if (propertyInfo.DependencyProperty == DesignTimeProperties.DesignWidthProperty) {
var widthProperty = this.ParentObject.Properties.FirstOrDefault(x => x.DependencyProperty == FrameworkElement.WidthProperty);

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs

@ -78,6 +78,11 @@ namespace ICSharpCode.WpfDesign @@ -78,6 +78,11 @@ namespace ICSharpCode.WpfDesign
/// </summary>
public abstract DesignItemPropertyCollection Properties { get; }
/// <summary>
/// Gets properties set on the design item.
/// </summary>
public abstract IEnumerable<DesignItemProperty> AllSetProperties { get; }
/// <summary>
/// Gets/Sets the name of the design item.
/// </summary>

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs

@ -38,6 +38,8 @@ namespace ICSharpCode.WpfDesign @@ -38,6 +38,8 @@ namespace ICSharpCode.WpfDesign
IPlacementBehavior currentContainerBehavior;
bool isAborted, isCommitted;
public const double PasteOffset = 10;
#region Properties
/// <summary>
/// The items being placed.
@ -294,6 +296,7 @@ namespace ICSharpCode.WpfDesign @@ -294,6 +296,7 @@ namespace ICSharpCode.WpfDesign
#endregion
#region ChangeGroup handling
/// <summary>
/// Gets/Sets the description of the underlying change group.
/// </summary>
@ -301,7 +304,7 @@ namespace ICSharpCode.WpfDesign @@ -301,7 +304,7 @@ namespace ICSharpCode.WpfDesign
get { return changeGroup.Title; }
set { changeGroup.Title = value; }
}
/// <summary>
/// Aborts the operation.
/// This aborts the underlying change group, reverting all changes done while the operation was running.

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

@ -127,6 +127,9 @@ namespace ICSharpCode.WpfDesign @@ -127,6 +127,9 @@ namespace ICSharpCode.WpfDesign
/// <summary>Event raised whenever a component is registered</summary>
event EventHandler<DesignItemEventArgs> ComponentRegistered;
/// <summary>Event raised whenever a component is removed</summary>
event EventHandler<DesignItemEventArgs> ComponentRemoved;
/// <summary>Property Changed</summary>
event EventHandler<DesignItemPropertyChangedEventArgs> PropertyChanged;

Loading…
Cancel
Save