From 78fe8ec6984e2fb8d06e60853a8ff4e50bace2e1 Mon Sep 17 00:00:00 2001 From: jkuehner Date: Mon, 28 Apr 2014 08:52:27 +0200 Subject: [PATCH] Show a Border around multiple Selected Items and a TopLeftContainerDragHandle (multipleItems) --- .../Project/Controls/PanelMoveAdorner.cs | 2 +- .../Extensions/TopLeftContainerDragHandle.cs | 8 +- ...TopLeftContainerDragHandleMultipleItems.cs | 93 +++++++++++++++++++ .../Project/WpfDesign.Designer.csproj | 1 + 4 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs index 3869f3c036..3958c4e123 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs @@ -54,7 +54,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { e.Handled = true; - item.Services.Selection.SetSelectedComponents(new DesignItem [] { item }, SelectionTypes.Auto); + //item.Services.Selection.SetSelectedComponents(new DesignItem [] { item }, SelectionTypes.Auto); new DragMoveMouseGesture(item, false).Start(item.Services.DesignPanel, e); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandle.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandle.cs index 6c111f3453..c8220c2e32 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandle.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandle.cs @@ -32,9 +32,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions { /// - /// The drag handle displayed for panels. + /// The drag handle displayed for Framework Elements /// - [ExtensionServer(typeof(PrimarySelectionExtensionServer))] + [ExtensionServer(typeof(OnlyOneItemSelectedExtensionServer))] [ExtensionFor(typeof(FrameworkElement))] public class TopLeftContainerDragHandle : AdornerProvider { @@ -44,9 +44,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions ContainerDragHandle rect = new ContainerDragHandle(); rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { - Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto); + //Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto); new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e); - e.Handled=true; + e.Handled=true; }; RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs new file mode 100644 index 0000000000..12a2505b3d --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs @@ -0,0 +1,93 @@ +// 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.Windows.Controls; +using System.Windows; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Shapes; +using ICSharpCode.WpfDesign.Adorners; +using ICSharpCode.WpfDesign.Extensions; + +using ICSharpCode.WpfDesign.Designer.Services; +using ICSharpCode.WpfDesign.Designer.Controls; + +namespace ICSharpCode.WpfDesign.Designer.Extensions +{ + + /// + /// The drag handle displayed for Framework Elements + /// + [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))] + [ExtensionFor(typeof(FrameworkElement))] + public class TopLeftContainerDragHandleMultipleItems : AdornerProvider + { + /// + public TopLeftContainerDragHandleMultipleItems() + { } + + protected override void OnInitialized() + { + base.OnInitialized(); + + ContainerDragHandle rect = new ContainerDragHandle(); + + rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) { + //Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto); + new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e); + e.Handled=true; + }; + + var items = this.ExtendedItem.Services.Selection.SelectedItems; + + double minX = 0; + double minY = 0; + double maxX = 0; + double maxY = 0; + + foreach (DesignItem di in items) { + Point relativeLocation = di.View.TranslatePoint(new Point(0, 0), this.ExtendedItem.View); + + minX = minX < relativeLocation.X ? minX : relativeLocation.X; + minY = minY < relativeLocation.Y ? minY : relativeLocation.Y; + maxX = maxX > relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth; + maxY = maxY > relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight; + } + + Rectangle rect2 = new Rectangle() { + Width = (maxX - minX) + 4, + Height = (maxY - minY) + 4, + Stroke = Brushes.Black, + StrokeThickness = 2, + StrokeDashArray = new DoubleCollection(){ 2, 2 }, + }; + + RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); + p.XOffset = minX - 3; + p.YOffset = minY - 3; + + RelativePlacement p2 = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top); + p2.XOffset = (minX + rect2.Width) - 2; + p2.YOffset = (minY + rect2.Height) - 2; + + AddAdorner(p, AdornerOrder.Background, rect); + AddAdorner(p2, AdornerOrder.Background, rect2); + } + } +} 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 a34a76e1b1..09acd365fa 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 @@ + FlatCollectionEditor.xaml Code