Browse Source

Allow creating new components.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2425 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
877dd375d9
  1. BIN
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Delete.png
  2. 2
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/StandaloneDesigner.csproj
  3. 115
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs
  4. 13
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml
  5. 23
      src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs
  6. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.cs
  7. 27
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs
  8. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  9. 66
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignSurface.cs
  10. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasChildResizeSupport.cs
  11. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs
  12. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ClickOrDragMouseGesture.cs
  13. 182
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  14. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs
  15. 114
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs
  16. 52
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs
  17. 163
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ToolService.cs
  18. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  19. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
  20. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs
  21. 28
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs
  22. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs
  23. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  24. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  25. 55
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs
  26. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementType.cs
  27. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyEditor/DesignItemDataProperty.cs
  28. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyEditor/IPropertyEditorDataSource.cs
  29. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyEditor/MultiSelectionDataProperty.cs
  30. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs
  31. 22
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs
  32. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs

BIN
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Images/Delete.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

2
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/StandaloneDesigner.csproj

@ -48,6 +48,7 @@ @@ -48,6 +48,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Toolbox.cs" />
<Compile Include="Window1.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>Window1.xaml</DependentUpon>
@ -64,5 +65,6 @@ @@ -64,5 +65,6 @@
<Folder Include="Images" />
<Resource Include="Images\Redo.png" />
<Resource Include="Images\Undo.png" />
<Resource Include="Images\Delete.png" />
</ItemGroup>
</Project>

115
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Toolbox.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
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;
using ICSharpCode.WpfDesign.Designer.Services;
namespace StandaloneDesigner
{
public partial class Toolbox : ListBox
{
public Toolbox()
{
this.SelectionMode = SelectionMode.Single;
}
IToolService toolService;
public IToolService ToolService {
get { return toolService; }
set {
if (toolService != null) {
toolService.CurrentToolChanged -= OnCurrentToolChanged;
}
toolService = value;
this.Items.Clear();
if (toolService != null) {
AddTool("Pointer", toolService.PointerTool);
AddTool(typeof(Button));
AddTool(typeof(TextBox));
AddTool(typeof(CheckBox));
toolService.CurrentToolChanged += OnCurrentToolChanged;
OnCurrentToolChanged(null, null);
}
}
}
void AddTool(Type componentType)
{
AddTool(componentType.Name, new CreateComponentTool(componentType));
}
void AddTool(string title, ITool tool)
{
ListBoxItem item = new ListBoxItem();
item.Content = title;
item.Tag = tool;
this.Items.Add(item);
}
void OnCurrentToolChanged(object sender, EventArgs e)
{
Debug.WriteLine("Toolbox.OnCurrentToolChanged");
for (int i = 0; i < this.Items.Count; i++) {
if (((ListBoxItem)this.Items[i]).Tag == toolService.CurrentTool) {
this.SelectedIndex = i;
return;
}
}
this.SelectedIndex = -1;
}
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
base.OnSelectionChanged(e);
Debug.WriteLine("Toolbox.OnSelectionChanged");
if (toolService != null && this.SelectedItem is ListBoxItem) {
toolService.CurrentTool = (ITool)(this.SelectedItem as ListBoxItem).Tag;
}
}
Point startPos;
bool canStartDrag;
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
{
startPos = e.GetPosition(this);
canStartDrag = true;
base.OnPreviewMouseLeftButtonDown(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (canStartDrag && e.LeftButton == MouseButtonState.Pressed) {
if ((e.GetPosition(this) - startPos).LengthSquared > 4) {
canStartDrag = false;
if (this.SelectedItem == null)
return;
if (toolService != null && this.SelectedItem is ListBoxItem) {
ITool tool = (ITool)(this.SelectedItem as ListBoxItem).Tag;
if (tool is CreateComponentTool) {
DragDrop.DoDragDrop((ListBoxItem)this.SelectedItem, tool, DragDropEffects.Copy);
}
}
}
}
base.OnMouseMove(e);
}
}
}

13
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml

@ -2,12 +2,14 @@ @@ -2,12 +2,14 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:designer="clr-namespace:ICSharpCode.WpfDesign.Designer;assembly=ICSharpCode.WpfDesign.Designer"
xmlns:my="clr-namespace:StandaloneDesigner"
Title="StandaloneDesigner" Height="500" Width="700"
>
<DockPanel>
<ToolBar DockPanel.Dock="Top" Name="toolBar">
<Button Command="Undo"><Image Source="Images/Undo.png" Stretch="None"/></Button>
<Button Command="Redo"><Image Source="Images/Redo.png" Stretch="None"/></Button>
<Button Command="Delete"><Image Source="Images/Delete.png" Stretch="None"/></Button>
</ToolBar>
<Grid>
<Grid.ColumnDefinitions>
@ -47,7 +49,16 @@ @@ -47,7 +49,16 @@
</TabItem>
</TabControl>
<GridSplitter HorizontalAlignment="Left" Width="4" VerticalAlignment="Stretch" Grid.Column="1"/>
<designer:PropertyEditor Name="propertyEditor" Grid.Column="1" Margin="4 0 0 0" FontSize="8.25pt"/>
<Grid Grid.Column="1" Margin="4 0 0 0">
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<my:Toolbox x:Name="toolbox"/>
<!--<Button Click="TestButtonClick">TestButton</Button>-->
<GridSplitter HorizontalAlignment="Stretch" Height="4" VerticalAlignment="Top" Grid.Row="1"/>
<designer:PropertyEditor Name="propertyEditor" Grid.Row="1" Margin="0 4 0 0" FontSize="8.25pt"/>
</Grid>
</Grid>
</DockPanel>
</Window>

23
src/AddIns/DisplayBindings/WpfDesign/StandaloneDesigner/Window1.xaml.cs

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.Windows;
@ -8,6 +9,8 @@ using System.Xml; @@ -8,6 +9,8 @@ using System.Xml;
using ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.PropertyEditor;
using System.Threading;
using System.Windows.Threading;
namespace StandaloneDesigner
{
@ -37,6 +40,7 @@ namespace StandaloneDesigner @@ -37,6 +40,7 @@ namespace StandaloneDesigner
DesignSurface designSurface;
PropertyEditor propertyEditor;
ToolBar toolBar;
Toolbox toolbox;
#endif
void tabControlSelectionChanged(object sender, RoutedEventArgs e)
@ -45,6 +49,7 @@ namespace StandaloneDesigner @@ -45,6 +49,7 @@ namespace StandaloneDesigner
if (tabControl.SelectedItem == designTab) {
designSurface.LoadDesigner(new XmlTextReader(new StringReader(CodeTextBox.Text)));
designSurface.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
toolbox.ToolService = designSurface.DesignContext.Services.Tool;
} else {
if (designSurface.DesignContext != null) {
propertyEditor.EditedObject = null;
@ -58,6 +63,7 @@ namespace StandaloneDesigner @@ -58,6 +63,7 @@ namespace StandaloneDesigner
}
}
designSurface.UnloadDesigner();
toolbox.ToolService = null;
}
}
@ -68,7 +74,8 @@ namespace StandaloneDesigner @@ -68,7 +74,8 @@ namespace StandaloneDesigner
ISelectionService selectionService = designSurface.DesignContext.Services.Selection;
ICollection<DesignItem> items = selectionService.SelectedItems;
if (!IsCollectionWithSameElements(items, oldItems)) {
propertyEditor.EditedObject = DesignItemDataSource.GetDataSourceForDesignItems(items);
IPropertyEditorDataSource dataSource = DesignItemDataSource.GetDataSourceForDesignItems(items);
propertyEditor.EditedObject = dataSource;
oldItems = items;
}
}
@ -86,5 +93,19 @@ namespace StandaloneDesigner @@ -86,5 +93,19 @@ namespace StandaloneDesigner
}
return true;
}
void TestButtonClick(object sender, EventArgs e)
{
DesignItem[] c = new List<DesignItem>(designSurface.DesignContext.Services.Selection.SelectedItems).ToArray();
if (c.Length < 2) return;
int index = 0;
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
timer.Tick += delegate {
index++;
designSurface.DesignContext.Services.Selection.SetSelectedComponents(new DesignItem[] { c[index % c.Length] });
};
timer.Start();
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyEditor.cs

@ -117,13 +117,13 @@ namespace ICSharpCode.WpfDesign.Designer @@ -117,13 +117,13 @@ namespace ICSharpCode.WpfDesign.Designer
}
} else {
PropertyGridView grid = new PropertyGridView();
contentStackPanel.Children.Add(grid);
foreach (IPropertyEditorDataProperty p in Func.Sort(dataSource.Properties, ComparePropertyNames)) {
if (p.Name == "Name") {
continue;
}
grid.AddProperty(p);
}
contentStackPanel.Children.Add(grid);
}
}

27
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PropertyEditor/PropertyNameTextBlock.cs

@ -18,8 +18,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -18,8 +18,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
sealed class PropertyNameTextBlock : TextBlock
{
readonly IPropertyEditorDataProperty property;
readonly TextBlock toolTipTextBlock;
bool toolTipTextBlockInitialized;
readonly DockPanel toolTipDockPanel;
bool toolTipInitialized;
internal DependencyPropertyDotButton ContextMenuProvider;
public PropertyNameTextBlock(IPropertyEditorDataProperty property)
@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
this.TextAlignment = TextAlignment.Right;
this.TextTrimming = TextTrimming.CharacterEllipsis;
this.ToolTip = toolTipTextBlock = new TextBlock();
this.ToolTip = toolTipDockPanel = new DockPanel();
}
protected override void OnToolTipOpening(ToolTipEventArgs e)
@ -48,17 +48,22 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -48,17 +48,22 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
void CreateToolTip()
{
if (toolTipTextBlockInitialized)
if (toolTipInitialized)
return;
toolTipTextBlockInitialized = true;
toolTipTextBlock.TextAlignment = TextAlignment.Left;
toolTipTextBlock.Inlines.Add(new Bold(new Run(property.Name)));
toolTipInitialized = true;
TextBlock textBlock = new TextBlock();
textBlock.TextAlignment = TextAlignment.Left;
textBlock.Inlines.Add(new Bold(new Run(property.Name)));
if (property.ReturnType != null) {
toolTipTextBlock.Inlines.Add(" (" + property.ReturnType.Name + ")");
textBlock.Inlines.Add(" (" + property.ReturnType.Name + ")");
}
if (!string.IsNullOrEmpty(property.Description)) {
toolTipTextBlock.Inlines.Add(new LineBreak());
toolTipTextBlock.Inlines.Add(property.Description);
DockPanel.SetDock(textBlock, Dock.Top);
toolTipDockPanel.Children.Add(textBlock);
object description = property.GetDescription();
if (description != null) {
ContentControl cc = new ContentControl();
cc.Content = description;
toolTipDockPanel.Children.Add(cc);
}
}
}

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs

@ -145,9 +145,11 @@ namespace ICSharpCode.WpfDesign.Designer @@ -145,9 +145,11 @@ namespace ICSharpCode.WpfDesign.Designer
this.Focusable = true;
this.VerticalAlignment = VerticalAlignment.Top;
this.HorizontalAlignment = HorizontalAlignment.Left;
this.AllowDrop = true;
DesignerProperties.SetIsInDesignMode(this, true);
_eatAllHitTestRequests = new EatAllHitTestRequests();
_eatAllHitTestRequests.AllowDrop = true;
_adornerLayer = new AdornerLayer(this);
_markerCanvas = new Canvas();
_markerCanvas.IsHitTestVisible = false;
@ -170,10 +172,6 @@ namespace ICSharpCode.WpfDesign.Designer @@ -170,10 +172,6 @@ namespace ICSharpCode.WpfDesign.Designer
}
}
public Canvas MarkerCanvas {
get { return _markerCanvas; }
}
/// <summary>
/// Gets/Sets if the design content is visible for hit-testing purposes.
/// </summary>

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

@ -40,54 +40,58 @@ namespace ICSharpCode.WpfDesign.Designer @@ -40,54 +40,58 @@ namespace ICSharpCode.WpfDesign.Designer
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, OnUndoExecuted, OnUndoCanExecute));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, OnRedoExecuted, OnRedoCanExecute));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, OnDeleteExecuted, OnDeleteCanExecute));
}
#region Undo/Redo
UndoService _undoService;
private UndoService UndoService {
get { return _undoService; }
set {
if (_undoService != null) {
_undoService.UndoStackChanged -= OnUndoStackChanged;
}
_undoService = value;
if (_undoService != null) {
_undoService.UndoStackChanged += OnUndoStackChanged;
}
CommandManager.InvalidateRequerySuggested();
}
T GetService<T>() where T : class
{
if (_designContext != null)
return _designContext.Services.GetService<T>();
else
return null;
}
#region Command: Undo/Redo
void OnUndoExecuted(object sender, ExecutedRoutedEventArgs e)
{
IUndoAction action = Func.First(_undoService.UndoActions);
UndoService undoService = GetService<UndoService>();
IUndoAction action = Func.First(undoService.UndoActions);
Debug.WriteLine("Undo " + action.Title);
_undoService.Undo();
undoService.Undo();
_designContext.Services.Selection.SetSelectedComponents(action.AffectedElements);
}
void OnUndoCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = _undoService != null && _undoService.CanUndo;
UndoService undoService = GetService<UndoService>();
e.CanExecute = undoService != null && undoService.CanUndo;
}
void OnRedoExecuted(object sender, ExecutedRoutedEventArgs e)
{
IUndoAction action = Func.First(_undoService.RedoActions);
UndoService undoService = GetService<UndoService>();
IUndoAction action = Func.First(undoService.RedoActions);
Debug.WriteLine("Redo " + action.Title);
_undoService.Redo();
undoService.Redo();
_designContext.Services.Selection.SetSelectedComponents(action.AffectedElements);
}
void OnRedoCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = _undoService != null && _undoService.CanRedo;
UndoService undoService = GetService<UndoService>();
e.CanExecute = undoService != null && undoService.CanRedo;
}
#endregion
void OnUndoStackChanged(object sender, EventArgs e)
#region Command: Delete
void OnDeleteExecuted(object sender, ExecutedRoutedEventArgs e)
{
CommandManager.InvalidateRequerySuggested();
}
void OnDeleteCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
}
#endregion
@ -125,7 +129,13 @@ namespace ICSharpCode.WpfDesign.Designer @@ -125,7 +129,13 @@ namespace ICSharpCode.WpfDesign.Designer
designPanelBorder.Padding = new Thickness(10);
_designPanel.Child = designPanelBorder;
designPanelBorder.Child = context.RootItem.View;
UndoService = context.Services.GetService<UndoService>();
context.Services.RunWhenAvailable<UndoService>(
delegate (UndoService undoService) {
CommandManager.InvalidateRequerySuggested();
});
context.Services.Selection.SelectionChanged += delegate {
CommandManager.InvalidateRequerySuggested();
};
}
/// <summary>
@ -133,12 +143,16 @@ namespace ICSharpCode.WpfDesign.Designer @@ -133,12 +143,16 @@ namespace ICSharpCode.WpfDesign.Designer
/// </summary>
public void UnloadDesigner()
{
if (_designContext != null) {
foreach (object o in _designContext.Services.AllServices) {
IDisposable d = o as IDisposable;
if (d != null) d.Dispose();
}
}
_designContext = null;
_designPanel.Context = null;
_designPanel.Child = null;
_designPanel.Adorners.Clear();
_designPanel.MarkerCanvas.Children.Clear();
UndoService = null;
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/CanvasChildResizeSupport.cs

@ -34,7 +34,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -34,7 +34,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <inherits/>
public bool CanPlace(ICollection<DesignItem> child, PlacementType type, PlacementAlignment position)
{
return type == PlacementType.Resize || type == PlacementType.Move;
return type == PlacementType.Resize || type == PlacementType.Move || type == PlacementType.Delete;
}
/// <inherits/>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelSelectionHandler.cs

@ -54,7 +54,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -54,7 +54,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
this.positionRelativeTo = container.View;
}
protected override void OnDragStarted()
protected override void OnDragStarted(MouseEventArgs e)
{
adornerPanel = new AdornerPanel();
adornerPanel.SetAdornedElement(container.View, container);

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ClickOrDragMouseGesture.cs

@ -34,9 +34,11 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -34,9 +34,11 @@ namespace ICSharpCode.WpfDesign.Designer.Services
{
if (!hasDragStarted) {
Vector v = e.GetPosition(positionRelativeTo) - startPoint;
if (v.LengthSquared >= MinimumDragDistance * MinimumDragDistance) {
if (Math.Abs(v.X) >= SystemParameters.MinimumHorizontalDragDistance
|| Math.Abs(v.Y) >= SystemParameters.MinimumVerticalDragDistance)
{
hasDragStarted = true;
OnDragStarted();
OnDragStarted(e);
}
}
}
@ -46,6 +48,6 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -46,6 +48,6 @@ namespace ICSharpCode.WpfDesign.Designer.Services
hasDragStarted = false;
}
protected virtual void OnDragStarted() {}
protected virtual void OnDragStarted(MouseEventArgs e) {}
}
}

182
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs

@ -0,0 +1,182 @@ @@ -0,0 +1,182 @@
// <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.Windows;
using System;
using System.Diagnostics;
using System.Windows.Input;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Services
{
/// <summary>
/// A tool that creates a component when used.
/// </summary>
public class CreateComponentTool : ITool
{
readonly Type componentType;
/// <summary>
/// Creates a new CreateComponentTool instance.
/// </summary>
public CreateComponentTool(Type componentType)
{
if (componentType == null)
throw new ArgumentNullException("componentType");
this.componentType = componentType;
}
/// <summary>
/// Gets the type of the component to be created.
/// </summary>
public Type ComponentType {
get { return componentType; }
}
/// <inherits/>
public Cursor Cursor {
get { return null; }
}
/// <inherits/>
public void Activate(IDesignPanel designPanel)
{
designPanel.MouseDown += OnMouseDown;
designPanel.DragOver += OnDragOver;
designPanel.Drop += OnDrop;
}
/// <inherits/>
public void Deactivate(IDesignPanel designPanel)
{
designPanel.MouseDown -= OnMouseDown;
designPanel.DragOver -= OnDragOver;
designPanel.Drop -= OnDrop;
}
/// <summary>
/// Is called to create the item used by the CreateComponentTool.
/// </summary>
protected virtual DesignItem CreateItem(DesignContext context)
{
object newInstance = Activator.CreateInstance(componentType);
return context.Services.Component.RegisterComponentForDesigner(newInstance);
}
void OnDragOver(object sender, DragEventArgs e)
{
if (e.Data.GetData(typeof(CreateComponentTool)) == this) {
e.Effects = DragDropEffects.Copy;
e.Handled = true;
} else {
e.Effects = DragDropEffects.None;
}
}
void OnDrop(object sender, DragEventArgs e)
{
if (e.Data.GetData(typeof(CreateComponentTool)) != this)
return;
e.Handled = true;
MessageBox.Show("Not implemented");
}
void OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) {
e.Handled = true;
IDesignPanel designPanel = (IDesignPanel)sender;
DesignPanelHitTestResult result = designPanel.HitTest(e, false, true);
if (result.ModelHit != null) {
IPlacementBehavior behavior = result.ModelHit.GetBehavior<IPlacementBehavior>();
if (behavior != null) {
// ensure the design panel has the focus - otherwise pressing Escape to abort creating doesn't work
designPanel.Focus();
DesignItem createdItem = CreateItem(designPanel.Context);
new CreateComponentMouseGesture(result.ModelHit, createdItem).Start(designPanel, e);
}
}
}
}
}
sealed class CreateComponentMouseGesture : ClickOrDragMouseGesture
{
DesignItem createdItem;
PlacementOperation operation;
DesignItem container;
public CreateComponentMouseGesture(DesignItem clickedOn, DesignItem createdItem)
{
this.container = clickedOn;
this.createdItem = createdItem;
this.positionRelativeTo = clickedOn.View;
}
// GrayOutDesignerExceptActiveArea grayOut;
// SelectionFrame frame;
// AdornerPanel adornerPanel;
Rect GetStartToEndRect(MouseEventArgs e)
{
Point endPoint = e.GetPosition(positionRelativeTo);
return new Rect(
Math.Min(startPoint.X, endPoint.X),
Math.Min(startPoint.Y, endPoint.Y),
Math.Abs(startPoint.X - endPoint.X),
Math.Abs(startPoint.Y - endPoint.Y)
);
}
protected override void OnDragStarted(MouseEventArgs e)
{
operation = PlacementOperation.TryStartInsertNewComponents(container,
new DesignItem[] { createdItem },
new Rect[] { GetStartToEndRect(e) },
PlacementType.Resize);
if (operation != null) {
services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
}
}
protected override void OnMouseMove(object sender, MouseEventArgs e)
{
base.OnMouseMove(sender, e);
if (operation != null) {
foreach (PlacementInformation info in operation.PlacedItems) {
info.Bounds = GetStartToEndRect(e);
operation.CurrentContainerBehavior.SetPosition(info);
}
}
}
protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (hasDragStarted) {
if (operation != null) {
operation.Commit();
operation = null;
}
} else {
}
base.OnMouseUp(sender, e);
}
protected override void OnStopped()
{
if (operation != null) {
operation.Abort();
operation = null;
}
base.OnStopped();
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/DragMoveMouseGesture.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -19,7 +19,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
/// </summary>
sealed class DragMoveMouseGesture : ClickOrDragMouseGesture
{
DesignItem clickedOn;
readonly DesignItem clickedOn;
PlacementOperation operation;
ICollection<DesignItem> selectedItems;
@ -39,7 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -39,7 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
selectedItems = new DesignItem[0];
}
protected override void OnDragStarted()
protected override void OnDragStarted(MouseEventArgs e)
{
IPlacementBehavior b = PlacementOperation.GetPlacementBehavior(selectedItems);
if (b != null && b.CanPlace(selectedItems, PlacementType.Move, PlacementAlignments.TopLeft)) {

114
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs

@ -0,0 +1,114 @@ @@ -0,0 +1,114 @@
// <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.Diagnostics;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Services
{
/// <summary>
/// Base class for classes handling mouse gestures on the design surface.
/// </summary>
abstract class MouseGestureBase
{
/// <summary>
/// Checks if <paramref name="button"/> is the only button that is currently pressed.
/// </summary>
internal static bool IsOnlyButtonPressed(MouseEventArgs e, MouseButton button)
{
return e.LeftButton == (button == MouseButton.Left ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.MiddleButton == (button == MouseButton.Middle ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.RightButton == (button == MouseButton.Right ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.XButton1 == (button == MouseButton.XButton1 ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.XButton2 == (button == MouseButton.XButton2 ? MouseButtonState.Pressed : MouseButtonState.Released);
}
protected IDesignPanel designPanel;
protected ServiceContainer services;
protected bool canAbortWithEscape = true;
bool isStarted;
public void Start(IDesignPanel designPanel, MouseButtonEventArgs e)
{
if (designPanel == null)
throw new ArgumentNullException("designPanel");
if (e == null)
throw new ArgumentNullException("e");
if (isStarted)
throw new InvalidOperationException("Gesture already was started");
isStarted = true;
this.designPanel = designPanel;
this.services = designPanel.Context.Services;
designPanel.IsAdornerLayerHitTestVisible = false;
if (designPanel.CaptureMouse()) {
RegisterEvents();
OnStarted(e);
} else {
Stop();
}
}
void RegisterEvents()
{
designPanel.LostMouseCapture += OnLostMouseCapture;
designPanel.MouseDown += OnMouseDown;
designPanel.MouseMove += OnMouseMove;
designPanel.MouseUp += OnMouseUp;
designPanel.KeyDown += OnKeyDown;
}
void UnRegisterEvents()
{
designPanel.LostMouseCapture -= OnLostMouseCapture;
designPanel.MouseDown -= OnMouseDown;
designPanel.MouseMove -= OnMouseMove;
designPanel.MouseUp -= OnMouseUp;
designPanel.KeyDown -= OnKeyDown;
}
void OnKeyDown(object sender, KeyEventArgs e)
{
if (canAbortWithEscape && e.Key == Key.Escape) {
e.Handled = true;
Stop();
}
}
void OnLostMouseCapture(object sender, MouseEventArgs e)
{
Stop();
}
protected virtual void OnMouseDown(object sender, MouseButtonEventArgs e)
{
}
protected virtual void OnMouseMove(object sender, MouseEventArgs e)
{
}
protected virtual void OnMouseUp(object sender, MouseButtonEventArgs e)
{
Stop();
}
protected void Stop()
{
if (!isStarted) return;
isStarted = false;
designPanel.ReleaseMouseCapture();
UnRegisterEvents();
designPanel.IsAdornerLayerHitTestVisible = true;
OnStopped();
}
protected virtual void OnStarted(MouseButtonEventArgs e) {}
protected virtual void OnStopped() {}
}
}

52
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/PointerTool.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// <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.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Services
{
sealed class PointerTool : ITool
{
internal static readonly PointerTool Instance = new PointerTool();
public Cursor Cursor {
get { return null; }
}
public void Activate(IDesignPanel designPanel)
{
designPanel.MouseDown += OnMouseDown;
}
public void Deactivate(IDesignPanel designPanel)
{
designPanel.MouseDown -= OnMouseDown;
}
void OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) {
e.Handled = true;
IDesignPanel designPanel = (IDesignPanel)sender;
DesignPanelHitTestResult result = designPanel.HitTest(e, false, true);
if (result.ModelHit != null) {
IHandlePointerToolMouseDown b = result.ModelHit.GetBehavior<IHandlePointerToolMouseDown>();
if (b != null) {
b.HandleSelectionMouseDown(designPanel, e, result);
} else {
ISelectionService selectionService = designPanel.Context.Services.Selection;
selectionService.SetSelectedComponents(new DesignItem[] { result.ModelHit }, SelectionTypes.Auto);
if (selectionService.IsComponentSelected(result.ModelHit)) {
new DragMoveMouseGesture(result.ModelHit).Start(designPanel, e);
}
}
}
}
}
}
}

163
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/ToolService.cs

@ -11,15 +11,14 @@ using System.Windows.Input; @@ -11,15 +11,14 @@ using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Services
{
// See IToolService for description.
sealed class DefaultToolService : IToolService
sealed class DefaultToolService : IToolService, IDisposable
{
PointerTool _pointerTool;
ITool _currentTool;
IDesignPanel _designPanel;
public DefaultToolService(DesignContext context)
{
_currentTool = _pointerTool = new PointerTool();
_currentTool = this.PointerTool;
context.Services.RunWhenAvailable<IDesignPanel>(
delegate(IDesignPanel designPanel) {
_designPanel = designPanel;
@ -27,8 +26,16 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -27,8 +26,16 @@ namespace ICSharpCode.WpfDesign.Designer.Services
});
}
public void Dispose()
{
if (_designPanel != null) {
_currentTool.Deactivate(_designPanel);
_designPanel = null;
}
}
public ITool PointerTool {
get { return _pointerTool; }
get { return Services.PointerTool.Instance; }
}
public ITool CurrentTool {
@ -37,149 +44,19 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -37,149 +44,19 @@ namespace ICSharpCode.WpfDesign.Designer.Services
if (value == null)
throw new ArgumentNullException("value");
if (_currentTool == value) return;
_currentTool.Deactivate(_designPanel);
if (_designPanel != null) {
_currentTool.Deactivate(_designPanel);
}
_currentTool = value;
_currentTool.Activate(_designPanel);
}
}
}
sealed class PointerTool : ITool
{
public Cursor Cursor {
get { return null; }
}
public void Activate(IDesignPanel designPanel)
{
designPanel.MouseDown += OnMouseDown;
}
public void Deactivate(IDesignPanel designPanel)
{
designPanel.MouseDown -= OnMouseDown;
}
void OnMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left && MouseGestureBase.IsOnlyButtonPressed(e, MouseButton.Left)) {
e.Handled = true;
IDesignPanel designPanel = (IDesignPanel)sender;
DesignPanelHitTestResult result = designPanel.HitTest(e, false, true);
if (result.ModelHit != null) {
IHandlePointerToolMouseDown b = result.ModelHit.GetBehavior<IHandlePointerToolMouseDown>();
if (b != null) {
b.HandleSelectionMouseDown(designPanel, e, result);
} else {
ISelectionService selectionService = designPanel.Context.Services.Selection;
selectionService.SetSelectedComponents(new DesignItem[] { result.ModelHit }, SelectionTypes.Auto);
if (selectionService.IsComponentSelected(result.ModelHit)) {
new DragMoveMouseGesture(result.ModelHit).Start(designPanel, e);
}
}
if (_designPanel != null) {
_currentTool.Activate(_designPanel);
}
if (CurrentToolChanged != null) {
CurrentToolChanged(this, EventArgs.Empty);
}
}
}
}
/// <summary>
/// Base class for classes handling mouse gestures on the design surface.
/// </summary>
abstract class MouseGestureBase
{
/// <summary>
/// Checks if <paramref name="button"/> is the only button that is currently pressed.
/// </summary>
internal static bool IsOnlyButtonPressed(MouseEventArgs e, MouseButton button)
{
return e.LeftButton == (button == MouseButton.Left ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.MiddleButton == (button == MouseButton.Middle ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.RightButton == (button == MouseButton.Right ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.XButton1 == (button == MouseButton.XButton1 ? MouseButtonState.Pressed : MouseButtonState.Released)
&& e.XButton2 == (button == MouseButton.XButton2 ? MouseButtonState.Pressed : MouseButtonState.Released);
}
protected IDesignPanel designPanel;
protected ServiceContainer services;
protected bool canAbortWithEscape = true;
bool isStarted;
public void Start(IDesignPanel designPanel, MouseButtonEventArgs e)
{
if (designPanel == null)
throw new ArgumentNullException("designPanel");
if (e == null)
throw new ArgumentNullException("e");
if (isStarted)
throw new InvalidOperationException("Gesture already was started");
isStarted = true;
this.designPanel = designPanel;
this.services = designPanel.Context.Services;
designPanel.IsAdornerLayerHitTestVisible = false;
if (designPanel.CaptureMouse()) {
RegisterEvents();
OnStarted(e);
} else {
Stop();
}
}
void RegisterEvents()
{
designPanel.LostMouseCapture += OnLostMouseCapture;
designPanel.MouseDown += OnMouseDown;
designPanel.MouseMove += OnMouseMove;
designPanel.MouseUp += OnMouseUp;
designPanel.KeyDown += OnKeyDown;
}
void UnRegisterEvents()
{
designPanel.LostMouseCapture -= OnLostMouseCapture;
designPanel.MouseDown -= OnMouseDown;
designPanel.MouseMove -= OnMouseMove;
designPanel.MouseUp -= OnMouseUp;
designPanel.KeyDown -= OnKeyDown;
}
void OnKeyDown(object sender, KeyEventArgs e)
{
if (canAbortWithEscape && e.Key == Key.Escape) {
e.Handled = true;
Stop();
}
}
void OnLostMouseCapture(object sender, MouseEventArgs e)
{
Stop();
}
protected virtual void OnMouseDown(object sender, MouseButtonEventArgs e)
{
}
protected virtual void OnMouseMove(object sender, MouseEventArgs e)
{
}
protected virtual void OnMouseUp(object sender, MouseButtonEventArgs e)
{
Stop();
}
protected void Stop()
{
if (!isStarted) return;
isStarted = false;
designPanel.ReleaseMouseCapture();
UnRegisterEvents();
designPanel.IsAdornerLayerHitTestVisible = true;
OnStopped();
}
protected virtual void OnStarted(MouseButtonEventArgs e) {}
protected virtual void OnStopped() {}
public event EventHandler CurrentToolChanged;
}
}

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

@ -83,9 +83,12 @@ @@ -83,9 +83,12 @@
<Compile Include="Func.cs" />
<Compile Include="ServiceRequiredException.cs" />
<Compile Include="Services\ClickOrDragMouseGesture.cs" />
<Compile Include="Services\CreateComponentTool.cs" />
<Compile Include="Services\DragMoveMouseGesture.cs" />
<Compile Include="Services\ErrorService.cs" />
<Compile Include="Services\MouseGestureBase.cs" />
<Compile Include="Services\OptionService.cs" />
<Compile Include="Services\PointerTool.cs" />
<Compile Include="Services\SelectionService.cs" />
<Compile Include="Services\ToolService.cs" />
<Compile Include="Services\UndoService.cs" />

32
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs

@ -39,8 +39,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -39,8 +39,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
}
public event EventHandler<DesignItemEventArgs> ComponentRegistered;
public event EventHandler<DesignItemEventArgs> ComponentUnregistered;
// TODO: this must not be a dictionary because there's no way to unregister components
// however, this isn't critical because our design items will stay alive for the lifetime of the
// designer anyway if we don't limit the Undo stack.
Dictionary<object, XamlDesignItem> _sites = new Dictionary<object, XamlDesignItem>(IdentityEqualityComparer.Instance);
public DesignItem GetDesignItem(object component)
@ -62,23 +64,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -62,23 +64,10 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
XamlDesignItem item = new XamlDesignItem(_context.Document.CreateObject(component), _context);
_sites.Add(component, item);
return item;
}
/// <summary>
/// currently for use by UnregisterAllComponents only because it doesn't update the XAML
/// </summary>
void UnregisterComponentFromDesigner(DesignItem site)
{
if (site == null)
throw new ArgumentNullException("site");
if (!_sites.Remove(site.Component))
throw new ArgumentException("The site was not registered here!");
if (ComponentUnregistered != null) {
ComponentUnregistered(this, new DesignItemEventArgs(site));
if (ComponentRegistered != null) {
ComponentRegistered(this, new DesignItemEventArgs(item));
}
return item;
}
/// <summary>
@ -102,14 +91,5 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -102,14 +91,5 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
}
return site;
}
/// <summary>
/// unregisters all components
/// </summary>
internal void UnregisterAllComponents()
{
Array.ForEach(Func.ToArray(_sites.Values), UnregisterComponentFromDesigner);
_sites.Clear();
}
}
}

4
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTestHelper.cs

@ -31,12 +31,12 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -31,12 +31,12 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
{
log = new StringBuilder();
XamlDesignContext context = new XamlDesignContext(new XmlTextReader(new StringReader(xaml)));
context.Services.Component.ComponentRegistered += delegate(object sender, DesignItemEventArgs e) {
/*context.Services.Component.ComponentRegistered += delegate(object sender, DesignItemEventArgs e) {
log.AppendLine("Register " + ItemIdentity(e.Item));
};
context.Services.Component.ComponentUnregistered += delegate(object sender, DesignItemEventArgs e) {
log.AppendLine("Unregister " + ItemIdentity(e.Item));
};
};*/
return context;
}

28
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

@ -111,6 +111,34 @@ namespace ICSharpCode.WpfDesign.Tests.Designer @@ -111,6 +111,34 @@ namespace ICSharpCode.WpfDesign.Tests.Designer
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasEmptyImplicitPanelChildrenCollection()
{
DesignItem canvas = CreateCanvasContext("<Canvas></Canvas>");
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("<Canvas>\n" +
" <Panel.Children>\n" +
" <TextBox />\n" +
" </Panel.Children>\n" +
"</Canvas>", canvas.Context);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasEmptyImplicitPanelChildrenCollectionEmptyTag()
{
DesignItem canvas = CreateCanvasContext("<Canvas/>");
DesignItem textBox = canvas.Services.Component.RegisterComponentForDesigner(new TextBox());
canvas.Properties["Children"].CollectionElements.Add(textBox);
AssertCanvasDesignerOutput("<Canvas>\n" +
" <Panel.Children>\n" +
" <TextBox />\n" +
" </Panel.Children>\n" +
"</Canvas>", canvas.Context);
AssertLog("");
}
[Test]
public void AddTextBoxToCanvasEmptyExplicitPanelChildrenCollection()
{

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlParser.cs

@ -187,7 +187,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -187,7 +187,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
if (defaultProperty != null && defaultProperty.IsCollection && !element.IsEmpty) {
defaultPropertyValue = defaultProperty.GetValue(instance);
obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty, null));
obj.AddProperty(defaultCollectionProperty = new XamlProperty(obj, defaultProperty));
}
foreach (XmlNode childNode in GetNormalizedChildNodes(element)) {
@ -202,6 +202,9 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -202,6 +202,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
XmlElement childElement = childNode as XmlElement;
if (childElement != null) {
if (childElement.NamespaceURI == XamlConstants.XamlNamespace)
continue;
if (ObjectChildElementIsPropertyElement(childElement)) {
// I don't know why the official XamlReader runs the property getter
// here, but let's try to imitate it as good as possible
@ -431,7 +434,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -431,7 +434,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
collectionInstance = propertyInfo.GetValue(obj.Instance);
}
if (collectionProperty == null) {
obj.AddProperty(collectionProperty = new XamlProperty(obj, propertyInfo, null));
obj.AddProperty(collectionProperty = new XamlProperty(obj, propertyInfo));
}
collectionProperty.ParserSetPropertyElement(element);
}

15
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs

@ -30,18 +30,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -30,18 +30,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
// for use by parser only
internal XamlProperty(XamlObject parentObject, XamlPropertyInfo propertyInfo, XamlPropertyValue propertyValue)
: this(parentObject, propertyInfo)
{
this.parentObject = parentObject;
this.propertyInfo = propertyInfo;
this.propertyValue = propertyValue;
if (propertyValue != null) {
propertyValue.ParentProperty = this;
} else {
if (propertyInfo.IsCollection) {
isCollection = true;
collectionElements = new CollectionElementsCollection(this);
}
}
}
@ -49,7 +42,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -49,7 +42,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
this.parentObject = parentObject;
this.propertyInfo = propertyInfo;
isCollection = propertyInfo.IsCollection;
if (propertyInfo.IsCollection) {
isCollection = true;
collectionElements = new CollectionElementsCollection(this);
}
}
/// <summary>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs

@ -135,6 +135,8 @@ namespace ICSharpCode.WpfDesign @@ -135,6 +135,8 @@ namespace ICSharpCode.WpfDesign
internal void ReapplyExtensionServer(ExtensionManager extensionManager, ExtensionServer server)
{
Debug.Assert(_extensionServers != null);
for (int i = 0; i < _extensionServers.Length; i++) {
if (_extensionServers[i] == server) {
bool shouldApply = server.ShouldApplyExtensions(this);

55
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs

@ -24,8 +24,6 @@ namespace ICSharpCode.WpfDesign @@ -24,8 +24,6 @@ namespace ICSharpCode.WpfDesign
readonly ChangeGroup changeGroup;
readonly ReadOnlyCollection<PlacementInformation> placedItems;
readonly PlacementType type;
readonly DesignItem oldContainer;
readonly IPlacementBehavior oldContainerBehavior;
DesignItem currentContainer;
IPlacementBehavior currentContainerBehavior;
bool isAborted, isCommitted;
@ -155,11 +153,9 @@ namespace ICSharpCode.WpfDesign @@ -155,11 +153,9 @@ namespace ICSharpCode.WpfDesign
this.placedItems = new ReadOnlyCollection<PlacementInformation>(information);
this.type = type;
this.oldContainer = items[0].Parent;
this.oldContainerBehavior = GetPlacementBehavior(items);
this.currentContainer = items[0].Parent;
this.currentContainerBehavior = GetPlacementBehavior(items);
this.currentContainer = oldContainer;
this.currentContainerBehavior = oldContainerBehavior;
this.changeGroup = items[0].Context.OpenGroup(type.ToString(), items);
}
@ -186,6 +182,53 @@ namespace ICSharpCode.WpfDesign @@ -186,6 +182,53 @@ namespace ICSharpCode.WpfDesign
}
#endregion
#region StartInsertNewComponents
/// <summary>
/// Try to insert new components into the container.
/// </summary>
/// <param name="container">The container that should become the parent of the components.</param>
/// <param name="placedItems">The components to add to the container.</param>
/// <param name="positions">The rectangle specifying the position the element should get.</param>
/// <param name="type">The type </param>
/// <returns>The operation that inserts the new components, or null if inserting is not possible.</returns>
public static PlacementOperation TryStartInsertNewComponents(DesignItem container, IList<DesignItem> placedItems, IList<Rect> positions, PlacementType type)
{
if (container == null)
throw new ArgumentNullException("container");
if (placedItems == null)
throw new ArgumentNullException("placedItems");
if (positions == null)
throw new ArgumentNullException("positions");
if (type == null)
throw new ArgumentNullException("type");
if (placedItems.Count == 0)
throw new ArgumentException("placedItems.Count must be > 0");
if (placedItems.Count != positions.Count)
throw new ArgumentException("positions.Count must be = placedItems.Count");
DesignItem[] items = Func.ToArray(placedItems);
PlacementOperation op = new PlacementOperation(items, type);
try {
for (int i = 0; i < items.Length; i++) {
op.placedItems[i].OriginalBounds = op.placedItems[i].Bounds = positions[i];
}
op.currentContainer = container;
op.currentContainerBehavior = container.GetBehavior<IPlacementBehavior>();
if (op.currentContainerBehavior == null || !op.currentContainerBehavior.CanEnterContainer(op)) {
op.changeGroup.Abort();
return null;
}
op.currentContainerBehavior.EnterContainer(op);
} catch (Exception ex) {
Debug.WriteLine(ex.ToString());
op.changeGroup.Abort();
throw;
}
return op;
}
#endregion
#region ChangeGroup handling
/// <summary>
/// Gets/Sets the description of the underlying change group.

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementType.cs

@ -26,6 +26,12 @@ namespace ICSharpCode.WpfDesign @@ -26,6 +26,12 @@ namespace ICSharpCode.WpfDesign
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly PlacementType Move = Register("Move");
/// <summary>
/// Not a "real" placement, but deleting the element.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly PlacementType Delete = Register("Delete");
readonly string name;
private PlacementType(string name)
@ -36,6 +42,8 @@ namespace ICSharpCode.WpfDesign @@ -36,6 +42,8 @@ namespace ICSharpCode.WpfDesign
/// <summary>
/// Creates a new unique PlacementKind.
/// </summary>
/// <param name="name">The name to return from a ToString() call.
/// Note that two PlacementTypes with the same name are NOT equal!</param>
public static PlacementType Register(string name)
{
return new PlacementType(name);

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyEditor/DesignItemDataProperty.cs

@ -40,8 +40,13 @@ namespace ICSharpCode.WpfDesign.PropertyEditor @@ -40,8 +40,13 @@ namespace ICSharpCode.WpfDesign.PropertyEditor
get { return property.Name; }
}
public string Description {
get { return "Description for " + property.Name; }
public object GetDescription()
{
IPropertyDescriptionService p = ownerDataSource.DesignItem.Services.GetService<IPropertyDescriptionService>();
if (p != null)
return p.GetDescription(property);
else
return null;
}
public System.ComponentModel.TypeConverter TypeConverter {

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyEditor/IPropertyEditorDataSource.cs

@ -90,9 +90,10 @@ namespace ICSharpCode.WpfDesign.PropertyEditor @@ -90,9 +90,10 @@ namespace ICSharpCode.WpfDesign.PropertyEditor
TypeConverter TypeConverter { get; }
/// <summary>
/// Gets the description of the property.
/// Gets the description of the property. The returned object should be something that
/// can be used as Content for a WPF tooltip.
/// </summary>
string Description { get; }
object GetDescription();
/// <summary>
/// Gets/Sets if the property has been assigned a local value.

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PropertyEditor/MultiSelectionDataProperty.cs

@ -195,8 +195,9 @@ namespace ICSharpCode.WpfDesign.PropertyEditor @@ -195,8 +195,9 @@ namespace ICSharpCode.WpfDesign.PropertyEditor
get { return data[0].TypeConverter; }
}
public string Description {
get { return data[0].Description; }
public object GetDescription()
{
return data[0].GetDescription();
}
public bool CanUseCustomExpression {

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ServiceContainer.cs

@ -20,6 +20,15 @@ namespace ICSharpCode.WpfDesign @@ -20,6 +20,15 @@ namespace ICSharpCode.WpfDesign
readonly Dictionary<Type, object> _services = new Dictionary<Type, object>();
readonly Dictionary<Type, Delegate> _waitingSubscribers = new Dictionary<Type, Delegate>();
/// <summary>
/// Gets a collection of all registered services.
/// </summary>
public IEnumerable<object> AllServices {
get {
return _services.Values;
}
}
/// <summary>
/// Adds a new service to the container.
/// </summary>

22
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs

@ -42,11 +42,11 @@ namespace ICSharpCode.WpfDesign @@ -42,11 +42,11 @@ namespace ICSharpCode.WpfDesign
/// <summary>
/// Remove from the selection.
/// </summary>
Remove = 0x1,
Remove = 0x10,
/// <summary>
/// Replace the selection.
/// </summary>
Replace = 0x2
Replace = 0x20
}
/// <summary>
@ -112,13 +112,8 @@ namespace ICSharpCode.WpfDesign @@ -112,13 +112,8 @@ namespace ICSharpCode.WpfDesign
/// <summary>Registers a component for usage in the designer.</summary>
DesignItem RegisterComponentForDesigner(object component);
// /// <summary>Unregisters a component from usage in the designer.</summary>
// void UnregisterComponentFromDesigner(DesignSite site);
/// <summary>Event raised whenever a component is registered</summary>
event EventHandler<DesignItemEventArgs> ComponentRegistered;
/// <summary>Event raised whenever a component is unregistered</summary>
event EventHandler<DesignItemEventArgs> ComponentUnregistered;
}
#endregion
@ -147,6 +142,19 @@ namespace ICSharpCode.WpfDesign @@ -147,6 +142,19 @@ namespace ICSharpCode.WpfDesign
}
#endregion
#region IPropertyDescriptionService
/// <summary>
/// Used to get a description for properties.
/// </summary>
public interface IPropertyDescriptionService
{
/// <summary>
/// Gets a WPF object representing a graphical description of the property.
/// </summary>
object GetDescription(DesignItemProperty property);
}
#endregion
#region IErrorService
/// <summary>
/// Service for showing error UI.

25
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Tools.cs

@ -52,6 +52,11 @@ namespace ICSharpCode.WpfDesign @@ -52,6 +52,11 @@ namespace ICSharpCode.WpfDesign
/// Gets/Sets the currently selected tool.
/// </summary>
ITool CurrentTool { get; set; }
/// <summary>
/// Is raised when the current tool changes.
/// </summary>
event EventHandler CurrentToolChanged;
}
/// <summary>
@ -103,5 +108,25 @@ namespace ICSharpCode.WpfDesign @@ -103,5 +108,25 @@ namespace ICSharpCode.WpfDesign
/// Occurs when a mouse button is released.
/// </summary>
event MouseButtonEventHandler MouseUp;
/// <summary>
/// Occurs when a drag operation enters the design panel.
/// </summary>
event DragEventHandler DragEnter;
/// <summary>
/// Occurs when a drag operation is over the design panel.
/// </summary>
event DragEventHandler DragOver;
/// <summary>
/// Occurs when a drag operation leaves the design panel.
/// </summary>
event DragEventHandler DragLeave;
/// <summary>
/// Occurs when an element is dropped on the design panel.
/// </summary>
event DragEventHandler Drop;
}
}

Loading…
Cancel
Save