Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 78fe8ec

Browse files
committed
Show a Border around multiple Selected Items and a TopLeftContainerDragHandle (multipleItems)
1 parent 9cdcb17 commit 78fe8ec

4 files changed

Lines changed: 99 additions & 5 deletions

File tree

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public PanelMoveAdorner(DesignItem item)
5454
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
5555
{
5656
e.Handled = true;
57-
item.Services.Selection.SetSelectedComponents(new DesignItem [] { item }, SelectionTypes.Auto);
57+
//item.Services.Selection.SetSelectedComponents(new DesignItem [] { item }, SelectionTypes.Auto);
5858
new DragMoveMouseGesture(item, false).Start(item.Services.DesignPanel, e);
5959
}
6060

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandle.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
3232
{
3333

3434
/// <summary>
35-
/// The drag handle displayed for panels.
35+
/// The drag handle displayed for Framework Elements
3636
/// </summary>
37-
[ExtensionServer(typeof(PrimarySelectionExtensionServer))]
37+
[ExtensionServer(typeof(OnlyOneItemSelectedExtensionServer))]
3838
[ExtensionFor(typeof(FrameworkElement))]
3939
public class TopLeftContainerDragHandle : AdornerProvider
4040
{
@@ -44,9 +44,9 @@ public TopLeftContainerDragHandle()
4444
ContainerDragHandle rect = new ContainerDragHandle();
4545

4646
rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) {
47-
Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto);
47+
//Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto);
4848
new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e);
49-
e.Handled=true;
49+
e.Handled=true;
5050
};
5151

5252
RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using System.Windows.Controls;
21+
using System.Windows;
22+
using System.Windows.Input;
23+
using System.Windows.Media;
24+
using System.Windows.Shapes;
25+
using ICSharpCode.WpfDesign.Adorners;
26+
using ICSharpCode.WpfDesign.Extensions;
27+
28+
using ICSharpCode.WpfDesign.Designer.Services;
29+
using ICSharpCode.WpfDesign.Designer.Controls;
30+
31+
namespace ICSharpCode.WpfDesign.Designer.Extensions
32+
{
33+
34+
/// <summary>
35+
/// The drag handle displayed for Framework Elements
36+
/// </summary>
37+
[ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))]
38+
[ExtensionFor(typeof(FrameworkElement))]
39+
public class TopLeftContainerDragHandleMultipleItems : AdornerProvider
40+
{
41+
/// <summary/>
42+
public TopLeftContainerDragHandleMultipleItems()
43+
{ }
44+
45+
protected override void OnInitialized()
46+
{
47+
base.OnInitialized();
48+
49+
ContainerDragHandle rect = new ContainerDragHandle();
50+
51+
rect.PreviewMouseDown += delegate(object sender, MouseButtonEventArgs e) {
52+
//Services.Selection.SetSelectedComponents(new DesignItem[] { this.ExtendedItem }, SelectionTypes.Auto);
53+
new DragMoveMouseGesture(this.ExtendedItem, false).Start(this.ExtendedItem.Services.DesignPanel,e);
54+
e.Handled=true;
55+
};
56+
57+
var items = this.ExtendedItem.Services.Selection.SelectedItems;
58+
59+
double minX = 0;
60+
double minY = 0;
61+
double maxX = 0;
62+
double maxY = 0;
63+
64+
foreach (DesignItem di in items) {
65+
Point relativeLocation = di.View.TranslatePoint(new Point(0, 0), this.ExtendedItem.View);
66+
67+
minX = minX < relativeLocation.X ? minX : relativeLocation.X;
68+
minY = minY < relativeLocation.Y ? minY : relativeLocation.Y;
69+
maxX = maxX > relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth;
70+
maxY = maxY > relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight;
71+
}
72+
73+
Rectangle rect2 = new Rectangle() {
74+
Width = (maxX - minX) + 4,
75+
Height = (maxY - minY) + 4,
76+
Stroke = Brushes.Black,
77+
StrokeThickness = 2,
78+
StrokeDashArray = new DoubleCollection(){ 2, 2 },
79+
};
80+
81+
RelativePlacement p = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
82+
p.XOffset = minX - 3;
83+
p.YOffset = minY - 3;
84+
85+
RelativePlacement p2 = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Top);
86+
p2.XOffset = (minX + rect2.Width) - 2;
87+
p2.YOffset = (minY + rect2.Height) - 2;
88+
89+
AddAdorner(p, AdornerOrder.Background, rect);
90+
AddAdorner(p2, AdornerOrder.Background, rect2);
91+
}
92+
}
93+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<Compile Include="Extensions\RenderTransformOriginExtension.cs" />
8989
<Compile Include="Extensions\RightClickContextMenuExtension.cs" />
9090
<Compile Include="Extensions\SkewThumbExtension.cs" />
91+
<Compile Include="Extensions\TopLeftContainerDragHandleMultipleItems.cs" />
9192
<Compile Include="PropertyGrid\Editors\FlatCollectionEditor.xaml.cs">
9293
<DependentUpon>FlatCollectionEditor.xaml</DependentUpon>
9394
<SubType>Code</SubType>

0 commit comments

Comments
 (0)