From db2a41dcba9570fda28c43936240065d9dbe0567 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Fri, 10 Jul 2015 10:33:40 +0200 Subject: [PATCH 01/18] Fix Selection after Delete in WPF Designer --- .../Project/Extensions/DefaultPlacementBehavior.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs index 67f8743067..54cd207b2a 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs @@ -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) From 35b7b8e4636a97c28beec5d3566e1c4fbc8d255a Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Fri, 10 Jul 2015 11:29:11 +0200 Subject: [PATCH 02/18] Implement IEnumerable on XAML Properties --- .../Project/Xaml/XamlModelPropertyCollection.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelPropertyCollection.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelPropertyCollection.cs index 8c708bf69c..6264665627 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelPropertyCollection.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelPropertyCollection.cs @@ -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 public override System.Collections.Generic.IEnumerator GetEnumerator() { - yield break; + foreach (var value in propertiesDictionary.Values) + { + yield return value; + } } } } From 945af620752fc8bad8b50ad68a74896fd10449dc Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Sat, 11 Jul 2015 12:04:13 +0200 Subject: [PATCH 03/18] Better DesignItemBinding --- .../MarkupExtensions/DesignItemBinding.cs | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs index b0340d7379..0e9751f076 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs @@ -65,19 +65,30 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions void targetObject_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { - var ctx = ((FrameworkElement) sender).DataContext as FrameworkElement; - - var surface = ctx.TryFindParent(); + var dcontext = ((FrameworkElement) sender).DataContext; + + DesignContext context; + FrameworkElement fe; + DesignItem designItem; + + if (dcontext is DesignItem) { + designItem = (DesignItem)dcontext; + context = designItem.Context; + fe = designItem.View as FrameworkElement; + } else { + fe = ((FrameworkElement)dcontext); + var srv = fe.TryFindParent(); + 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; - var designItem = surface.DesignContext.Services.Component.GetDesignItem(ctx); - _converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty); _binding.Converter = _converter; From 10baef1e4d420c87deafa25ed419c64e847fe975 Mon Sep 17 00:00:00 2001 From: jogibear9988 Date: Sun, 12 Jul 2015 18:40:28 +0200 Subject: [PATCH 04/18] Fixes in DesignItemBinding! --- .../MarkupExtensions/DesignItemBinding.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs index 0e9751f076..1c8fa95518 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs @@ -63,23 +63,33 @@ 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 dcontext = ((FrameworkElement) sender).DataContext; - DesignContext context; - FrameworkElement fe; - DesignItem designItem; + 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 { + } else if (dcontext is FrameworkElement) { fe = ((FrameworkElement)dcontext); var srv = fe.TryFindParent(); - context = srv.DesignContext; - designItem = context.Services.Component.GetDesignItem(fe); + if (srv != null) { + context = srv.DesignContext; + designItem = context.Services.Component.GetDesignItem(fe); + } } if (context != null) From 94ff0eba9a4fb3b5f21f5b842ddbd07377c17d0f Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 14 Jul 2015 15:11:16 +0200 Subject: [PATCH 05/18] Rotate Left/Right Command --- .../Project/DesignSurface.cs | 5 +- .../Extensions/RotateThumbExtension.cs | 32 +++----- .../WpfDesign.Designer/Project/ModelTools.cs | 81 +++++++++++++++++++ 3 files changed, 92 insertions(+), 26 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs index b5e88ce221..4efa725ddb 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs @@ -76,9 +76,8 @@ 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); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs index 89b39c9aaa..f7e06b31be 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs @@ -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 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 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) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index 88bfe0a00b..7e1f6b3aa4 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -344,6 +344,87 @@ namespace ICSharpCode.WpfDesign.Designer return new Tuple(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); + designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterXProperty).SetValue(rotateTransform.CenterX); + 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 items, ArrangeDirection arrangeDirection) { From 8cf8bde1406d674fabe86c52849320919a673a43 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 14 Jul 2015 15:23:32 +0200 Subject: [PATCH 06/18] Apply CenterX,Y only when != 0 --- .../WpfDesign/WpfDesign.Designer/Project/ModelTools.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index 7e1f6b3aa4..bcf099aaad 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -388,8 +388,10 @@ namespace ICSharpCode.WpfDesign.Designer angle = rotateTransform.Angle + ((RotateTransform)oldTransform).Angle; } designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.AngleProperty).SetValue(angle); - designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterXProperty).SetValue(rotateTransform.CenterX); - designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterYProperty).SetValue(rotateTransform.CenterY); + 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)); From 55ef5ab75ad83f84287c41a92b3f314743e4a794 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 14 Jul 2015 15:56:02 +0200 Subject: [PATCH 07/18] Extend DesignItemBinding --- .../MarkupExtensions/DesignItemBinding.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs index 1c8fa95518..d3387cca30 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs @@ -43,6 +43,10 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions public bool SingleItemProperty { get; set; } + public IValueConverter Converter { get; set; } + + public object ConverterParameter { get; set; } + public UpdateSourceTrigger UpdateSourceTrigger { get; set; } public DesignItemBinding(string path) @@ -98,8 +102,9 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions _binding.Source = fe; _binding.UpdateSourceTrigger = UpdateSourceTrigger; _binding.Mode = BindingMode.TwoWay; + _binding.ConverterParameter = ConverterParameter; - _converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty); + _converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty, Converter); _binding.Converter = _converter; _targetObject.SetBinding(_targetProperty, _binding); @@ -115,28 +120,37 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions private DesignItem _designItem; private string _property; private bool _singleItemProperty; + private IValueConverter _converter; - public DesignItemSetConverter(DesignItem desigItem, string property, bool singleItemProperty) + public DesignItemSetConverter(DesignItem desigItem, string property, bool singleItemProperty, IValueConverter converter) { this._designItem = desigItem; this._property = property; this._singleItemProperty = singleItemProperty; + this._converter = converter; } 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) @@ -153,7 +167,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions catch(Exception) { } if (property != null) - property.SetValue(value); + property.SetValue(val); } } } @@ -165,7 +179,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions changeGroup.Abort(); } - return value; + return val; } } } From 0e49242b83365ad4a0afdbbfadd167fc39a1dad2 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Wed, 15 Jul 2015 14:57:41 +0200 Subject: [PATCH 08/18] Raise an Event when a Component is Removed --- .../WpfDesign.Designer/Project/ModelTools.cs | 6 ++++++ .../Project/Xaml/XamlComponentService.cs | 13 +++++++++++++ .../WpfDesign/Project/PlacementOperation.cs | 3 ++- .../WpfDesign/WpfDesign/Project/Services.cs | 3 +++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index bcf099aaad..0175a7c2cd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -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(); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs index 9998929502..53a6608478 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs @@ -56,6 +56,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml public event EventHandler ComponentRegistered; + public event EventHandler 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 ev(this, new DesignItemPropertyChangedEventArgs(property.DesignItem, property)); } } + + /// + /// raises the RaiseComponentRemoved Event + /// + internal void RaiseComponentRemoved(DesignItem item) + { + var ev = this.ComponentRemoved; + if (ev != null) { + ev(this, new DesignItemEventArgs(item)); + } + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs index dcd1080fbf..931b393c66 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs @@ -294,6 +294,7 @@ namespace ICSharpCode.WpfDesign #endregion #region ChangeGroup handling + /// /// Gets/Sets the description of the underlying change group. /// @@ -301,7 +302,7 @@ namespace ICSharpCode.WpfDesign get { return changeGroup.Title; } set { changeGroup.Title = value; } } - + /// /// Aborts the operation. /// This aborts the underlying change group, reverting all changes done while the operation was running. diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs index 61ed242246..dfd90f1b47 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs @@ -127,6 +127,9 @@ namespace ICSharpCode.WpfDesign /// Event raised whenever a component is registered event EventHandler ComponentRegistered; + /// Event raised whenever a component is removed + event EventHandler ComponentRemoved; + /// Property Changed event EventHandler PropertyChanged; From 1535c2df773d5081b70f6098af261fa5b1fecebe Mon Sep 17 00:00:00 2001 From: jkuehner Date: Wed, 15 Jul 2015 15:38:54 +0200 Subject: [PATCH 09/18] Fix Namescope Issue for Recursive Elements --- .../XamlModelCollectionElementsCollection.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs index 3a5766f11a..0824fe99ae 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlModelCollectionElementsCollection.cs @@ -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 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 From dd6404c3018bbcaeb794b6aff6d02f75c21b4a4b Mon Sep 17 00:00:00 2001 From: jkuehner Date: Thu, 16 Jul 2015 11:39:27 +0200 Subject: [PATCH 10/18] Move Inserted components by 10 Pixel --- .../Extensions/CanvasPlacementSupport.cs | 5 +++++ .../Extensions/GridPlacementSupport.cs | 20 +++++++++++++++++++ .../Project/Xaml/XamlEditOperations.cs | 2 +- .../WpfDesign/Project/PlacementOperation.cs | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs index 0f45fd9f4c..c8f4ce5760 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs @@ -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); + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs index cbd2ad1baa..e5a78cf63e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs @@ -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; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs index be2964d11a..96af34fa59 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlEditOperations.cs @@ -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(); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs index 931b393c66..4d9b70fa5e 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs @@ -38,6 +38,8 @@ namespace ICSharpCode.WpfDesign IPlacementBehavior currentContainerBehavior; bool isAborted, isCommitted; + public const double PasteOffset = 10; + #region Properties /// /// The items being placed. From d61cee604c595b1467a3211a39192d115749c767 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Thu, 16 Jul 2015 11:44:08 +0200 Subject: [PATCH 11/18] Fix unit Tests --- .../Tests/Designer/EditOperationTests.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs index 827ccd037c..5c816fe895 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/EditOperationTests.cs @@ -254,7 +254,7 @@ namespace ICSharpCode.WpfDesign.Tests.Designer xamlContext.XamlEditAction.Paste(); string expectedXaml = " public abstract DesignItemPropertyCollection Properties { get; } + /// + /// Gets properties set on the design item. + /// + public abstract IEnumerable AllSetProperties { get; } + /// /// Gets/Sets the name of the design item. /// From 0751c7fbd8669fe7b769797a3291ee8da4e34233 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Tue, 21 Jul 2015 13:53:33 +0200 Subject: [PATCH 14/18] Access DesignSurface from Panel! --- .../WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs | 2 ++ .../WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index d038b14dfb..5e932ffd44 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -219,6 +219,8 @@ namespace ICSharpCode.WpfDesign.Designer #region Properties + public DesignSurface DesignSurface { get; internal set; } + //Set custom HitTestFilterCallbak public HitTestFilterCallback CustomHitTestFilterBehavior { get; set; } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs index 4efa725ddb..382d0a1245 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs @@ -82,7 +82,7 @@ namespace ICSharpCode.WpfDesign.Designer _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; From 44187f5779498a62cbba7e6a9932875c93ef0070 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 3 Aug 2015 15:24:02 +0200 Subject: [PATCH 15/18] Work on a Extension for User Shape Types (wip) --- .../Thumbs/UserControlPointsObjectThumb.cs | 30 +++ .../Project/Extensions/LineExtensionBase.cs | 2 +- .../Extensions/LineHandlerExtension.cs | 2 +- .../Extensions/PolyLineHandlerExtension.cs | 2 +- .../UserControlPointsObjectExtension.cs | 245 ++++++++++++++++++ .../Project/WpfDesign.Designer.csproj | 2 + 6 files changed, 280 insertions(+), 3 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/UserControlPointsObjectThumb.cs create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/UserControlPointsObjectExtension.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/UserControlPointsObjectThumb.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/UserControlPointsObjectThumb.cs new file mode 100644 index 0000000000..18cb5735c0 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/UserControlPointsObjectThumb.cs @@ -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; } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs index 623bf53f2b..5d2b3214ea 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs @@ -107,7 +107,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// /// if using a polygon or multipoint adorner this is the index of the point in the Points array /// - 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; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs index 161b9a3236..30fdd856fd 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs @@ -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); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs index 0a8bd1ccdd..4817174750 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs @@ -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); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/UserControlPointsObjectExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/UserControlPointsObjectExtension.cs new file mode 100644 index 0000000000..dbf2388dfb --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/UserControlPointsObjectExtension.cs @@ -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 +{ + /// + /// Description of UserControlPointsObjectExtension. + /// + //[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 + { + /// + /// Used instead of Rect to allow negative values on "Width" and "Height" (here called X and Y). + /// + class Bounds + { + public double X, Y, Left, Top; + } + + // + private double CurrentX2; + private double CurrentY2; + private double CurrentLeft; + private double CurrentTop; + + private IEnumerable _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(); + + 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 + + /// + /// is invoked whenever a line is selected on the canvas, remember that the adorners are created for each line object and never destroyed + /// + 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 FillThumbProperties(); + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj index 73df4f6809..444bb3b156 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj @@ -88,6 +88,7 @@ + @@ -131,6 +132,7 @@ ArrangeItemsContextMenu.xaml + WrapItemContextMenu.xaml From 3e1bd350202ec40c24ddfa809b4e7c5a3507e600 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Fri, 4 Sep 2015 10:28:50 +0200 Subject: [PATCH 16/18] DesignItemBinding -> DisableAskOnChange --- .../Project/MarkupExtensions/DesignItemBinding.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs index d3387cca30..10279b816b 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/MarkupExtensions/DesignItemBinding.cs @@ -43,6 +43,8 @@ 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; } @@ -54,6 +56,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions this._propertyName = path; UpdateSourceTrigger = UpdateSourceTrigger.Default; + AskWhenMultipleItemsSelected = true; } public override object ProvideValue(IServiceProvider serviceProvider) @@ -104,7 +107,7 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions _binding.Mode = BindingMode.TwoWay; _binding.ConverterParameter = ConverterParameter; - _converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty, Converter); + _converter = new DesignItemSetConverter(designItem, _propertyName, SingleItemProperty, AskWhenMultipleItemsSelected, Converter); _binding.Converter = _converter; _targetObject.SetBinding(_targetProperty, _binding); @@ -120,14 +123,16 @@ 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, IValueConverter converter) + 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) @@ -155,7 +160,10 @@ namespace ICSharpCode.WpfDesign.Designer.MarkupExtensions 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) From 7b78ef6fadc4158ead3358a68cc483f93ca418b1 Mon Sep 17 00:00:00 2001 From: gumme Date: Mon, 7 Sep 2015 10:03:21 +0200 Subject: [PATCH 17/18] Fixed bug; If a Binding inside a MultiBinding is referencing a resource not available until the MultiBinding is added to the tree, the resource was not resolved. --- .../Tests/Designer/ModelTests.cs | 62 +++++++++++++++++++ .../WpfDesign.XamlDom/Project/XamlObject.cs | 13 +++- .../WpfDesign.XamlDom/Project/XamlProperty.cs | 9 +++ 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs index 82fd578baf..05a74a12da 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs @@ -895,6 +895,52 @@ namespace ICSharpCode.WpfDesign.Tests.Designer AssertLog(""); } + [Test] + public void AddBindingWithStaticResourceToMultiBinding() + { + DesignItem textBox = CreateCanvasContext(""); + + DesignItem canvasItem = textBox.Parent; + DesignItemProperty canvasResources = canvasItem.Properties.GetProperty("Resources"); + + DesignItem exampleClassItem = textBox.Services.Component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass()); + exampleClassItem.Key = "testKey"; + exampleClassItem.Properties["StringProp"].SetValue("String value"); + canvasResources.CollectionElements.Add(exampleClassItem); + + DesignItem multiBindingItem = textBox.Context.Services.Component.RegisterComponentForDesigner(new MultiBinding()); + multiBindingItem.Properties["Converter"].SetValue(new ReturnFirstValueMultiConverter()); + DesignItemProperty bindingsProp = multiBindingItem.ContentProperty; + + DesignItem myBindingExtension = textBox.Context.Services.Component.RegisterComponentForDesigner(new Binding()); + myBindingExtension.Properties["Path"].SetValue("StringProp"); + myBindingExtension.Properties["Source"].SetValue(new StaticResourceExtension()); + myBindingExtension.Properties["Source"].Value.Properties["ResourceKey"].SetValue("testKey"); + + // Adding it to MultiBinding "Bindings" collection. + bindingsProp.CollectionElements.Add(myBindingExtension); + + textBox.ContentProperty.SetValue(multiBindingItem); + + // Verify that the text have the expected value, proving that the StaticResource have been resolved. + Assert.AreEqual("String value", ((TextBox)textBox.Component).Text); + + const string expectedXaml = "\n" + + " \n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + AssertCanvasDesignerOutput(expectedXaml, textBox.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); + AssertLog(""); + } + [Test] public void AddBrushAsResource() { @@ -1024,6 +1070,22 @@ namespace ICSharpCode.WpfDesign.Tests.Designer } } + public class ReturnFirstValueMultiConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + if(values != null && values.Length > 0) { + return values[0]; + } else { + return System.Windows.DependencyProperty.UnsetValue; + } + } + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + } + public class ExampleClass { string stringProp; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs index 72e8f8b7be..5400bafaf3 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs @@ -283,8 +283,17 @@ namespace ICSharpCode.WpfDesign.XamlDom void UpdateChildMarkupExtensions(XamlObject obj) { - foreach (XamlObject propXamlObject in obj.Properties.Where((prop) => prop.IsSet).Select((prop) => prop.PropertyValue).OfType()) { - UpdateChildMarkupExtensions(propXamlObject); + foreach (var prop in obj.Properties) { + if (prop.IsSet) { + var propXamlObject = prop.PropertyValue as XamlObject; + if (propXamlObject != null) { + UpdateChildMarkupExtensions(propXamlObject); + } + } else if (prop.IsCollection) { + foreach (var propXamlObject in prop.CollectionElements.OfType()) { + UpdateChildMarkupExtensions(propXamlObject); + } + } } if (obj.IsMarkupExtension && obj.ParentProperty != null) { diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs index 093c418abb..9d40d15d25 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs @@ -266,6 +266,15 @@ namespace ICSharpCode.WpfDesign.XamlDom catch (Exception ex) { Debug.WriteLine("UpdateValueOnInstance() failed - Exception:" + ex.Message); } + } else if (IsCollection) { + var list = ValueOnInstance as System.Collections.IList; + if (list != null) { + list.Clear(); + foreach (var item in CollectionElements) { + var newValue = item.GetValueFor(propertyInfo); + list.Add(newValue); + } + } } } From 8a9884a6b99d33c694b04e403960354d1087d48e Mon Sep 17 00:00:00 2001 From: Andreas Weizel Date: Thu, 1 Oct 2015 21:48:37 +0200 Subject: [PATCH 18/18] Updated resources from RFT. --- data/resources/StringResources.it.resx | 3 +++ data/resources/StringResources.ru.resx | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/data/resources/StringResources.it.resx b/data/resources/StringResources.it.resx index cfd311c3e3..7743977f62 100644 --- a/data/resources/StringResources.it.resx +++ b/data/resources/StringResources.it.resx @@ -409,6 +409,9 @@ Smetteranno di funzionare dopo la rimozione di questo Componente! Sei sicuro di Mostra Diagramma delle Classi + + Pulisci console + Cancella cronologia diff --git a/data/resources/StringResources.ru.resx b/data/resources/StringResources.ru.resx index 789aa6575d..d2ff9e4dae 100644 --- a/data/resources/StringResources.ru.resx +++ b/data/resources/StringResources.ru.resx @@ -1,4 +1,4 @@ - +