Browse Source

allow resizing and deleting Grid rows and columns

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2442 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
f1718c35c4
  1. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  2. 186
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs
  3. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  4. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs
  5. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs
  6. 83
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs
  7. 22
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  8. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml

@ -161,6 +161,8 @@ @@ -161,6 +161,8 @@
<ColumnDefinition Width="10"/> <!-- 10=RailSize -->
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle -->
<Rectangle Fill="Transparent"/>
<Path Name="railHandle" Fill="#FFE6E6FF" Stretch="Fill" Stroke="#FF584FFF" Data="M0,0 L0,1 1,0.5 z"/>
<Path Name="line" Stretch="Fill" Stroke="#FF584FFF" Grid.Column="2" Margin="-1 0 0 0" Data="M0,0.5 L1,0.5"/>
</Grid>
@ -187,6 +189,8 @@ @@ -187,6 +189,8 @@
<RowDefinition Height="10"/> <!-- 10=RailSize -->
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- put a transparent rectangle in the rail so the user does not have to hit the small railHandle -->
<Rectangle Fill="Transparent"/>
<Path Name="railHandle" Fill="#FFE6E6FF" Stretch="Fill" Stroke="#FF584FFF" Data="M0,0 L1,0 0.5,1 z"/>
<Path Name="line" Stretch="Fill" Stroke="#FF584FFF" Grid.Row="2" Margin="0 -1 0 0" Data="M0.5,0 L0.5,1"/>
</Grid>

186
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/GridAdorner.cs

@ -6,15 +6,13 @@ @@ -6,15 +6,13 @@
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
@ -35,6 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -35,6 +33,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
readonly Orientation orientation;
public const double RailSize = 10;
public const double RailDistance = 6;
public const double SplitterWidth = 10;
public GridRailAdorner(DesignItem gridItem, AdornerPanel adornerPanel, Orientation orientation)
@ -49,10 +48,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -49,10 +48,10 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (orientation == Orientation.Horizontal) {
this.Height = RailSize;
previewAdorner = new GridColumnSplitterAdorner();
previewAdorner = new GridColumnSplitterAdorner(gridItem, null, null);
} else { // vertical
this.Width = RailSize;
previewAdorner = new GridRowSplitterAdorner();
previewAdorner = new GridRowSplitterAdorner(gridItem, null, null);
}
previewAdorner.IsPreview = true;
previewAdorner.IsHitTestVisible = false;
@ -70,14 +69,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -70,14 +69,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
base.OnMouseMove(e);
RelativePlacement rp = new RelativePlacement();
if (orientation == Orientation.Vertical) {
rp.XOffset = -RailSize;
rp.WidthOffset = RailSize;
rp.XOffset = -(RailSize + RailDistance);
rp.WidthOffset = RailSize + RailDistance;
rp.WidthRelativeToContentWidth = 1;
rp.HeightOffset = SplitterWidth;
rp.YOffset = e.GetPosition(this).Y - SplitterWidth / 2;
} else {
rp.YOffset = -RailSize;
rp.HeightOffset = RailSize;
rp.YOffset = -(RailSize + RailDistance);
rp.HeightOffset = RailSize + RailDistance;
rp.HeightRelativeToContentHeight = 1;
rp.WidthOffset = SplitterWidth;
rp.XOffset = e.GetPosition(this).X - SplitterWidth / 2;
@ -95,6 +94,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -95,6 +94,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
{
base.OnMouseLeftButtonDown(e);
e.Handled = true;
Focus();
adornerPanel.Children.Remove(previewAdorner);
if (orientation == Orientation.Vertical) {
using (ChangeGroup changeGroup = gridItem.OpenGroup("Split grid row")) {
@ -119,6 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -119,6 +119,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
rowCollection.CollectionElements[i].Properties[RowDefinition.HeightProperty].SetValue(newLength1);
newRowDefinition.Properties[RowDefinition.HeightProperty].SetValue(newLength2);
changeGroup.Commit();
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { newRowDefinition }, SelectionTypes.Auto);
break;
}
}
@ -145,6 +146,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -145,6 +146,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
newColumnDefinition.Properties[ColumnDefinition.WidthProperty].SetValue(newLength2);
columnCollection.CollectionElements.Insert(i + 1, newColumnDefinition);
changeGroup.Commit();
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { newColumnDefinition }, SelectionTypes.Auto);
break;
}
}
@ -164,15 +166,126 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -164,15 +166,126 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
#endregion
}
public class GridSplitterAdorner : Control
public abstract class GridSplitterAdorner : Control
{
public static readonly DependencyProperty IsPreviewProperty
= DependencyProperty.Register("IsPreview", typeof(bool), typeof(GridSplitterAdorner), new PropertyMetadata(SharedInstances.BoxedFalse));
protected readonly Grid grid;
protected readonly DesignItem gridItem;
protected readonly DesignItem firstRow, secondRow; // can also be columns
internal GridSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow)
{
Debug.Assert(gridItem != null);
this.grid = (Grid)gridItem.Component;
this.gridItem = gridItem;
this.firstRow = firstRow;
this.secondRow = secondRow;
}
public bool IsPreview {
get { return (bool)GetValue(IsPreviewProperty); }
set { SetValue(IsPreviewProperty, SharedInstances.Box(value)); }
}
ChangeGroup activeChangeGroup;
double mouseStartPos;
bool mouseIsDown;
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
e.Handled = true;
if (CaptureMouse()) {
Focus();
gridItem.Services.Selection.SetSelectedComponents(new DesignItem[] { secondRow }, SelectionTypes.Auto);
mouseStartPos = GetCoordinate(e.GetPosition(grid));
mouseIsDown = true;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (mouseIsDown) {
double mousePos = GetCoordinate(e.GetPosition(grid));
if (activeChangeGroup == null) {
if (Math.Abs(mousePos - mouseStartPos)
>= GetCoordinate(new Point(SystemParameters.MinimumHorizontalDragDistance, SystemParameters.MinimumVerticalDragDistance)))
{
activeChangeGroup = gridItem.OpenGroup("Change grid row/column size");
RememberOriginalSize();
}
}
if (activeChangeGroup != null) {
ChangeSize(mousePos - mouseStartPos);
}
}
}
protected GridLength original1, original2;
protected double originalPixelSize1, originalPixelSize2;
protected abstract double GetCoordinate(Point point);
protected abstract void RememberOriginalSize();
protected abstract DependencyProperty RowColumnSizeProperty { get; }
void ChangeSize(double delta)
{
// delta = difference in pixels
if (delta < -originalPixelSize1) delta = -originalPixelSize1;
if (delta > originalPixelSize2) delta = originalPixelSize2;
// replace Auto lengths with absolute lengths if necessary
if (original1.IsAuto) original1 = new GridLength(originalPixelSize1);
if (original2.IsAuto) original2 = new GridLength(originalPixelSize2);
GridLength new1;
if (original1.IsStar && originalPixelSize1 > 0)
new1 = new GridLength(original1.Value * (originalPixelSize1 + delta) / originalPixelSize1, GridUnitType.Star);
else
new1 = new GridLength(original1.Value + delta);
GridLength new2;
if (original2.IsStar && originalPixelSize2 > 0)
new2 = new GridLength(original2.Value * (originalPixelSize2 - delta) / originalPixelSize2, GridUnitType.Star);
else
new2 = new GridLength(original2.Value - delta);
firstRow.Properties[RowColumnSizeProperty].SetValue(new1);
secondRow.Properties[RowColumnSizeProperty].SetValue(new2);
((UIElement)VisualTreeHelper.GetParent(this)).InvalidateArrange();
}
protected override void OnMouseUp(MouseButtonEventArgs e)
{
if (activeChangeGroup != null) {
activeChangeGroup.Commit();
activeChangeGroup = null;
}
Stop();
}
protected override void OnLostMouseCapture(MouseEventArgs e)
{
Stop();
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Escape) {
e.Handled = true;
Stop();
}
}
protected void Stop()
{
ReleaseMouseCapture();
mouseIsDown = false;
if (activeChangeGroup != null) {
activeChangeGroup.Abort();
activeChangeGroup = null;
}
}
}
public class GridRowSplitterAdorner : GridSplitterAdorner
@ -182,14 +295,61 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -182,14 +295,61 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridRowSplitterAdorner)));
CursorProperty.OverrideMetadata(typeof(GridRowSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeNS));
}
internal GridRowSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) : base(gridItem, firstRow, secondRow)
{
}
protected override double GetCoordinate(Point point)
{
return point.Y;
}
protected override void RememberOriginalSize()
{
RowDefinition r1 = (RowDefinition)firstRow.Component;
RowDefinition r2 = (RowDefinition)secondRow.Component;
original1 = (GridLength)r1.GetValue(RowDefinition.HeightProperty);
original2 = (GridLength)r2.GetValue(RowDefinition.HeightProperty);
originalPixelSize1 = r1.ActualHeight;
originalPixelSize2 = r2.ActualHeight;
}
protected override DependencyProperty RowColumnSizeProperty {
get { return RowDefinition.HeightProperty; }
}
}
public class GridColumnSplitterAdorner : GridSplitterAdorner
public sealed class GridColumnSplitterAdorner : GridSplitterAdorner
{
static GridColumnSplitterAdorner()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(typeof(GridColumnSplitterAdorner)));
CursorProperty.OverrideMetadata(typeof(GridColumnSplitterAdorner), new FrameworkPropertyMetadata(Cursors.SizeWE));
}
internal GridColumnSplitterAdorner(DesignItem gridItem, DesignItem firstRow, DesignItem secondRow) : base(gridItem, firstRow, secondRow)
{
}
protected override double GetCoordinate(Point point)
{
return point.X;
}
protected override void RememberOriginalSize()
{
ColumnDefinition r1 = (ColumnDefinition)firstRow.Component;
ColumnDefinition r2 = (ColumnDefinition)secondRow.Component;
original1 = (GridLength)r1.GetValue(ColumnDefinition.WidthProperty);
original2 = (GridLength)r2.GetValue(ColumnDefinition.WidthProperty);
originalPixelSize1 = r1.ActualWidth;
originalPixelSize2 = r2.ActualWidth;
}
protected override DependencyProperty RowColumnSizeProperty {
get { return ColumnDefinition.WidthProperty; }
}
}
}

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs

@ -6,10 +6,11 @@ @@ -6,10 +6,11 @@
// </file>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Input;
using System.Xml;
using ICSharpCode.WpfDesign.Designer.Controls;
@ -58,7 +59,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -58,7 +59,7 @@ namespace ICSharpCode.WpfDesign.Designer
IUndoAction action = Func.First(undoService.UndoActions);
Debug.WriteLine("Undo " + action.Title);
undoService.Undo();
_designContext.Services.Selection.SetSelectedComponents(action.AffectedElements);
_designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements));
}
void OnUndoCanExecute(object sender, CanExecuteRoutedEventArgs e)
@ -73,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -73,7 +74,7 @@ namespace ICSharpCode.WpfDesign.Designer
IUndoAction action = Func.First(undoService.RedoActions);
Debug.WriteLine("Redo " + action.Title);
undoService.Redo();
_designContext.Services.Selection.SetSelectedComponents(action.AffectedElements);
_designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements));
}
void OnRedoCanExecute(object sender, CanExecuteRoutedEventArgs e)
@ -81,6 +82,19 @@ namespace ICSharpCode.WpfDesign.Designer @@ -81,6 +82,19 @@ namespace ICSharpCode.WpfDesign.Designer
UndoService undoService = GetService<UndoService>();
e.CanExecute = undoService != null && undoService.CanRedo;
}
// Filters an element list, dropping all elements that are not part of the xaml document
// (e.g. because they were deleted).
static List<DesignItem> GetLiveElements(ICollection<DesignItem> items)
{
List<DesignItem> result = new List<DesignItem>(items.Count);
foreach (DesignItem item in items) {
if (ModelTools.IsInDocument(item)) {
result.Add(item);
}
}
return result;
}
#endregion
#region Command: Delete

3
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasPlacementSupport.cs

@ -10,9 +10,8 @@ using System.Collections.Generic; @@ -10,9 +10,8 @@ using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{

32
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridAdornerProvider.cs

@ -7,14 +7,13 @@ @@ -7,14 +7,13 @@
using System;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Threading;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
@ -22,7 +21,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -22,7 +21,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// Allows arranging the rows/column on a grid.
/// </summary>
[ExtensionFor(typeof(Grid))]
public class GridAdornerProvider : PrimarySelectionAdornerProvider
[ExtensionServer(typeof(LogicalOrExtensionServer<PrimarySelectionExtensionServer, PrimarySelectionParentExtensionServer>))]
public class GridAdornerProvider : AdornerProvider
{
sealed class RowSplitterPlacement : AdornerPlacement
{
@ -31,9 +31,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -31,9 +31,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
adorner.Arrange(new Rect(-GridRailAdorner.RailSize,
adorner.Arrange(new Rect(-(GridRailAdorner.RailSize + GridRailAdorner.RailDistance),
row.Offset - GridRailAdorner.SplitterWidth / 2,
GridRailAdorner.RailSize + adornedElementSize.Width,
GridRailAdorner.RailSize + GridRailAdorner.RailDistance + adornedElementSize.Width,
GridRailAdorner.SplitterWidth));
}
}
@ -46,9 +46,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -46,9 +46,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
adorner.Arrange(new Rect(column.Offset - GridRailAdorner.SplitterWidth / 2,
-GridRailAdorner.RailSize,
-(GridRailAdorner.RailSize + GridRailAdorner.RailDistance),
GridRailAdorner.SplitterWidth,
GridRailAdorner.RailSize + adornedElementSize.Height));
GridRailAdorner.RailSize + GridRailAdorner.RailDistance + adornedElementSize.Height));
}
}
@ -60,8 +60,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -60,8 +60,12 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
leftBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Vertical);
topBar = new GridRailAdorner(this.ExtendedItem, adornerPanel, Orientation.Horizontal);
AdornerPanel.SetPlacement(leftBar, new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Stretch));
AdornerPanel.SetPlacement(topBar, new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Top));
RelativePlacement rp = new RelativePlacement(HorizontalAlignment.Left, VerticalAlignment.Stretch);
rp.XOffset -= GridRailAdorner.RailDistance;
AdornerPanel.SetPlacement(leftBar, rp);
rp = new RelativePlacement(HorizontalAlignment.Stretch, VerticalAlignment.Top);
rp.YOffset -= GridRailAdorner.RailDistance;
AdornerPanel.SetPlacement(topBar, rp);
adornerPanel.Children.Add(leftBar);
adornerPanel.Children.Add(topBar);
@ -110,16 +114,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -110,16 +114,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
splitterList.Clear();
Grid grid = (Grid)this.ExtendedItem.Component;
IList<DesignItem> col = this.ExtendedItem.Properties["RowDefinitions"].CollectionElements;
for (int i = 1; i < grid.RowDefinitions.Count; i++) {
RowDefinition row = grid.RowDefinitions[i];
GridRowSplitterAdorner splitter = new GridRowSplitterAdorner();
GridRowSplitterAdorner splitter = new GridRowSplitterAdorner(this.ExtendedItem, col[i-1], col[i]);
AdornerPanel.SetPlacement(splitter, new RowSplitterPlacement(row));
adornerPanel.Children.Add(splitter);
splitterList.Add(splitter);
}
col = this.ExtendedItem.Properties["ColumnDefinitions"].CollectionElements;
for (int i = 1; i < grid.ColumnDefinitions.Count; i++) {
ColumnDefinition column = grid.ColumnDefinitions[i];
GridColumnSplitterAdorner splitter = new GridColumnSplitterAdorner();
GridColumnSplitterAdorner splitter = new GridColumnSplitterAdorner(this.ExtendedItem, col[i-1], col[i]);
AdornerPanel.SetPlacement(splitter, new ColumnSplitterPlacement(column));
adornerPanel.Children.Add(splitter);
splitterList.Add(splitter);

83
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/GridPlacementSupport.cs

@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// Provides <see cref="IPlacementBehavior"/> behavior for <see cref="Grid"/>.
/// </summary>
[ExtensionFor(typeof(Grid))]
public sealed class GridPlacementSupport : BehaviorExtension, IPlacementBehavior
{
protected override void OnInitialized()
{
base.OnInitialized();
this.ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this);
}
public bool CanPlace(ICollection<DesignItem> childItems, PlacementType type, PlacementAlignment position)
{
return type == PlacementType.Delete;
}
public void BeginPlacement(PlacementOperation operation)
{
}
public void EndPlacement(PlacementOperation operation)
{
}
public Rect GetPosition(PlacementOperation operation, DesignItem child)
{
return new Rect();
}
public void SetPosition(PlacementInformation info)
{
throw new NotImplementedException();
}
public bool CanLeaveContainer(PlacementOperation operation)
{
return true;
}
public void LeaveContainer(PlacementOperation operation)
{
foreach (PlacementInformation info in operation.PlacedItems) {
if (info.Item.ComponentType == typeof(ColumnDefinition)) {
// TODO: combine the width of the deleted column with the previous column
this.ExtendedItem.Properties["ColumnDefinitions"].CollectionElements.Remove(info.Item);
} else if (info.Item.ComponentType == typeof(RowDefinition)) {
this.ExtendedItem.Properties["RowDefinitions"].CollectionElements.Remove(info.Item);
} else {
throw new NotImplementedException();
}
}
}
public bool CanEnterContainer(PlacementOperation operation)
{
return false;
}
public void EnterContainer(PlacementOperation operation)
{
throw new NotImplementedException();
}
}
}

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

@ -44,6 +44,20 @@ namespace ICSharpCode.WpfDesign.Designer @@ -44,6 +44,20 @@ namespace ICSharpCode.WpfDesign.Designer
return 0;
}
/// <summary>
/// Gets if the specified design item is in the document it belongs to.
/// </summary>
/// <returns>True for live objects, false for deleted objects.</returns>
public static bool IsInDocument(DesignItem item)
{
DesignItem rootItem = item.Context.RootItem;
while (item != null) {
if (item == rootItem) return true;
item = item.Parent;
}
return false;
}
/// <summary>
/// Gets if the specified components can be deleted.
/// </summary>
@ -60,9 +74,15 @@ namespace ICSharpCode.WpfDesign.Designer @@ -60,9 +74,15 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
public static void DeleteComponents(ICollection<DesignItem> items)
{
DesignItem parent = Func.First(items).Parent;
PlacementOperation operation = PlacementOperation.Start(items, PlacementType.Delete);
try {
Func.First(items).Services.Selection.SetSelectedComponents(items, SelectionTypes.Remove);
ISelectionService selectionService = Func.First(items).Services.Selection;
selectionService.SetSelectedComponents(items, SelectionTypes.Remove);
// if the selection is empty after deleting some components, select the parent of the deleted component
if (selectionService.SelectionCount == 0 && !items.Contains(parent)) {
selectionService.SetSelectedComponents(new DesignItem[] { parent });
}
operation.DeleteItemsAndCommit();
} catch {
operation.Abort();

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

@ -74,6 +74,7 @@ @@ -74,6 +74,7 @@
<Compile Include="Controls\WindowClone.cs" />
<Compile Include="DesignPanel.cs" />
<Compile Include="Extensions\GridAdornerProvider.cs" />
<Compile Include="Extensions\GridPlacementSupport.cs" />
<Compile Include="ModelTools.cs" />
<Compile Include="Extensions\CanvasPlacementSupport.cs" />
<Compile Include="Extensions\PanelInstanceFactory.cs" />

Loading…
Cancel
Save