Browse Source

Arrange Items via ContextMenu and a few fixes...

pull/584/head
jogibear9988 11 years ago
parent
commit
a906864e40
  1. 18
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs
  2. 36
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml
  3. 78
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs
  4. 58
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs
  5. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs
  6. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml
  7. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs
  8. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs
  9. BIN
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png
  10. 329
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  11. 48
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs
  12. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

18
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ArrangeDirection.cs

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSharpCode.WpfDesign.Designer
{
public enum ArrangeDirection
{
Top,
VerticalMiddle,
Bottom,
Left,
HorizontalMiddle,
Right,
}
}

36
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml

@ -0,0 +1,36 @@
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.ArrangeItemsContextMenu"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
>
<MenuItem Header="{Binding ArrangeLeft, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeLeft">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-left.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{Binding ArrangeHorizontalMiddle, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeHorizontalCentered">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-center.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{Binding ArrangeRight, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeRight">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-right.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{Binding ArrangeTop, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeTop">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{Binding ArrangeVerticalMiddle, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeVerticalCentered">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-middle.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{Binding ArrangeBottom, Source={x:Static Translation:Translations.Instance}}" Click="Click_ArrangeBottom">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/layers-alignment-bottom.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>

78
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenu.xaml.cs

@ -0,0 +1,78 @@
// 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.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.PropertyGrid;
using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public partial class ArrangeItemsContextMenu
{
private DesignItem designItem;
public ArrangeItemsContextMenu(DesignItem designItem)
{
this.designItem = designItem;
InitializeComponent();
}
void Click_ArrangeLeft(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Left);
}
void Click_ArrangeHorizontalCentered(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.HorizontalMiddle);
}
void Click_ArrangeRight(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Right);
}
void Click_ArrangeTop(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Top);
}
void Click_ArrangeVerticalCentered(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.VerticalMiddle);
}
void Click_ArrangeBottom(object sender, System.Windows.RoutedEventArgs e)
{
ModelTools.ArrangeItems(this.designItem.Services.Selection.SelectedItems, ArrangeDirection.Bottom);
}
}
}

58
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ArrangeItemsContextMenuExtension.cs

@ -0,0 +1,58 @@
// 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;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
///
/// </summary>
[ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))]
[ExtensionFor(typeof(UIElement))]
[Extension(Order = 30)]
public class ArrangeItemsContextMenuExtension : SelectionAdornerProvider
{
DesignPanel panel;
ContextMenu contextMenu;
protected override void OnInitialized()
{
base.OnInitialized();
contextMenu = new ArrangeItemsContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.AddContextMenu(contextMenu);
}
protected override void OnRemove()
{
panel.RemoveContextMenu(contextMenu);
base.OnRemove();
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TopLeftContainerDragHandleMultipleItems.cs

@ -66,8 +66,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
minX = minX < relativeLocation.X ? minX : relativeLocation.X; minX = minX < relativeLocation.X ? minX : relativeLocation.X;
minY = minY < relativeLocation.Y ? minY : relativeLocation.Y; minY = minY < relativeLocation.Y ? minY : relativeLocation.Y;
maxX = maxX > relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)this.ExtendedItem.View).ActualWidth; maxX = maxX > relativeLocation.X + ((FrameworkElement)di.View).ActualWidth ? maxX : relativeLocation.X + ((FrameworkElement)di.View).ActualWidth;
maxY = maxY > relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)this.ExtendedItem.View).ActualHeight; maxY = maxY > relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight ? maxY : relativeLocation.Y + ((FrameworkElement)di.View).ActualHeight;
} }
Rectangle rect2 = new Rectangle() { Rectangle rect2 = new Rectangle() {

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml

@ -1,8 +1,12 @@
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.RightClickMultipleItemsContextMenu" <ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.WrapItemsContextMenu"
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation" xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer" xmlns:Translation="clr-namespace:ICSharpCode.WpfDesign.Designer"
> >
<MenuItem Header="{Binding WrapInCanvas, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInCanvas" /> <MenuItem Header="{Binding WrapInCanvas, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInCanvas" />
<MenuItem Header="{Binding WrapInGrid, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInGrid" /> <MenuItem Header="{Binding WrapInGrid, Source={x:Static Translation:Translations.Instance}}" Click="Click_WrapInGrid">
<MenuItem.Icon>
<Image Source="/ICSharpCode.WpfDesign.Designer;component/Images/grid.png" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu> </ContextMenu>

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenu.xaml.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenu.xaml.cs

@ -34,11 +34,11 @@ using ICSharpCode.WpfDesign.Designer.Xaml;
namespace ICSharpCode.WpfDesign.Designer.Extensions namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
public partial class RightClickMultipleItemsContextMenu public partial class WrapItemsContextMenu
{ {
private DesignItem designItem; private DesignItem designItem;
public RightClickMultipleItemsContextMenu(DesignItem designItem) public WrapItemsContextMenu(DesignItem designItem)
{ {
this.designItem = designItem; this.designItem = designItem;

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/WrapItemsContextMenuExtension.cs

@ -33,7 +33,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// </summary> /// </summary>
[ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))] [ExtensionServer(typeof(PrimarySelectionButOnlyWhenMultipleSelectedExtensionServer))]
[ExtensionFor(typeof(UIElement))] [ExtensionFor(typeof(UIElement))]
public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider [Extension(Order = 50)]
public class WrapItemsContextMenuExtension : SelectionAdornerProvider
{ {
DesignPanel panel; DesignPanel panel;
ContextMenu contextMenu; ContextMenu contextMenu;
@ -42,7 +43,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{ {
base.OnInitialized(); base.OnInitialized();
contextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem); contextMenu = new WrapItemsContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
panel.AddContextMenu(contextMenu); panel.AddContextMenu(contextMenu);
} }

BIN
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Images/grid.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

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

@ -229,8 +229,113 @@ namespace ICSharpCode.WpfDesign.Designer
public DesignItem DesignItem { get; set; } public DesignItem DesignItem { get; set; }
} }
public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType) private static ItemPos GetItemPos(DesignItem designItem)
{
var itemPos = new ItemPos() {DesignItem = designItem};
if (designItem.Parent.Component is Canvas)
{
var canvas = designItem.Parent.View as Canvas;
if (designItem.Properties.GetAttachedProperty(Canvas.RightProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{
itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = canvas.ActualWidth -
(double) designItem.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth;
}
else if (designItem.Properties.GetAttachedProperty(Canvas.LeftProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet)
{
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin =
(double) designItem.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
}
else
{
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
}
if (designItem.Properties.GetAttachedProperty(Canvas.BottomProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{
itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = canvas.ActualHeight -
(double)
designItem.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight;
}
else if (designItem.Properties.GetAttachedProperty(Canvas.TopProperty) != null &&
designItem.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet)
{
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin =
(double) designItem.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
}
else
{
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
}
}
else if (designItem.Parent.Component is Grid)
{
var grid = designItem.Parent.View as Grid;
if (
(HorizontalAlignment)
designItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance ==
HorizontalAlignment.Right)
{
itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = grid.ActualWidth -
((Thickness)
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Right;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement) designItem.View).ActualWidth;
}
else
{
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin =
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement) designItem.View).ActualWidth;
}
if (
(VerticalAlignment)
designItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance ==
VerticalAlignment.Bottom)
{
itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = grid.ActualHeight -
((Thickness)
designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Bottom;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement) designItem.View).ActualHeight;
}
else
{
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin =
((Thickness) designItem.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance)
.Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement) designItem.View).ActualHeight;
}
}
return itemPos;
}
public static void WrapItemsNewContainer(IEnumerable<DesignItem> items, Type containerType)
{ {
var collection = items; var collection = items;
@ -248,68 +353,14 @@ namespace ICSharpCode.WpfDesign.Designer
List<ItemPos> itemList = new List<ItemPos>(); List<ItemPos> itemList = new List<ItemPos>();
foreach (var item in collection) { foreach (var item in collection) {
itemList.Add(GetItemPos(item));
var itemPos = new ItemPos(){ DesignItem = item };
itemList.Add(itemPos);
if (oldContainer.Component is Canvas) { if (oldContainer.Component is Canvas) {
var canvas = oldContainer.View as Canvas;
if (item.Properties.GetAttachedProperty(Canvas.RightProperty) != null && item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet) {
itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = canvas.ActualWidth - (double)item.Properties.GetAttachedProperty(Canvas.RightProperty).ValueOnInstance;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth;
}
else if (item.Properties.GetAttachedProperty(Canvas.LeftProperty) != null && item.Properties.GetAttachedProperty(Canvas.LeftProperty).IsSet) {
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin = (double)item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
} else {
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
}
if (item.Properties.GetAttachedProperty(Canvas.BottomProperty) != null && item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet) {
itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = canvas.ActualHeight - (double)item.Properties.GetAttachedProperty(Canvas.BottomProperty).ValueOnInstance;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight;
}
else if (item.Properties.GetAttachedProperty(Canvas.TopProperty) != null && item.Properties.GetAttachedProperty(Canvas.TopProperty).IsSet) {
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin = (double)item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
} else {
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
}
item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset();
item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset();
} else if (oldContainer.Component is Grid) { } else if (oldContainer.Component is Grid) {
var grid = oldContainer.View as Grid;
if ((HorizontalAlignment)item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).ValueOnInstance == HorizontalAlignment.Right) {
itemPos.HorizontalAlignment = HorizontalAlignment.Right;
itemPos.Xmax = grid.ActualWidth - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Right;
itemPos.Xmin = itemPos.Xmax - ((FrameworkElement)item.View).ActualWidth;
} else {
itemPos.HorizontalAlignment = HorizontalAlignment.Left;
itemPos.Xmin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Left;
itemPos.Xmax = itemPos.Xmin + ((FrameworkElement)item.View).ActualWidth;
}
if ((VerticalAlignment)item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).ValueOnInstance == VerticalAlignment.Bottom) {
itemPos.VerticalAlignment = VerticalAlignment.Bottom;
itemPos.Ymax = grid.ActualHeight - ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Bottom;
itemPos.Ymin = itemPos.Ymax - ((FrameworkElement)item.View).ActualHeight;
} else {
itemPos.VerticalAlignment = VerticalAlignment.Top;
itemPos.Ymin = ((Thickness)item.Properties.GetProperty(FrameworkElement.MarginProperty).ValueOnInstance).Top;
itemPos.Ymax = itemPos.Ymin + ((FrameworkElement)item.View).ActualHeight;
}
item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset();
item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset();
item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset(); item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset();
@ -380,5 +431,167 @@ namespace ICSharpCode.WpfDesign.Designer
_context.Services.Selection.SetSelectedComponents(new []{ newPanel }); _context.Services.Selection.SetSelectedComponents(new []{ newPanel });
} }
}
public static void ArrangeItems(IEnumerable<DesignItem> items, ArrangeDirection arrangeDirection)
{
var collection = items;
var _context = collection.First().Context as XamlDesignContext;
var container = collection.First().Parent;
if (collection.Any(x => x.Parent != container))
return;
var changeGroup = container.OpenGroup("Arrange Elements");
List<ItemPos> itemList = new List<ItemPos>();
foreach (var item in collection)
{
itemList.Add(GetItemPos(item));
}
var xmin = itemList.Min(x => x.Xmin);
var xmax = itemList.Max(x => x.Xmax);
var mpos = (xmax - xmin) / 2 + xmin;
var ymin = itemList.Min(x => x.Ymin);
var ymax = itemList.Max(x => x.Ymax);
var ympos = (ymax - ymin) / 2 + ymin;
foreach (var item in collection)
{
switch (arrangeDirection)
{
case ArrangeDirection.Left:
{
if (container.Component is Canvas)
{
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(xmin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualWidth - (xmin + (double) ((FrameworkElement) item.Component).ActualWidth);
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
}
}
else if (container.Component is Grid)
{
}
}
break;
case ArrangeDirection.HorizontalMiddle:
{
if (container.Component is Canvas)
{
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(mpos - (((FrameworkElement)item.Component).ActualWidth) / 2);
}
else
{
var pp = mpos - (((FrameworkElement) item.Component).ActualWidth)/2;
var pos = (double)((Panel)item.Parent.Component).ActualWidth - pp - (((FrameworkElement)item.Component).ActualWidth);
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
}
}
else if (container.Component is Grid)
{
}
}
break;
case ArrangeDirection.Right:
{
if (container.Component is Canvas)
{
if (!item.Properties.GetAttachedProperty(Canvas.RightProperty).IsSet)
{
var pos = xmax - (double)((FrameworkElement)item.Component).ActualWidth;
item.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(pos);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualWidth - xmax;
item.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(pos);
}
}
else if (container.Component is Grid)
{
}
}
break;
case ArrangeDirection.Top:
{
if (container.Component is Canvas)
{
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ymin);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualHeight - (ymin + (double)((FrameworkElement)item.Component).ActualHeight);
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
}
}
else if (container.Component is Grid)
{
}
}
break;
case ArrangeDirection.VerticalMiddle:
{
if (container.Component is Canvas)
{
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(ympos - (((FrameworkElement)item.Component).ActualHeight) / 2);
}
else
{
var pp = mpos - (((FrameworkElement)item.Component).ActualHeight) / 2;
var pos = (double)((Panel)item.Parent.Component).ActualHeight - pp - (((FrameworkElement)item.Component).ActualHeight);
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
}
}
else if (container.Component is Grid)
{
}
}
break;
case ArrangeDirection.Bottom:
{
if (container.Component is Canvas)
{
if (!item.Properties.GetAttachedProperty(Canvas.BottomProperty).IsSet)
{
var pos = ymax - (double)((FrameworkElement)item.Component).ActualHeight;
item.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(pos);
}
else
{
var pos = (double)((Panel)item.Parent.Component).ActualHeight - ymax;
item.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(pos);
}
}
else if (container.Component is Grid)
{
}
}
break;
}
}
changeGroup.Commit();
//_context.Services.Selection.SetSelectedComponents(null);
//_context.Services.Selection.SetSelectedComponents(items.ToList());
}
}
} }

48
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Translations.cs

@ -92,6 +92,52 @@ namespace ICSharpCode.WpfDesign.Designer
} }
} }
public virtual string ArrangeLeft
{
get
{
return "Arrange Left";
}
}
public virtual string ArrangeHorizontalMiddle
{
get
{
return "Horizontal centered";
}
}
public virtual string ArrangeRight
{
get
{
return "Arrange Right";
}
}
public virtual string ArrangeTop
{
get
{
return "Arrange Top";
}
}
public virtual string ArrangeVerticalMiddle
{
get
{
return "Vertical centered";
}
}
public virtual string ArrangeBottom
{
get
{
return "Arrange Bottom";
}
}
} }
} }

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

@ -83,6 +83,7 @@
<Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs"> <Compile Include="..\..\..\..\..\Main\GlobalAssemblyInfo.cs">
<Link>Configuration\GlobalAssemblyInfo.cs</Link> <Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="ArrangeDirection.cs" />
<Compile Include="Controls\RenderTransformOriginThumb.cs" /> <Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Extensions\PartialPanelSelectionHandler.cs" /> <Compile Include="Extensions\PartialPanelSelectionHandler.cs" />
<Compile Include="Extensions\TextBlockRightClickContextMenu.xaml.cs"> <Compile Include="Extensions\TextBlockRightClickContextMenu.xaml.cs">
@ -95,10 +96,14 @@
<Compile Include="Extensions\RenderTransformOriginExtension.cs" /> <Compile Include="Extensions\RenderTransformOriginExtension.cs" />
<Compile Include="Extensions\RightClickContextMenuExtension.cs" /> <Compile Include="Extensions\RightClickContextMenuExtension.cs" />
<Compile Include="Extensions\TextBlockRightClickContextMenuExtension.cs" /> <Compile Include="Extensions\TextBlockRightClickContextMenuExtension.cs" />
<Compile Include="Extensions\ArrangeItemsContextMenuExtension.cs" />
<Compile Include="Extensions\ArrangeItemsContextMenu.xaml.cs">
<DependentUpon>ArrangeItemsContextMenu.xaml</DependentUpon>
</Compile>
<Compile Include="OutlineView\OutlineNodeBase.cs" /> <Compile Include="OutlineView\OutlineNodeBase.cs" />
<Compile Include="Extensions\RightClickMultipleItemsContextMenuExtension.cs" /> <Compile Include="Extensions\WrapItemsContextMenuExtension.cs" />
<Compile Include="Extensions\RightClickMultipleItemsContextMenu.xaml.cs"> <Compile Include="Extensions\WrapItemsContextMenu.xaml.cs">
<DependentUpon>RightClickMultipleItemsContextMenu.xaml</DependentUpon> <DependentUpon>WrapItemsContextMenu.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Extensions\SkewThumbExtension.cs" /> <Compile Include="Extensions\SkewThumbExtension.cs" />
<Compile Include="Extensions\TopLeftContainerDragHandleMultipleItems.cs" /> <Compile Include="Extensions\TopLeftContainerDragHandleMultipleItems.cs" />
@ -279,7 +284,12 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Include="Extensions\RightClickContextMenu.xaml" /> <Page Include="Extensions\RightClickContextMenu.xaml" />
<Page Include="Extensions\RightClickMultipleItemsContextMenu.xaml" /> <Page Include="Extensions\ArrangeItemsContextMenu.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Extensions\WrapItemsContextMenu.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="PropertyGrid\Editors\ColorEditor.xaml" /> <Page Include="PropertyGrid\Editors\ColorEditor.xaml" />
<Page Include="PropertyGrid\Editors\FlatCollectionEditor.xaml" /> <Page Include="PropertyGrid\Editors\FlatCollectionEditor.xaml" />
<Page Include="PropertyGrid\Editors\FormatedTextEditor\FormatedTextEditor.xaml"> <Page Include="PropertyGrid\Editors\FormatedTextEditor\FormatedTextEditor.xaml">
@ -425,4 +435,7 @@
<ItemGroup> <ItemGroup>
<Resource Include="Images\edit.png" /> <Resource Include="Images\edit.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="Images\grid.png" />
</ItemGroup>
</Project> </Project>
Loading…
Cancel
Save