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

Commit 6585614

Browse files
committed
Merge pull request #463 from jogibear9988/master
Right Click Context Menu for multiple Selected Items to Wrap them in a Container
2 parents e4a573d + df4cd4b commit 6585614

File tree

11 files changed

+425
-92
lines changed

11 files changed

+425
-92
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
3232
{
3333
public class RotateThumb : ResizeThumb
3434
{
35-
// private double initialAngle;
36-
// private RotateTransform rotateTransform;
37-
// private Vector startVector;
38-
// private Point centerPoint;
39-
// private Control designerItem;
40-
// private Panel canvas;
41-
// private AdornerPanel parent;
42-
4335
static RotateThumb()
4436
{
4537
DefaultStyleKeyProperty.OverrideMetadata(typeof(RotateThumb), new FrameworkPropertyMetadata(typeof(RotateThumb)));

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@
2626

2727
namespace ICSharpCode.WpfDesign.Designer.Controls
2828
{
29-
/// <summary>
30-
/// Display height of the element.
31-
/// </summary>
32-
class HeightDisplay : Control
33-
{
34-
static HeightDisplay()
35-
{
36-
DefaultStyleKeyProperty.OverrideMetadata(typeof(HeightDisplay), new FrameworkPropertyMetadata(typeof(HeightDisplay)));
37-
}
38-
}
29+
/// <summary>
30+
/// Display height of the element.
31+
/// </summary>
32+
class HeightDisplay : Control
33+
{
34+
static HeightDisplay()
35+
{
36+
DefaultStyleKeyProperty.OverrideMetadata(typeof(HeightDisplay), new FrameworkPropertyMetadata(typeof(HeightDisplay)));
37+
}
38+
}
3939

40-
/// <summary>
41-
/// Display width of the element.
42-
/// </summary>
43-
class WidthDisplay : Control
44-
{
45-
static WidthDisplay()
46-
{
47-
DefaultStyleKeyProperty.OverrideMetadata(typeof(WidthDisplay), new FrameworkPropertyMetadata(typeof(WidthDisplay)));
48-
}
49-
}
40+
/// <summary>
41+
/// Display width of the element.
42+
/// </summary>
43+
class WidthDisplay : Control
44+
{
45+
static WidthDisplay()
46+
{
47+
DefaultStyleKeyProperty.OverrideMetadata(typeof(WidthDisplay), new FrameworkPropertyMetadata(typeof(WidthDisplay)));
48+
}
49+
}
5050
}

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

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,55 @@ public class ContentControlInitializer : DefaultInitializer
3030
{
3131
public override void InitializeDefaults(DesignItem item)
3232
{
33-
//Not every Content Control can have a text as Content (e.g. ZoomBox of WPF Toolkit)
34-
if (item.Component is Button)
35-
{
33+
//Not every Content Control can have a text as Content (e.g. ZoomBox of WPF Toolkit)
34+
if (item.Component is Button)
35+
{
3636
DesignItemProperty contentProperty = item.Properties["Content"];
37-
if (contentProperty.ValueOnInstance == null)
38-
{
37+
if (contentProperty.ValueOnInstance == null)
38+
{
3939
contentProperty.SetValue(item.ComponentType.Name);
4040
}
4141
}
4242

43-
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
44-
if (verticalAlignmentProperty.ValueOnInstance == null)
45-
{
46-
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
47-
}
43+
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
44+
if (verticalAlignmentProperty.ValueOnInstance == null)
45+
{
46+
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
47+
}
4848

49-
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
50-
if (horizontalAlignmentProperty.ValueOnInstance == null)
51-
{
52-
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
53-
}
49+
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
50+
if (horizontalAlignmentProperty.ValueOnInstance == null)
51+
{
52+
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
53+
}
5454
}
5555
}
5656

5757
[ExtensionFor(typeof(TextBlock))]
58-
public class TextBlockInitializer : DefaultInitializer
59-
{
60-
public override void InitializeDefaults(DesignItem item)
61-
{
62-
DesignItemProperty textProperty = item.Properties["Text"];
63-
if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "")
64-
{
65-
textProperty.SetValue(item.ComponentType.Name);
66-
}
58+
public class TextBlockInitializer : DefaultInitializer
59+
{
60+
public override void InitializeDefaults(DesignItem item)
61+
{
62+
DesignItemProperty textProperty = item.Properties["Text"];
63+
if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "")
64+
{
65+
textProperty.SetValue(item.ComponentType.Name);
66+
}
6767

68-
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
69-
if (verticalAlignmentProperty.ValueOnInstance == null)
70-
{
71-
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
72-
}
68+
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
69+
if (verticalAlignmentProperty.ValueOnInstance == null)
70+
{
71+
verticalAlignmentProperty.SetValue(VerticalAlignment.Center);
72+
}
7373

74-
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
75-
if (horizontalAlignmentProperty.ValueOnInstance == null)
76-
{
77-
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
78-
}
79-
}
74+
DesignItemProperty horizontalAlignmentProperty = item.Properties["HorizontalAlignment"];
75+
if (horizontalAlignmentProperty.ValueOnInstance == null)
76+
{
77+
horizontalAlignmentProperty.SetValue(HorizontalAlignment.Center);
78+
}
79+
}
8080
}
81-
81+
8282
[ExtensionFor(typeof(HeaderedContentControl), OverrideExtension = typeof(ContentControlInitializer))]
8383
public class HeaderedContentControlInitializer : DefaultInitializer
8484
{
@@ -96,7 +96,7 @@ public override void InitializeDefaults(DesignItem item)
9696
}
9797
}
9898

99-
[ExtensionFor(typeof(Shape))]
99+
[ExtensionFor(typeof(Shape))]
100100
public class ShapeInitializer : DefaultInitializer
101101
{
102102
public override void InitializeDefaults(DesignItem item)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.RightClickMultipleItemsContextMenu"
2+
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
5+
>
6+
<MenuItem Header="{Binding WrapInCanvas, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInCanvas" />
7+
<MenuItem Header="{Binding WrapInGrid, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInGrid" />
8+
</ContextMenu>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.Collections.Generic;
21+
using System.Linq;
22+
using System.Text;
23+
using System.Windows;
24+
using System.Windows.Controls;
25+
using System.Windows.Data;
26+
using System.Windows.Documents;
27+
using System.Windows.Input;
28+
using System.Windows.Media;
29+
using System.Windows.Media.Imaging;
30+
using System.Windows.Navigation;
31+
using System.Windows.Shapes;
32+
using ICSharpCode.WpfDesign.PropertyGrid;
33+
using ICSharpCode.WpfDesign.Designer.Xaml;
34+
35+
namespace ICSharpCode.WpfDesign.Designer.Extensions
36+
{
37+
public partial class RightClickMultipleItemsContextMenu
38+
{
39+
private DesignItem designItem;
40+
41+
public RightClickMultipleItemsContextMenu(DesignItem designItem)
42+
{
43+
this.designItem = designItem;
44+
45+
InitializeComponent();
46+
}
47+
48+
void Click_WrapInCanvas(object sender, System.Windows.RoutedEventArgs e)
49+
{
50+
ModelTools.WrapItemsNewContainer(this.designItem.Services.Selection.SelectedItems, typeof(Canvas));
51+
}
52+
53+
void Click_WrapInGrid(object sender, System.Windows.RoutedEventArgs e)
54+
{
55+
ModelTools.WrapItemsNewContainer(this.designItem.Services.Selection.SelectedItems, typeof(Grid));
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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;
21+
using System.Windows.Media;
22+
using System.Windows.Shapes;
23+
24+
using ICSharpCode.WpfDesign.Adorners;
25+
using ICSharpCode.WpfDesign.Extensions;
26+
using ICSharpCode.WpfDesign.Designer;
27+
28+
namespace ICSharpCode.WpfDesign.Designer.Extensions
29+
{
30+
/// <summary>
31+
///
32+
/// </summary>
33+
[ExtensionServer(typeof(MultipleSelectedExtensionServer))]
34+
[ExtensionFor(typeof(UIElement))]
35+
public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider
36+
{
37+
DesignPanel panel;
38+
39+
protected override void OnInitialized()
40+
{
41+
base.OnInitialized();
42+
43+
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
44+
panel.ContextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem);
45+
}
46+
47+
protected override void OnRemove()
48+
{
49+
panel.ContextMenu = null;
50+
51+
base.OnRemove();
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)