Browse Source

Merge branch 'master' of https://github.com/icsharpcode/SharpDevelop into WpfDesignerCollectionResetUndoRedoFix

Conflicts:
	src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
pull/657/head
gumme 11 years ago
parent
commit
d49a8c6dc8
  1. 7
      .gitignore
  2. 3
      samples/XamlDesigner/Document.cs
  3. 8
      samples/XamlDesigner/XamlDesigner.sln
  4. 37
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs
  5. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ContainerDragHandle.cs
  6. 74
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ControlStyles.xaml
  7. 30
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs
  8. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/PanelMoveAdorner.cs
  9. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs
  10. 74
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/DesignerThumb.cs
  11. 52
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/MultiPointThumb.cs
  12. 115
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs
  13. 52
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/ResizeThumb.cs
  14. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/RotateThumb.cs
  15. 36
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs
  16. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs
  17. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs
  18. 124
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs
  19. 173
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs
  20. 173
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs
  21. 12
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs
  22. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs
  23. 93
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs
  24. 49
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MultiPointResizeThumb.cs
  25. 8
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathContextMenu.xaml
  26. 135
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathContextMenu.xaml.cs
  27. 58
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathContextMenuExtension.cs
  28. 792
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs
  29. 148
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs
  30. 105
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs
  31. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/QuickOperationMenuExtension.cs
  32. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs
  33. 58
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs
  34. 6
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs
  35. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SkewThumbExtension.cs
  36. 137
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs
  37. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs
  38. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  39. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs
  40. 18
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs
  41. 9
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml
  42. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml.cs
  43. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/SolidBrushEditor.xaml
  44. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs
  45. 56
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs
  46. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs
  47. 25
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs
  48. 81
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MouseGestureBase.cs
  49. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs
  50. 19
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/WpfDesign.Designer.csproj
  51. 17
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Xaml/XamlComponentService.cs
  52. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs
  53. 45
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs
  54. 15
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs
  55. 1
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/WpfDesign.XamlDom.csproj
  56. 21
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs
  57. 10
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs
  58. 156
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlXmlWriter.cs
  59. 38
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DesignItem.cs
  60. 35
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemExtension.cs
  61. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs
  62. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs
  63. 14
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementType.cs
  64. 3
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Services.cs
  65. 40
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIExtensions/UIHelpers.cs
  66. 5
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj
  67. 78
      src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs
  68. 14
      src/AddIns/Misc/PackageManagement/Project/Src/PackageSourceConverter.cs
  69. 4
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs
  70. BIN
      src/AddIns/Misc/PackageManagement/RequiredLibraries/NuGet.Console.Types.dll
  71. BIN
      src/AddIns/Misc/PackageManagement/RequiredLibraries/NuGet.Core.dll
  72. BIN
      src/AddIns/Misc/PackageManagement/RequiredLibraries/NuGet.exe
  73. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs
  74. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml
  75. 21
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs
  76. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoViewModel.cs
  77. 8
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml
  78. 186
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml.cs
  79. 24
      src/Main/Base/Test/ProjectOptions/AssemblyInfoProviderTests.cs

7
.gitignore vendored

@ -23,3 +23,10 @@ bin/ @@ -23,3 +23,10 @@ bin/
/src/AddIns/Misc/PackageManagement/Packages/AvalonEdit/lib
/packages/
/src/Tools/ResGet/*.log
*.ide/
*.sdsettings
*.DotSettings.user
*.suo
.DS_Store

3
samples/XamlDesigner/Document.cs

@ -11,6 +11,7 @@ using System.Xml; @@ -11,6 +11,7 @@ using System.Xml;
using ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Designer.Services;
using System.Diagnostics;
using ICSharpCode.WpfDesign.XamlDom;
namespace ICSharpCode.XamlDesigner
{
@ -196,7 +197,7 @@ namespace ICSharpCode.XamlDesigner @@ -196,7 +197,7 @@ namespace ICSharpCode.XamlDesigner
void UpdateXaml()
{
var sb = new StringBuilder();
using (var xmlWriter = XmlWriter.Create(sb)) {
using (var xmlWriter = new XamlXmlWriter(sb)) {
DesignSurface.SaveDesigner(xmlWriter);
Text = XamlFormatter.Format(sb.ToString());
}

8
samples/XamlDesigner/XamlDesigner.sln

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 5.0
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# SharpDevelop 5.1
VisualStudioVersion = 12.0.20827.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XamlDesigner", "XamlDesigner.csproj", "{27DA2B5C-2AAA-4478-AB00-3E184273C241}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfDesign", "..\..\src\AddIns\DisplayBindings\WpfDesign\WpfDesign\Project\WpfDesign.csproj", "{66A378A1-E9F4-4AD5-8946-D0EC06C2902F}"

37
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/BasicMetadata.cs

@ -260,6 +260,11 @@ namespace ICSharpCode.WpfDesign.Designer @@ -260,6 +260,11 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.AddPopularControl(typeof(Viewbox));
Metadata.AddPopularControl(typeof(Viewport3D));
Metadata.AddPopularControl(typeof(WrapPanel));
Metadata.AddPopularControl(typeof(Line));
Metadata.AddPopularControl(typeof(Polyline));
Metadata.AddPopularControl(typeof(Ellipse));
Metadata.AddPopularControl(typeof(Rectangle));
Metadata.AddPopularControl(typeof(Path));
//Basic Metadata Size of double.NaN, means no Size should be set.
Metadata.AddDefaultSize(typeof(TextBlock), new Size(double.NaN, double.NaN));
@ -285,6 +290,38 @@ namespace ICSharpCode.WpfDesign.Designer @@ -285,6 +290,38 @@ namespace ICSharpCode.WpfDesign.Designer
Metadata.AddDefaultSize(typeof(Label), new Size(130, 120));
Metadata.AddDefaultSize(typeof(Expander), new Size(130, 120));
Metadata.AddDefaultPropertyValue(typeof(Line), Line.X1Property, 0.0);
Metadata.AddDefaultPropertyValue(typeof(Line), Line.Y1Property, 0.0);
Metadata.AddDefaultPropertyValue(typeof(Line), Line.X2Property, 20.0);
Metadata.AddDefaultPropertyValue(typeof(Line), Line.Y2Property, 20.0);
Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Line), Line.StrokeThicknessProperty, 2d);
Metadata.AddDefaultPropertyValue(typeof(Line), Line.StretchProperty, Stretch.None);
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.PointsProperty, new PointCollection() { new Point(0, 0), new Point(20, 0), new Point(20, 20) });
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.StrokeThicknessProperty, 2d);
Metadata.AddDefaultPropertyValue(typeof(Polyline), Polyline.StretchProperty, Stretch.None);
Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.PointsProperty, new PointCollection() { new Point(0, 20), new Point(20, 20), new Point(10, 0) });
Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StrokeThicknessProperty, 2d);
Metadata.AddDefaultPropertyValue(typeof(Polygon), Polygon.StretchProperty, Stretch.None);
Metadata.AddDefaultPropertyValue(typeof(Path), Path.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Path), Path.StrokeThicknessProperty, 2d);
Metadata.AddDefaultPropertyValue(typeof(Path), Path.StretchProperty, Stretch.None);
Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.FillProperty, Brushes.Transparent);
Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Rectangle), Rectangle.StrokeThicknessProperty, 2d);
Metadata.AddDefaultPropertyValue(typeof(Ellipse), Ellipse.FillProperty, Brushes.Transparent);
Metadata.AddDefaultPropertyValue(typeof(Ellipse), Ellipse.StrokeProperty, Brushes.Black);
Metadata.AddDefaultPropertyValue(typeof(Ellipse), Ellipse.StrokeThicknessProperty, 2d);
}
}
}

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

@ -27,7 +27,7 @@ using ICSharpCode.WpfDesign.Extensions; @@ -27,7 +27,7 @@ using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{

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

@ -1,4 +1,9 @@ @@ -1,4 +1,9 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls" xmlns:ControlConvertors="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls.Converters" xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters" xmlns:Widgets="http://icsharpcode.net/sharpdevelop/widgets">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls"
xmlns:ControlConvertors="clr-namespace:ICSharpCode.WpfDesign.Designer.Controls.Converters"
xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters"
xmlns:Widgets="http://icsharpcode.net/sharpdevelop/widgets">
<!--
This file contains the default styles used by the Controls in ICSharpCode.WpfDesign.Designer.Controls
-->
@ -46,11 +51,20 @@ @@ -46,11 +51,20 @@
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type Controls:ResizeThumb}">
<Style TargetType="{x:Type Controls:DesignerThumb}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:ResizeThumb}">
<Rectangle Name="thumbRectangle" SnapsToDevicePixels="True" Stroke="Black" Fill="White" RadiusX="1.414" RadiusY="1.414" />
<ControlTemplate TargetType="{x:Type Controls:DesignerThumb}">
<Grid>
<Rectangle Name="thumbRectangle" SnapsToDevicePixels="True" Stroke="Black" Fill="White" RadiusX="1.414" RadiusY="1.414" />
<Menu Height="15" HorizontalAlignment="Left" Margin="0,-19,-19,0" VerticalAlignment="Top" Width="15" BorderThickness="0" Background="Transparent" Visibility="{Binding Path=OperationMenu, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" >
<MenuItem Height="15" Width="15" Padding="0" Background="Transparent" BorderThickness="1" ItemsSource="{TemplateBinding OperationMenu}">
<MenuItem.Header>
<Path Data="M3.5,5.5 L11.5,5.5 L7.5,11 z" Fill="Black" Stroke="Gray" StrokeThickness="1" />
</MenuItem.Header>
</MenuItem>
</Menu>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPrimarySelection" Value="False">
<Setter TargetName="thumbRectangle" Property="Stroke" Value="White" />
@ -59,8 +73,58 @@ @@ -59,8 +73,58 @@
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="thumbRectangle" Property="Fill" Value="Gray" />
</Trigger>
<Trigger Property="ResizeThumbVisible" Value="False">
<Trigger Property="ThumbVisible" Value="False">
<Setter TargetName="thumbRectangle" Property="Visibility" Value="Hidden" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:PointThumb}">
<Setter Property="Foreground" Value="Black" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:PointThumb}">
<Grid Margin="-3.5,-3.5,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.Resources>
<Converters:DoubleOffsetConverter x:Key="PointOffset" Offset="3.5" />
</Grid.Resources>
<Line HorizontalAlignment="Left" VerticalAlignment="Top" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" StrokeDashArray="2 2" X1="3.5" Y1="3.5" X2="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource PointOffset}, Path=RelativeToPoint.X}" Y2="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource PointOffset}, Path=RelativeToPoint.Y}" Visibility="{Binding Path=RelativeToPoint, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" />
<Grid Width="7" Height="7" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid.Resources>
<Style TargetType="MenuItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</Grid.Resources>
<Rectangle HorizontalAlignment="Left" VerticalAlignment="Top" Width="7" Height="7" Name="thumbRectangle" SnapsToDevicePixels="True" Stroke="{TemplateBinding Foreground}" Fill="White" RadiusX="1.414" RadiusY="1.414" />
<Ellipse HorizontalAlignment="Left" VerticalAlignment="Top" Width="7" Height="7" Name="thumbElipse" Stroke="{TemplateBinding Foreground}" SnapsToDevicePixels="True" Fill="White" Visibility="Collapsed" />
<Menu Foreground="Black" Height="15" HorizontalAlignment="Left" Margin="0,-19,-19,0" VerticalAlignment="Top" Width="15" BorderThickness="0" Background="Transparent" Visibility="{Binding Path=OperationMenu, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static Converters:CollapsedWhenNull.Instance}}" >
<MenuItem RenderTransform="{TemplateBinding InnerRenderTransform}" Height="15" Width="15" Padding="0" Background="Transparent" BorderThickness="1" ItemsSource="{TemplateBinding OperationMenu}">
<MenuItem.Header>
<Path Data="M3.5,5.5 L11.5,5.5 L7.5,11 z" Fill="Black" Stroke="Gray" StrokeThickness="1" />
</MenuItem.Header>
</MenuItem>
</Menu>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPrimarySelection" Value="False">
<Setter TargetName="thumbRectangle" Property="Stroke" Value="White" />
<Setter TargetName="thumbRectangle" Property="Fill" Value="Black" />
<Setter TargetName="thumbElipse" Property="Fill" Value="Black" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="thumbRectangle" Property="Fill" Value="Gray" />
</Trigger>
<Trigger Property="IsEllipse" Value="True">
<Setter TargetName="thumbRectangle" Property="Visibility" Value="Hidden" />
<Setter TargetName="thumbElipse" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="ThumbVisible" Value="False">
<Setter TargetName="thumbRectangle" Property="Visibility" Value="Hidden" />
<Setter TargetName="thumbElipse" Property="Visibility" Value="Hidden" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

30
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/DragListener.cs

@ -23,6 +23,7 @@ using System.Text; @@ -23,6 +23,7 @@ using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Diagnostics;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
@ -35,6 +36,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -35,6 +36,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
InputManager.Current.PostProcessInput += new ProcessInputEventHandler(PostProcessInput);
}
public Transform Transform { get; set; }
public DragListener(IInputElement target)
{
Target = target;
@ -43,6 +46,21 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -43,6 +46,21 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
Target.PreviewMouseMove += Target_MouseMove;
Target.PreviewMouseLeftButtonUp += Target_MouseUp;
}
public void ExternalStart()
{
Target_MouseDown(null, null);
}
public void ExternalMouseMove(MouseEventArgs e)
{
Target_MouseMove(null, e);
}
public void ExternalStop()
{
Target_MouseUp(null, null);
}
static DragListener CurrentListener;
@ -66,6 +84,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -66,6 +84,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
DeltaDelta = new Vector();
IsDown = true;
IsCanceled = false;
if (MouseDown != null)
MouseDown(this);
}
void Target_MouseMove(object sender, MouseEventArgs e)
@ -110,6 +130,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -110,6 +130,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
}
}
public event DragHandler MouseDown;
public event DragHandler Started;
public event DragHandler Changed;
public event DragHandler Completed;
@ -123,7 +144,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -123,7 +144,14 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public bool IsCanceled { get; private set; }
public Vector Delta {
get { return CurrentPoint - StartPoint; }
get {
if (Transform != null) {
var matrix = Transform.Value;
matrix.Invert();
return matrix.Transform(CurrentPoint - StartPoint);
}
return CurrentPoint - StartPoint;
}
}
}
}

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

@ -28,7 +28,7 @@ using System.Windows.Media; @@ -28,7 +28,7 @@ using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/QuickOperationMenu.cs

@ -20,12 +20,10 @@ using System; @@ -20,12 +20,10 @@ using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Converters;
using System.Globalization;
using System.Windows.Data;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
@ -41,12 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -41,12 +39,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
}
public QuickOperationMenu()
{
scaleTransform = new ScaleTransform(1.0, 1.0);
this.LayoutTransform = scaleTransform;
}
private ScaleTransform scaleTransform;
{ }
private MenuItem _mainHeader;
@ -98,16 +91,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -98,16 +91,6 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
if (mainHeader != null) {
_mainHeader = mainHeader;
}
var surface = this.TryFindParent<DesignSurface>();
if (surface != null && surface.ZoomControl != null)
{
var bnd = new Binding("CurrentZoom") { Source = surface.ZoomControl };
bnd.Converter = InvertedZoomConverter.Instance;
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleXProperty, bnd);
BindingOperations.SetBinding(scaleTransform, ScaleTransform.ScaleYProperty, bnd);
}
}
/// <summary>

74
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/ResizeThumb.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/DesignerThumb.cs

@ -16,44 +16,52 @@ @@ -16,44 +16,52 @@
// 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.Diagnostics;
using ICSharpCode.WpfDesign.UIExtensions;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// A thumb where the look can depend on the IsPrimarySelection property.
/// </summary>
public class ResizeThumb : Thumb
public class DesignerThumb : Thumb
{
/// <summary>
/// Dependency property for <see cref="IsPrimarySelection"/>.
/// </summary>
public static readonly DependencyProperty IsPrimarySelectionProperty
= DependencyProperty.Register("IsPrimarySelection", typeof(bool), typeof(ResizeThumb));
= DependencyProperty.Register("IsPrimarySelection", typeof(bool), typeof(DesignerThumb));
/// <summary>
/// Dependency property for <see cref="IsPrimarySelection"/>.
/// </summary>
public static readonly DependencyProperty ResizeThumbVisibleProperty
= DependencyProperty.Register("ResizeThumbVisible", typeof(bool), typeof(ResizeThumb), new FrameworkPropertyMetadata(true));
public static readonly DependencyProperty ThumbVisibleProperty
= DependencyProperty.Register("ThumbVisible", typeof(bool), typeof(DesignerThumb), new FrameworkPropertyMetadata(true));
/// <summary>
/// Dependency property for <see cref="OperationMenu"/>.
/// </summary>
public static readonly DependencyProperty OperationMenuProperty =
DependencyProperty.Register("OperationMenu", typeof(Control[]), typeof(DesignerThumb), new PropertyMetadata(null));
internal PlacementAlignment Alignment;
static ResizeThumb()
static DesignerThumb()
{
//This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
//This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(typeof(ResizeThumb), new FrameworkPropertyMetadata(typeof(ResizeThumb)));
DefaultStyleKeyProperty.OverrideMetadata(typeof(DesignerThumb), new FrameworkPropertyMetadata(typeof(DesignerThumb)));
}
public void ReDraw()
{
var parent = this.TryFindParent<FrameworkElement>();
if (parent != null)
parent.InvalidateArrange();
}
/// <summary>
/// Gets/Sets if the resize thumb is attached to the primary selection.
/// </summary>
@ -65,36 +73,18 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -65,36 +73,18 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
/// <summary>
/// Gets/Sets if the resize thumb is visible.
/// </summary>
public bool ResizeThumbVisible {
get { return (bool)GetValue(ResizeThumbVisibleProperty); }
set { SetValue(ResizeThumbVisibleProperty, value); }
public bool ThumbVisible {
get { return (bool)GetValue(ThumbVisibleProperty); }
set { SetValue(ThumbVisibleProperty, value); }
}
}
/// <summary>
/// Resize thumb that automatically disappears if the adornered element is too small.
/// </summary>
sealed class ResizeThumbImpl : ResizeThumb
{
bool checkWidth, checkHeight;
internal ResizeThumbImpl(bool checkWidth, bool checkHeight)
{
Debug.Assert((checkWidth && checkHeight) == false);
this.checkWidth = checkWidth;
this.checkHeight = checkHeight;
}
protected override Size ArrangeOverride(Size arrangeBounds)
/// <summary>
/// Gets/Sets the OperationMenu.
/// </summary>
public Control[] OperationMenu
{
AdornerPanel parent = this.Parent as AdornerPanel;
if (parent != null && parent.AdornedElement != null) {
if (checkWidth)
this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Width > 14;
else if (checkHeight)
this.ResizeThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14;
}
return base.ArrangeOverride(arrangeBounds);
get { return (Control[])GetValue(OperationMenuProperty); }
set { SetValue(OperationMenuProperty, value); }
}
}
}

52
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/MultiPointThumb.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// 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.Windows;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Description of MultiPointThumb.
/// </summary>
internal sealed class MultiPointThumb : DesignerThumb
{
private int _index;
public int Index
{
get { return _index; }
set
{
_index = value;
var p = AdornerPlacement as PointTrackerPlacementSupport;
if (p != null)
p.Index = value;
}
}
private AdornerPlacement _adornerPlacement;
public AdornerPlacement AdornerPlacement
{
get { return _adornerPlacement; }
set { _adornerPlacement = value; }
}
}
}

115
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/PointThumb.cs

@ -0,0 +1,115 @@ @@ -0,0 +1,115 @@
// 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.Windows;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
using System.Windows.Data;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Description of MultiPointThumb.
/// </summary>
public class PointThumb : DesignerThumb
{
public Transform InnerRenderTransform
{
get { return (Transform)GetValue(InnerRenderTransformProperty); }
set { SetValue(InnerRenderTransformProperty, value); }
}
// Using a DependencyProperty as the backing store for InnerRenderTransform. This enables animation, styling, binding, etc...
public static readonly DependencyProperty InnerRenderTransformProperty =
DependencyProperty.Register("InnerRenderTransform", typeof(Transform), typeof(PointThumb), new PropertyMetadata(null));
public bool IsEllipse
{
get { return (bool)GetValue(IsEllipseProperty); }
set { SetValue(IsEllipseProperty, value); }
}
// Using a DependencyProperty as the backing store for IsEllipse. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsEllipseProperty =
DependencyProperty.Register("IsEllipse", typeof(bool), typeof(PointThumb), new PropertyMetadata(false));
public Point Point
{
get { return (Point)GetValue(PointProperty); }
set { SetValue(PointProperty, value); }
}
// Using a DependencyProperty as the backing store for Point. This enables animation, styling, binding, etc...
public static readonly DependencyProperty PointProperty =
DependencyProperty.Register("Point", typeof(Point), typeof(PointThumb), new PropertyMetadata(OnPointChanged));
private static void OnPointChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var pt = (PointThumb)d;
((PointPlacementSupport)pt.AdornerPlacement).p = (Point)e.NewValue;
var bndExpr = pt.GetBindingExpression(PointThumb.RelativeToPointProperty);
if (bndExpr != null)
bndExpr.UpdateTarget();
((PointThumb)d).ReDraw();
}
public Point? RelativeToPoint
{
get { return (Point?)GetValue(RelativeToPointProperty); }
set { SetValue(RelativeToPointProperty, value); }
}
// Using a DependencyProperty as the backing store for RelativeToPoint. This enables animation, styling, binding, etc...
public static readonly DependencyProperty RelativeToPointProperty =
DependencyProperty.Register("RelativeToPoint", typeof(Point?), typeof(PointThumb), new PropertyMetadata(null));
static PointThumb()
{
//This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
//This style is defined in themes\generic.xaml
DefaultStyleKeyProperty.OverrideMetadata(typeof(PointThumb), new FrameworkPropertyMetadata(typeof(PointThumb)));
}
public PointThumb(Point point)
{
this.AdornerPlacement = new PointPlacementSupport(point);
Point = point;
}
public PointThumb()
{
this.AdornerPlacement = new PointPlacementSupport(Point);
}
public AdornerPlacement AdornerPlacement { get; private set; }
private class PointPlacementSupport : AdornerPlacement
{
public Point p;
public PointPlacementSupport(Point point)
{
this.p = point;
}
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
adorner.Arrange(new Rect(p.X, p.Y, adornedElementSize.Width, adornedElementSize.Height));
}
}
}
}

52
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/ResizeThumb.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// 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.Diagnostics;
using System.Windows;
using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
/// <summary>
/// Resize thumb that automatically disappears if the adornered element is too small.
/// </summary>
public sealed class ResizeThumb : DesignerThumb
{
bool checkWidth, checkHeight;
internal ResizeThumb(bool checkWidth, bool checkHeight)
{
Debug.Assert((checkWidth && checkHeight) == false);
this.checkWidth = checkWidth;
this.checkHeight = checkHeight;
}
protected override Size ArrangeOverride(Size arrangeBounds)
{
AdornerPanel parent = this.Parent as AdornerPanel;
if (parent != null && parent.AdornedElement != null)
{
if (checkWidth)
this.ThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Width > 14;
else if (checkHeight)
this.ThumbVisible = PlacementOperation.GetRealElementSize(parent.AdornedElement).Height > 14;
}
return base.ArrangeOverride(arrangeBounds);
}
}
}

12
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/RotateThumb.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Controls/Thumbs/RotateThumb.cs

@ -17,20 +17,12 @@ @@ -17,20 +17,12 @@
// 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.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Extensions;
namespace ICSharpCode.WpfDesign.Designer.Controls
{
public class RotateThumb : ResizeThumb
public class RotateThumb : DesignerThumb
{
static RotateThumb()
{
@ -39,7 +31,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls @@ -39,7 +31,7 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
public RotateThumb()
{
this.ResizeThumbVisible = true;
this.ThumbVisible = true;
}
}
}

36
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Converters.cs

@ -131,6 +131,26 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -131,6 +131,26 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
}
}
public class CollapsedWhenNull : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
public static readonly CollapsedWhenNull Instance = new CollapsedWhenNull();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class FalseWhenNull : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]
@ -224,7 +244,21 @@ namespace ICSharpCode.WpfDesign.Designer.Converters @@ -224,7 +244,21 @@ namespace ICSharpCode.WpfDesign.Designer.Converters
throw new NotImplementedException();
}
}
public class DoubleOffsetConverter : IValueConverter
{
public double Offset { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (double)value + Offset;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (double)value - Offset;
}
}
public class BlackWhenTrue : IValueConverter
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "converter is immutable")]

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

@ -32,7 +32,7 @@ using System.Windows.Threading; @@ -32,7 +32,7 @@ using System.Windows.Threading;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Extensions;
using System.Linq;
@ -511,7 +511,7 @@ namespace ICSharpCode.WpfDesign.Designer @@ -511,7 +511,7 @@ namespace ICSharpCode.WpfDesign.Designer
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#region ContextMenu
private Dictionary<ContextMenu, Tuple<int,List<object>>> contextMenusAndEntries = new Dictionary<ContextMenu, Tuple<int,List<object>>>();

10
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs

@ -87,8 +87,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -87,8 +87,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public virtual void SetPosition(PlacementInformation info)
{
if (info.Operation.Type != PlacementType.Move)
if (info.Operation.Type != PlacementType.Move && info.Operation.Type != PlacementType.MovePoint)
ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
//if (info.Operation.Type == PlacementType.MovePoint)
// ModelTools.Resize(info.Item, info.Bounds.Width, info.Bounds.Height);
}
public virtual bool CanLeaveContainer(PlacementOperation operation)
@ -172,5 +175,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -172,5 +175,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
}
public virtual Point PlacePoint(Point point)
{
return new Point(Math.Round(point.X), Math.Round(point.Y));
}
}
}

124
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawLineExtension.cs

@ -0,0 +1,124 @@ @@ -0,0 +1,124 @@
// 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.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(Canvas))]
[ExtensionFor(typeof(Grid))]
public class DrawLineExtension : BehaviorExtension, IDrawItemExtension
{
private ChangeGroup changeGroup;
DesignItem CreateItem(DesignContext context, Type componentType)
{
object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null);
DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance);
changeGroup = item.OpenGroup("Draw Line");
context.Services.ExtensionManager.ApplyDefaultInitializers(item);
return item;
}
#region IDrawItemBehavior implementation
public bool CanItemBeDrawn(Type createItemType)
{
return createItemType == typeof(Line);
}
public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e)
{
var createdItem = CreateItem(panel.Context, createItemType);
var startPoint = e.GetPosition(clickedOn.View);
var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn,
new DesignItem[] { createdItem },
new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) },
PlacementType.AddItem);
if (operation != null) {
createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
operation.Commit();
}
createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black);
createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
var lineHandler = createdItem.Extensions.OfType<LineHandlerExtension>().First();
lineHandler.DragListener.ExternalStart();
new DrawLineMouseGesture(lineHandler, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e);
}
#endregion
sealed class DrawLineMouseGesture : ClickOrDragMouseGesture
{
private LineHandlerExtension l;
private ChangeGroup changeGroup;
public DrawLineMouseGesture(LineHandlerExtension l, IInputElement relativeTo, ChangeGroup changeGroup)
{
this.l = l;
this.positionRelativeTo = relativeTo;
this.changeGroup = changeGroup;
}
protected override void OnMouseMove(object sender, MouseEventArgs e)
{
base.OnMouseMove(sender, e);
l.DragListener.ExternalMouseMove(e);
}
protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
{
l.DragListener.ExternalStop();
if (changeGroup != null)
{
changeGroup.Commit();
changeGroup = null;
}
base.OnMouseUp(sender, e);
}
protected override void OnStopped()
{
if (changeGroup != null)
{
changeGroup.Abort();
changeGroup = null;
}
if (services.Tool.CurrentTool is CreateComponentTool)
{
services.Tool.CurrentTool = services.Tool.PointerTool;
}
base.OnStopped();
}
}
}
}

173
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPathExtension.cs

@ -0,0 +1,173 @@ @@ -0,0 +1,173 @@
// 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.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(Canvas))]
[ExtensionFor(typeof(Grid))]
public class DrawPathExtension : BehaviorExtension, IDrawItemExtension
{
private ChangeGroup changeGroup;
DesignItem CreateItem(DesignContext context, Type componentType)
{
object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null);
DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance);
changeGroup = item.OpenGroup("Draw Path");
context.Services.ExtensionManager.ApplyDefaultInitializers(item);
return item;
}
#region IDrawItemBehavior implementation
public bool CanItemBeDrawn(Type createItemType)
{
return createItemType == typeof(Path);
}
public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e)
{
var createdItem = CreateItem(panel.Context, createItemType);
var startPoint = e.GetPosition(clickedOn.View);
var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn,
new DesignItem[] { createdItem },
new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) },
PlacementType.AddItem);
if (operation != null) {
createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
operation.Commit();
}
createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black);
createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
var figure = new PathFigure();
var geometry = new PathGeometry();
var geometryDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(geometry);
var figureDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(figure);
createdItem.Properties[Path.DataProperty].SetValue(geometry);
//geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem);
figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0));
new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup, this.ExtendedItem.GetCompleteAppliedTransformationToView()).Start(panel, (MouseButtonEventArgs) e);
}
#endregion
sealed class DrawPathMouseGesture : ClickOrDragMouseGesture
{
private ChangeGroup changeGroup;
private DesignItem newLine;
private Point sP;
private PathFigure figure;
private DesignItem geometry;
private Matrix matrix;
public DrawPathMouseGesture(PathFigure figure, DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup, Transform transform)
{
this.newLine = newLine;
this.positionRelativeTo = relativeTo;
this.changeGroup = changeGroup;
this.figure = figure;
this.matrix = transform.Value;
matrix.Invert();
sP = Mouse.GetPosition(null);
geometry = newLine.Properties[Path.DataProperty].Value;
}
protected override void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
base.OnPreviewMouseLeftButtonDown(sender, e);
}
protected override void OnMouseMove(object sender, MouseEventArgs e)
{
var delta = matrix.Transform(e.GetPosition(null) - sP);
var point = new Point(Math.Round(delta.X, 0), Math.Round(delta.Y, 0));
var segment = figure.Segments.LastOrDefault() as LineSegment;
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
if (segment == null || segment.Point != point)
{
figure.Segments.Add(new LineSegment(point, false));
segment = figure.Segments.Last() as LineSegment;}
}
segment.Point = point;
geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString());
}
protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
{
var delta = matrix.Transform(e.GetPosition(null) - sP);
var point = new Point(Math.Round(delta.X, 0), Math.Round(delta.Y,0));
figure.Segments.Add(new LineSegment(point, false));
geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString());
}
protected override void OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(sender, e);
figure.Segments.RemoveAt(figure.Segments.Count - 1);
geometry.Properties[PathGeometry.FiguresProperty].SetValue(figure.ToString());
if (changeGroup != null) {
changeGroup.Commit();
changeGroup = null;
}
Stop();
}
protected override void OnStopped()
{
if (changeGroup != null) {
changeGroup.Abort();
changeGroup = null;
}
if (services.Tool.CurrentTool is CreateComponentTool) {
services.Tool.CurrentTool = services.Tool.PointerTool;
}
newLine.ReapplyAllExtensions();
base.OnStopped();
}
}
}
}

173
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DrawPolyLineExtension.cs

@ -0,0 +1,173 @@ @@ -0,0 +1,173 @@
// 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.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer.Services;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
[ExtensionFor(typeof(Canvas))]
[ExtensionFor(typeof(Grid))]
public class DrawPolyLineExtension : BehaviorExtension, IDrawItemExtension
{
private ChangeGroup changeGroup;
DesignItem CreateItem(DesignContext context, Type componentType)
{
object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null);
DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance);
changeGroup = item.OpenGroup("Draw Polyline");
context.Services.ExtensionManager.ApplyDefaultInitializers(item);
return item;
}
#region IDrawItemBehavior implementation
public bool CanItemBeDrawn(Type createItemType)
{
return createItemType == typeof(Polyline) || createItemType == typeof(Polygon);
}
public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e)
{
var createdItem = CreateItem(panel.Context, createItemType);
var startPoint = e.GetPosition(clickedOn.View);
var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn,
new DesignItem[] { createdItem },
new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) },
PlacementType.AddItem);
if (operation != null) {
createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
operation.Commit();
}
createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black);
createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
if (createItemType == typeof(Polyline))
createdItem.Properties[Polyline.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0)));
else
createdItem.Properties[Polygon.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0,0)));
new DrawPolylineMouseGesture(createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs) e);
}
#endregion
sealed class DrawPolylineMouseGesture : ClickOrDragMouseGesture
{
private ChangeGroup changeGroup;
private DesignItem newLine;
private Point startPoint;
public DrawPolylineMouseGesture(DesignItem newLine, IInputElement relativeTo, ChangeGroup changeGroup)
{
this.newLine = newLine;
this.positionRelativeTo = relativeTo;
this.changeGroup = changeGroup;
startPoint = Mouse.GetPosition(null);
}
protected override void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
base.OnPreviewMouseLeftButtonDown(sender, e);
}
protected override void OnMouseMove(object sender, MouseEventArgs e)
{
var delta = e.GetPosition(null) - startPoint;
var point = new Point(delta.X, delta.Y);
if (newLine.View is Polyline) {
if (((Polyline)newLine.View).Points.Count <= 1)
((Polyline)newLine.View).Points.Add(point);
if (Mouse.LeftButton != MouseButtonState.Pressed)
((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1);
if (((Polyline)newLine.View).Points.Last() != point)
((Polyline)newLine.View).Points.Add(point);
} else {
if (((Polygon)newLine.View).Points.Count <= 1)
((Polygon)newLine.View).Points.Add(point);
if (Mouse.LeftButton != MouseButtonState.Pressed)
((Polygon)newLine.View).Points.RemoveAt(((Polygon)newLine.View).Points.Count - 1);
if (((Polygon)newLine.View).Points.Last() != point)
((Polygon)newLine.View).Points.Add(point);
}
}
protected override void OnMouseUp(object sender, MouseButtonEventArgs e)
{
var delta = e.GetPosition(null) - startPoint;
var point = new Point(delta.X, delta.Y);
if (newLine.View is Polyline)
((Polyline)newLine.View).Points.Add(point);
else
((Polygon)newLine.View).Points.Add(point);
}
protected override void OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
base.OnMouseDoubleClick(sender, e);
if (newLine.View is Polyline) {
((Polyline)newLine.View).Points.RemoveAt(((Polyline)newLine.View).Points.Count - 1);
newLine.Properties[Polyline.PointsProperty].SetValue(string.Join(",", ((Polyline)newLine.View).Points));
} else {
((Polygon)newLine.View).Points.RemoveAt(((Polygon)newLine.View).Points.Count - 1);
newLine.Properties[Polygon.PointsProperty].SetValue(string.Join(",", ((Polygon)newLine.View).Points));
}
if (changeGroup != null)
{
changeGroup.Commit();
changeGroup = null;
}
Stop();
}
protected override void OnStopped()
{
if (changeGroup != null) {
changeGroup.Abort();
changeGroup = null;
}
if (services.Tool.CurrentTool is CreateComponentTool) {
services.Tool.CurrentTool = services.Tool.PointerTool;
}
newLine.ReapplyAllExtensions();
base.OnStopped();
}
}
}
}

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

@ -97,16 +97,4 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers @@ -97,16 +97,4 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers
}
}
}
[ExtensionFor(typeof(Shape))]
public class ShapeInitializer : DefaultInitializer
{
public override void InitializeDefaults(DesignItem item)
{
DesignItemProperty fillProperty = item.Properties["Fill"];
if (fillProperty.ValueOnInstance == null) {
fillProperty.SetValue(Brushes.YellowGreen);
}
}
}
}

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineExtensionBase.cs

@ -73,7 +73,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -73,7 +73,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public LineExtensionBase()
{
_surface = new Canvas();
adornerPanel = new AdornerPanel();
adornerPanel = new AdornerPanel(){ MinWidth = 10, MinHeight = 10 };
adornerPanel.Order = AdornerOrder.Foreground;
adornerPanel.Children.Add(_surface);
Adorners.Add(adornerPanel);
@ -87,33 +87,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -87,33 +87,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
UpdateAdornerVisibility();
}
protected override void OnRemove()
{
this.ExtendedItem.PropertyChanged -= OnPropertyChanged;
this.Services.Selection.PrimarySelectionChanged -= OnPrimarySelectionChanged;
DependencyPropertyDescriptor.FromProperty(FrameworkElement.HeightProperty, typeof (Shape))
.RemoveValueChanged(ExtendedItem.View, (s, ev) => ResetWidthHeightProperties());
base.OnRemove();
}
protected void OnPrimarySelectionChanged(object sender, EventArgs e)
{
bool isPrimarySelection = this.Services.Selection.PrimarySelection == this.ExtendedItem;
if (isPrimarySelection)
DependencyPropertyDescriptor.FromProperty(FrameworkElement.HeightProperty, typeof (Shape))
.AddValueChanged(ExtendedItem.View, (s, ev) => ResetWidthHeightProperties());
//foreach (ResizeThumb g in adornerPanel.Children)
//{
// g.IsPrimarySelection = isPrimarySelection;
//}
}
#endregion
protected void UpdateAdornerVisibility()
{
FrameworkElement fe = this.ExtendedItem.View as FrameworkElement;
foreach (ResizeThumb r in resizeThumbs)
foreach (DesignerThumb r in resizeThumbs)
{
bool isVisible = resizeBehavior != null &&
resizeBehavior.CanPlace(extendedItemArray, PlacementType.Resize, r.Alignment);
@ -125,11 +111,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -125,11 +111,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// Places resize thumbs at their respective positions
/// and streches out thumbs which are at the center of outline to extend resizability across the whole outline
/// </summary>
/// <param name="resizeThumb"></param>
/// <param name="designerThumb"></param>
/// <param name="alignment"></param>
/// <param name="index">if using a polygon or multipoint adorner this is the index of the point in the Points array</param>
/// <returns></returns>
protected PointTrackerPlacementSupport Place(ref ResizeThumb resizeThumb, PlacementAlignment alignment, int index = -1)
protected PointTrackerPlacementSupport Place(ref DesignerThumb designerThumb, PlacementAlignment alignment, int index = -1)
{
PointTrackerPlacementSupport placement = new PointTrackerPlacementSupport(ExtendedItem.View as Shape, alignment, index);
return placement;
@ -150,20 +136,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -150,20 +136,19 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected void SetSurfaceInfo(int x, int y, string s)
{
if (_text == null)
{
_text = new TextBlock();
if (_text == null) {
_text = new TextBlock(){ FontSize = 8, FontStyle = FontStyles.Italic };
_surface.Children.Add(_text);
}
AdornerPanel ap = _surface.Parent as AdornerPanel;
_surface.Width = ap.Width;
_surface.Height = ap.Height;
_text.Text = s;
Canvas.SetLeft(_text, x);
Canvas.SetTop(_text, y);
}
protected void HideSizeAndShowHandles()
@ -194,7 +179,5 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -194,7 +179,5 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
ExtendedItem.Properties.GetProperty(FrameworkElement.HeightProperty).Reset();
ExtendedItem.Properties.GetProperty(FrameworkElement.WidthProperty).Reset();
}
}
}

93
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/LineHandlerExtension.cs

@ -17,21 +17,15 @@ @@ -17,21 +17,15 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Windows;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows;
using System.Windows.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
@ -49,18 +43,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -49,18 +43,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
//Size oldSize;
ZoomControl zoom;
protected ResizeThumb CreateThumb(PlacementAlignment alignment, Cursor cursor)
public DragListener DragListener {get; private set;}
protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor)
{
ResizeThumb resizeThumb = new ResizeThumb { Alignment = alignment, Cursor = cursor, IsPrimarySelection = true};
AdornerPanel.SetPlacement(resizeThumb, Place(ref resizeThumb, alignment));
DesignerThumb designerThumb = new DesignerThumb { Alignment = alignment, Cursor = cursor, IsPrimarySelection = true};
AdornerPanel.SetPlacement(designerThumb, Place(ref designerThumb, alignment));
adornerPanel.Children.Add(resizeThumb);
adornerPanel.Children.Add(designerThumb);
DragListener drag = new DragListener(resizeThumb);
drag.Started += drag_Started;
drag.Changed += drag_Changed;
drag.Completed += drag_Completed;
return resizeThumb;
DragListener = new DragListener(designerThumb);
DragListener.Started += drag_Started;
DragListener.Changed += drag_Changed;
DragListener.Completed += drag_Completed;
return designerThumb;
}
protected Bounds CalculateDrawing(double x, double y, double left, double top, double xleft, double xtop)
@ -95,7 +92,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -95,7 +92,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
SetSurfaceInfo(0, 0, Math.Round((180 / Math.PI) * Math.Atan2(y, x), 0).ToString());
SetSurfaceInfo(0, 3, Math.Round((180 / Math.PI) * Math.Atan2(y, x), 0).ToString());
return new Bounds { X = Math.Round(x, 1), Y = Math.Round(y, 1), Left = Math.Round(left, 1), Top = Math.Round(top, 1) };
}
@ -122,28 +119,27 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -122,28 +119,27 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
_isResizing = true;
(drag.Target as ResizeThumb).IsPrimarySelection = false;
(drag.Target as DesignerThumb).IsPrimarySelection = false;
}
protected virtual void drag_Changed(DragListener drag)
{
Line al = ExtendedItem.View as Line;
var alignment = (drag.Target as ResizeThumb).Alignment;
var alignment = (drag.Target as DesignerThumb).Alignment;
var info = operation.PlacedItems[0];
double dx = 0;
double dy = 0;
if (zoom != null)
{
if (zoom != null) {
dx = drag.Delta.X * (1 / zoom.CurrentZoom);
dy = drag.Delta.Y * (1 / zoom.CurrentZoom);
}
double top, left, x, y, xtop, xleft;
if (alignment == PlacementAlignment.TopLeft)
{
if (alignment == PlacementAlignment.TopLeft) {
//normal values
x = CurrentX2 - dx;
y = CurrentY2 - dy;
@ -154,14 +150,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -154,14 +150,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
xtop = CurrentTop + CurrentY2;
xleft = CurrentLeft + CurrentX2;
}
else
{
} else {
x = CurrentX2 + dx;
y = CurrentY2 + dy;
top = xtop = CurrentTop;
left = xleft = CurrentLeft;
}
Bounds position = CalculateDrawing(x, y, left, top, xleft, xtop);
ExtendedItem.Properties.GetProperty(Line.X1Property).SetValue(0);
@ -169,8 +164,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -169,8 +164,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
ExtendedItem.Properties.GetProperty(Line.X2Property).SetValue(position.X);
ExtendedItem.Properties.GetProperty(Line.Y2Property).SetValue(position.Y);
if (operation != null)
{
if (operation != null) {
var result = info.OriginalBounds;
result.X = position.Left;
result.Y = position.Top;
@ -180,8 +174,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -180,8 +174,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
info.Bounds = result.Round();
operation.CurrentContainerBehavior.BeforeSetPosition(operation);
operation.CurrentContainerBehavior.SetPosition(info);
// var p = operation.CurrentContainerBehavior.PlacePoint(new Point(position.X, position.Y));
// ExtendedItem.Properties.GetProperty(Line.X2Property).SetValue(p.X);
// ExtendedItem.Properties.GetProperty(Line.Y2Property).SetValue(p.Y);
}
(drag.Target as ResizeThumb).InvalidateArrange();
(drag.Target as DesignerThumb).InvalidateArrange();
ResetWidthHeightProperties();
}
@ -200,13 +199,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -200,13 +199,15 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
else
{
if (drag.IsCanceled) changeGroup.Abort();
else changeGroup.Commit();
if (drag.IsCanceled)
changeGroup.Abort();
else
changeGroup.Commit();
changeGroup = null;
}
_isResizing = false;
(drag.Target as ResizeThumb).IsPrimarySelection = true;
(drag.Target as DesignerThumb).IsPrimarySelection = true;
HideSizeAndShowHandles();
}
@ -216,34 +217,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -216,34 +217,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected override void OnInitialized()
{
base.OnInitialized();
if (ExtendedItem.Properties.GetProperty(Line.StrokeProperty).ValueOnInstance == null)
{
ExtendedItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black);
ExtendedItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
ExtendedItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
ExtendedItem.Properties.GetProperty(Line.X1Property).SetValue(0);
ExtendedItem.Properties.GetProperty(Line.Y1Property).SetValue(0);
ExtendedItem.Properties.GetProperty(Line.X2Property).SetValue(20);
ExtendedItem.Properties.GetProperty(Line.Y2Property).SetValue(20);
(ExtendedItem.View as Line).BringIntoView();
}
resizeThumbs = new ResizeThumb[]
resizeThumbs = new DesignerThumb[]
{
CreateThumb(PlacementAlignment.TopLeft, Cursors.SizeNWSE),
CreateThumb(PlacementAlignment.BottomRight, Cursors.SizeNWSE)
CreateThumb(PlacementAlignment.TopLeft, Cursors.Cross),
CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross)
};
extendedItemArray[0] = this.ExtendedItem;
Invalidate();
//ResetWidthHeightProperties();
this.ExtendedItem.PropertyChanged += OnPropertyChanged;
this.Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged;
resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
UpdateAdornerVisibility();
OnPrimarySelectionChanged(null, null);
}
#endregion

49
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/MultiPointResizeThumb.cs

@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
/*
* Created by SharpDevelop.
* User: trubra
* Date: 2014-12-22
* Time: 11:06
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Windows;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// Description of MultiPointResizeThumb.
/// </summary>
sealed class MultiPointResizeThumb: ResizeThumb
{
private int _index;
public int Index
{
get { return _index; }
set
{
_index = value;
PointTrackerPlacementSupport p = AdornerPlacement as PointTrackerPlacementSupport;
if (p != null)
p.Index = value;
}
}
public void Invalidate()
{
PointTrackerPlacementSupport p = AdornerPlacement as PointTrackerPlacementSupport;
}
private AdornerPlacement _adornerPlacement;
public AdornerPlacement AdornerPlacement
{
get { return _adornerPlacement; }
set { _adornerPlacement = value; }
}
}
}

8
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathContextMenu.xaml

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
<ContextMenu x:Class="ICSharpCode.WpfDesign.Designer.Extensions.PathContextMenu"
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="Convert To Figures" Click="Click_ConvertToFigures">
</MenuItem>
</ContextMenu>

135
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathContextMenu.xaml.cs

@ -0,0 +1,135 @@ @@ -0,0 +1,135 @@
// 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.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Designer.themes;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public partial class PathContextMenu
{
private DesignItem designItem;
public PathContextMenu(DesignItem designItem)
{
this.designItem = designItem;
SpecialInitializeComponent();
}
/// <summary>
/// Fixes InitializeComponent with multiple Versions of same Assembly loaded
/// </summary>
public void SpecialInitializeComponent()
{
if (!this._contentLoaded) {
this._contentLoaded = true;
Uri resourceLocator = new Uri(VersionedAssemblyResourceDictionary.GetXamlNameForType(this.GetType()), UriKind.Relative);
Application.LoadComponent(this, resourceLocator);
}
this.InitializeComponent();
}
void Click_ConvertToFigures(object sender, System.Windows.RoutedEventArgs e)
{
var path = this.designItem.Component as Path;
if (path.Data is StreamGeometry) {
var sg = path.Data as StreamGeometry;
var pg = sg.GetFlattenedPathGeometry();
// foreach (var g in parts) {
//
// }
var pgDes = designItem.Services.Component.RegisterComponentForDesigner(pg);
designItem.Properties[Path.DataProperty].SetValue(pgDes);
}
else if (path.Data is PathGeometry) {
var pg = path.Data as PathGeometry;
var figs = pg.Figures;
var newPg = new PathGeometry();
var newPgDes = designItem.Services.Component.RegisterComponentForDesigner(newPg);
foreach (var fig in figs) {
newPgDes.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(FigureToDesignItem(fig));
}
designItem.Properties[Path.DataProperty].SetValue(newPg);
}
}
private DesignItem FigureToDesignItem(PathFigure pf)
{
var pfDes = designItem.Services.Component.RegisterComponentForDesigner(new PathFigure());
pfDes.Properties[PathFigure.StartPointProperty].SetValue(pf.StartPoint);
pfDes.Properties[PathFigure.IsClosedProperty].SetValue(pf.IsClosed);
foreach (var s in pf.Segments) {
pfDes.Properties[PathFigure.SegmentsProperty].CollectionElements.Add(SegmentToDesignItem(s));
}
return pfDes;
}
private DesignItem SegmentToDesignItem(PathSegment s)
{
var sDes = designItem.Services.Component.RegisterComponentForDesigner(s.Clone());
if (!((PathSegment)s).IsStroked)
sDes.Properties[PathSegment.IsStrokedProperty].SetValue(((PathSegment)s).IsStroked);
if (((PathSegment)s).IsSmoothJoin)
sDes.Properties[PathSegment.IsSmoothJoinProperty].SetValue(((PathSegment)s).IsSmoothJoin);
if (s is LineSegment) {
sDes.Properties[LineSegment.PointProperty].SetValue(((LineSegment)s).Point);
} else if (s is QuadraticBezierSegment) {
sDes.Properties[QuadraticBezierSegment.Point1Property].SetValue(((QuadraticBezierSegment)s).Point1);
sDes.Properties[QuadraticBezierSegment.Point2Property].SetValue(((QuadraticBezierSegment)s).Point2);
} else if (s is BezierSegment) {
sDes.Properties[BezierSegment.Point1Property].SetValue(((BezierSegment)s).Point1);
sDes.Properties[BezierSegment.Point2Property].SetValue(((BezierSegment)s).Point2);
sDes.Properties[BezierSegment.Point3Property].SetValue(((BezierSegment)s).Point3);
} else if (s is ArcSegment) {
sDes.Properties[ArcSegment.PointProperty].SetValue(((ArcSegment)s).Point);
sDes.Properties[ArcSegment.IsLargeArcProperty].SetValue(((ArcSegment)s).IsLargeArc);
sDes.Properties[ArcSegment.RotationAngleProperty].SetValue(((ArcSegment)s).RotationAngle);
sDes.Properties[ArcSegment.SizeProperty].SetValue(((ArcSegment)s).Size);
sDes.Properties[ArcSegment.SweepDirectionProperty].SetValue(((ArcSegment)s).SweepDirection);
} else if (s is PolyLineSegment) {
sDes.Properties[PolyLineSegment.PointsProperty].SetValue(((PolyLineSegment)s).Points);
} else if (s is PolyQuadraticBezierSegment) {
sDes.Properties[PolyQuadraticBezierSegment.PointsProperty].SetValue(((PolyQuadraticBezierSegment)s).Points);
} else if (s is PolyBezierSegment) {
sDes.Properties[PolyBezierSegment.PointsProperty].SetValue(((PolyBezierSegment)s).Points);
}
return sDes;
}
}
}

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

@ -0,0 +1,58 @@ @@ -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.Shapes;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Designer;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
///
/// </summary>
[ExtensionServer(typeof(PrimarySelectionExtensionServer))]
[ExtensionFor(typeof(Path))]
[Extension(Order = 70)]
public class PathContextMenuExtension: SelectionAdornerProvider
{
DesignPanel panel;
ContextMenu contextMenu;
protected override void OnInitialized()
{
base.OnInitialized();
contextMenu = new PathContextMenu(ExtendedItem);
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
if (panel != null)
panel.AddContextMenu(contextMenu);
}
protected override void OnRemove()
{
if (panel != null)
panel.RemoveContextMenu(contextMenu);
base.OnRemove();
}
}
}

792
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PathHandlerExtension.cs

@ -0,0 +1,792 @@ @@ -0,0 +1,792 @@
// 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.Markup;
using ICSharpCode.WpfDesign.Extensions;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows;
using System.Windows.Controls;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.WpfDesign.UIExtensions;
using DragListener = ICSharpCode.WpfDesign.Designer.Controls.DragListener;
using System.Windows.Data;
using System.ComponentModel;
using System.Globalization;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// Description of PathHandlerExtension.
/// </summary>
[ExtensionFor(typeof(Path))]
internal class PathHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp
{
enum PathPartConvertType
{
insertPoint,
ToLineSegment,
ToBezierSegment,
ToQuadricBezierSegment,
ToArcSegment,
}
//A modifieable Point on the Path
protected class PathPoint : INotifyPropertyChanged
{
public PathPoint(Point point, Object @object, Object parentObject, Action<Point> setLambda, Action save, Shape shape)
{
this._point = point;
this._setLambda = setLambda;
this.Object = @object;
this.ParentObject = parentObject;
this._shape = shape;
this._save = save;
}
private Point _point;
Action<Point> _setLambda;
Action _save;
Shape _shape;
public void Commit() {
_save();
}
public Point Point
{
get { return _point; }
set {
if (_setLambda != null)
{
_point = value;
_setLambda(value);
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Point"));
PropertyChanged(this, new PropertyChangedEventArgs("TranslatedPoint"));
}
}
}
}
public Point TranslatedPoint
{
get {
if (_shape.RenderedGeometry.Transform == null)
return Point;
return _shape.RenderedGeometry.Transform.Transform(Point);
}
set {
if (_shape.RenderedGeometry.Transform == null)
Point = value;
else
Point = _shape.RenderedGeometry.Transform.Inverse.Transform(value);
}
}
public PathPoint ParentPathPoint {get; set;}
public Point ReferencePoint { get; private set; }
public object Object { get; private set; }
public object ParentObject { get; private set; }
public int PolyLineIndex { get; set; }
public PathPoint TargetPathPoint { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
}
//A Thumb wich displays the Point
protected class PathThumb : PointThumb
{
public PathThumb(int index, PathPoint pathpoint) : base()
{
this.Index = index;
this.PathPoint = pathpoint;
var bnd = new Binding("TranslatedPoint") { Source = this.PathPoint, Mode=BindingMode.OneWay };
this.SetBinding(PointProperty, bnd);
}
public int Index { get; set; }
public PathPoint PathPoint { get; set; }
}
//A Converter for the RealtiveTo Point (on PolyLineSegment, ...)
protected class RelativeToPointConverter : IValueConverter
{
PathPoint pathPoint;
public RelativeToPointConverter(PathPoint pathPoint)
{
this.pathPoint = pathPoint;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var pt = (Point)value;
return pt - new Vector(pathPoint.TranslatedPoint.X, pathPoint.TranslatedPoint.Y);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
private readonly Dictionary<int, Bounds> _selectedThumbs = new Dictionary<int, Bounds>();
private bool _isDragging;
ZoomControl _zoom;
private List<PathPoint> pathPoints = null;
protected virtual Control[] BuildMenu(PathPoint pathpoint)
{
var menuList = new List<Control>();
MenuItem menuItem = null;
if (pathpoint.TargetPathPoint == null && (pathpoint.Object is LineSegment || pathpoint.Object is PolyLineSegment || pathpoint.Object is BezierSegment || pathpoint.Object is QuadraticBezierSegment || pathpoint.Object is ArcSegment)) {
menuItem = new MenuItem() { Header = "insert Point", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.insertPoint);
menuList.Add(menuItem);
menuItem = new MenuItem() { Header = "to Line Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToLineSegment);
menuList.Add(menuItem);
menuItem = new MenuItem() {Header = "to Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToBezierSegment);
menuList.Add(menuItem);
menuItem = new MenuItem() {Header = "to Quadric Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToQuadricBezierSegment);
menuList.Add(menuItem);
menuItem = new MenuItem() { Header = "to Arc Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToArcSegment);
menuList.Add(menuItem);
menuList.Add(new Separator());
menuItem = new MenuItem() { Header = "is Stroked", IsChecked = ((PathSegment)pathpoint.Object).IsStroked, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuItem.Click += (s, e) => ChangeIsStroked(((DependencyObject)s).TryFindParent<PathThumb>(), (MenuItem)s);
menuList.Add(menuItem);
menuItem = new MenuItem() { Header = "is Smooth Join", IsChecked = ((PathSegment)pathpoint.Object).IsSmoothJoin, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuList.Add(menuItem);
}
if (pathpoint.Object is ArcSegment) {
menuItem = new MenuItem() { Header = "is large Arc", IsChecked = ((ArcSegment)pathpoint.Object).IsLargeArc, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuList.Add(menuItem);
menuItem = new MenuItem() { Header = "Rotation Angle", IsChecked = true, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuList.Add(menuItem);
menuItem = new MenuItem() { Header = "Clockwise SweepDirection", IsChecked = ((ArcSegment)pathpoint.Object).SweepDirection == SweepDirection.Clockwise, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuList.Add(menuItem);
}
if (pathpoint.Object is PathFigure) {
menuItem = new MenuItem() { Header = "is Closed", IsChecked = ((PathFigure)pathpoint.Object).IsClosed, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center };
menuItem.Click += (s, e) => ChangeIsClosed(((DependencyObject)s).TryFindParent<PathThumb>(), (MenuItem)s);
menuList.Add(menuItem);
}
if (!menuList.Any())
return null;
return menuList.ToArray();
}
#region thumb methods
protected virtual PathThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index, PathPoint pathpoint, Transform transform)
{
var designerThumb = new PathThumb(index, pathpoint) {Cursor = cursor};
designerThumb.OperationMenu = BuildMenu(pathpoint);
designerThumb.InnerRenderTransform = ((Transform)transform.Inverse);
if (pathpoint.TargetPathPoint != null) {
designerThumb.IsEllipse = true;
designerThumb.Foreground = Brushes.Blue;
var bnd = new Binding("TranslatedPoint") { Source = pathpoint.TargetPathPoint, Mode = BindingMode.OneWay, Converter = new RelativeToPointConverter(pathpoint) };
designerThumb.SetBinding(PathThumb.RelativeToPointProperty, bnd);
}
AdornerPanel.SetPlacement(designerThumb, designerThumb.AdornerPlacement);
adornerPanel.Children.Add(designerThumb);
DragListener drag = new DragListener(designerThumb);
drag.Transform = transform;
WeakEventManager<DesignerThumb, MouseButtonEventArgs>.AddHandler(designerThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp);
drag.MouseDown += drag_MouseDown;
drag.Started += drag_Started;
drag.Changed += drag_Changed;
drag.Completed += drag_Completed;
return designerThumb;
}
private void ConvertPart(PathThumb senderThumb, PathPartConvertType convertType)
{
if (senderThumb.PathPoint.ParentObject is PathFigure)
{
var pathFigure = senderThumb.PathPoint.ParentObject as PathFigure;
var pathSegment = senderThumb.PathPoint.Object as PathSegment;
var idx = pathFigure.Segments.IndexOf(pathSegment);
var point = senderThumb.PathPoint.Point;
if (pathSegment is PolyLineSegment) {
var poly = pathSegment as PolyLineSegment;
var lst = poly.Points.Take(senderThumb.PathPoint.PolyLineIndex);
var lst2 = poly.Points.Skip(senderThumb.PathPoint.PolyLineIndex + 1);
var p = poly.Points[senderThumb.PathPoint.PolyLineIndex];
pathFigure.Segments.RemoveAt(idx);
var p1 = new PolyLineSegment();
p1.Points.AddRange(lst);
pathFigure.Segments.Insert(idx, p1);
pathSegment = new LineSegment() {Point = p};
pathFigure.Segments.Insert(idx+1, pathSegment);
var p2 = new PolyLineSegment();
p2.Points.AddRange(lst2);
pathFigure.Segments.Insert(idx+2, p2);
idx++;
} else if (pathSegment is PolyBezierSegment) {
//TODO
} else if (pathSegment is PolyQuadraticBezierSegment) {
//TODO
}
pathFigure.Segments.RemoveAt(idx);
var midp = senderThumb.PathPoint.ParentPathPoint.Point - ((senderThumb.PathPoint.ParentPathPoint.Point - point) / 2);
PathSegment newSegment = null;
switch (convertType)
{
case PathPartConvertType.ToBezierSegment:
newSegment = new BezierSegment() { Point1 = midp - new Vector(40, 40), Point2 = midp + new Vector(-40, 40), Point3 = point };
break;
case PathPartConvertType.ToQuadricBezierSegment:
newSegment = new QuadraticBezierSegment() { Point1 = point - new Vector(40, 40), Point2 = point };
break;
case PathPartConvertType.ToArcSegment:
newSegment = new ArcSegment() { Point = point, Size = new Size(20, 20) };
break;
case PathPartConvertType.insertPoint:
pathFigure.Segments.Insert(idx, pathSegment);
newSegment = new LineSegment() { Point = midp, };
break;
default:
newSegment = new LineSegment() { Point = point };
break;
}
pathFigure.Segments.Insert(idx, newSegment);
}
this.ExtendedItem.ReapplyAllExtensions();
}
private void ChangeIsClosed(PathThumb senderThumb, MenuItem menuItem)
{
var figure = senderThumb.PathPoint.Object as PathFigure;
figure.IsClosed = !figure.IsClosed;
menuItem.IsChecked = figure.IsClosed;
}
private void ChangeIsStroked(PathThumb senderThumb, MenuItem menuItem)
{
var segment = senderThumb.PathPoint.Object as PathSegment;
segment.IsStroked = !segment.IsStroked;
menuItem.IsChecked = segment.IsStroked;
}
private void ResetThumbs()
{
foreach (FrameworkElement rt in adornerPanel.Children)
{
if (rt is DesignerThumb)
(rt as DesignerThumb).IsPrimarySelection = true;
}
_selectedThumbs.Clear();
}
private void SelectThumb(PathThumb mprt)
{
CommitOrAbortKeyboardOperation();
var points = GetPoints();
Point p = points[mprt.Index].TranslatedPoint;
_selectedThumbs.Add(mprt.Index, new Bounds { X = p.X, Y = p.Y });
mprt.IsPrimarySelection = false;
}
#endregion
#region eventhandlers
private void ResizeThumbOnMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
//get current thumb
var mprt = sender as PathThumb;
if (mprt != null)
{
//if not keyboard ctrl is pressed and selected point is not previously selected, clear selection
if (!_selectedThumbs.ContainsKey(mprt.Index) & !Keyboard.IsKeyDown(Key.LeftCtrl) &
!Keyboard.IsKeyDown(Key.RightCtrl))
{
ResetThumbs();
}
//add selected thumb, if ctrl pressed this could be all points in poly
if (!_selectedThumbs.ContainsKey(mprt.Index))
SelectThumb(mprt);
_isDragging = false;
}
}
protected void drag_MouseDown(DragListener drag)
{
}
// TODO : Remove all hide/show extensions from here.
protected void drag_Started(DragListener drag)
{
//get current thumb
var mprt = (drag.Target as PathThumb);
if (mprt != null)
{
SetOperation();
}
}
bool _isKeyboardMoveing;
void SetOperation()
{
var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
_zoom = designPanel.TryFindParent<ZoomControl>();
CommitOrAbortKeyboardOperation();
//Move a Virtual Design Item arround... (for Snaplines, raster, ...)
//And Resfresh the Points after Positioning that Item!
//if (resizeBehavior != null)
operation = PlacementOperation.Start(extendedItemArray, PlacementType.MovePoint);
// else
// {
// changeGroup = ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
// }
_isResizing = true;
}
void CommitOrAbortKeyboardOperation()
{
if (operation != null) {
if (!_isKeyboardMoveing) {
var op = operation;
operation = null;
op.Abort();
}
else
CommitOperation();
}
_isKeyboardMoveing = false;
}
void CommitOperation()
{
if (operation != null)
{
foreach (int i in _selectedThumbs.Keys)
{
pathPoints[i].Commit();
}
var op = operation;
operation = null;
op.Commit();
_isKeyboardMoveing = false;
}
// else
// {
// if (changeGroup != null)
// changeGroup.Commit();
// changeGroup = null;
// }
_isResizing = false;
//Invalidate();
}
protected void drag_Changed(DragListener drag)
{
var mprt = drag.Target as PathThumb;
if (mprt != null) {
_isDragging = true;
MovePoints(drag.Delta.X, drag.Delta.Y);
}
}
protected void drag_Completed(DragListener drag)
{
var mprt = drag.Target as PathThumb;
if (mprt != null) {
if (operation != null && drag.IsCanceled) {
operation.Abort();
} else if (drag.IsCanceled) {
changeGroup.Abort();
}
CommitOperation();
}
}
protected override void OnInitialized()
{
base.OnInitialized();
pathPoints = GetPoints();
resizeThumbs = new List<DesignerThumb>();
var transform = this.ExtendedItem.GetCompleteAppliedTransformationToView();
for (int i = 0; i < pathPoints.Count; i++) {
CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i, pathPoints[i], transform);
}
Invalidate();
ResetThumbs();
_isDragging = false;
extendedItemArray[0] = ExtendedItem;
ExtendedItem.PropertyChanged += OnPropertyChanged;
resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
UpdateAdornerVisibility();
this.ExtendedItem.Services.Selection.PrimarySelectionChanged += ExtendedItem_Services_Selection_PrimarySelectionChanged;
}
protected override void OnRemove()
{
this.ExtendedItem.Services.Selection.PrimarySelectionChanged -= ExtendedItem_Services_Selection_PrimarySelectionChanged;
base.OnRemove();
}
void ExtendedItem_Services_Selection_PrimarySelectionChanged(object sender, EventArgs e)
{
if (operation != null && _isKeyboardMoveing) {
var newSelection = this.ExtendedItem.Services.Selection.SelectedItems.ToList();
CommitOrAbortKeyboardOperation();
this.ExtendedItem.Services.Selection.SetSelectedComponents(newSelection);
}
}
#endregion
List<PathPoint> GetPoints()
{
return GetPoints(this.ExtendedItem);
}
protected List<PathPoint> GetPoints(DesignItem designItem)
{
var retVal = new List<PathPoint>();
AddGeometryPoints(retVal, ((Path)designItem.View).Data, ((Path)designItem.View), () => designItem.Properties["Data"].SetValue(((Path)designItem.View).Data.ToString()));
return retVal;
}
protected void AddGeometryPoints(List<PathPoint> list, Geometry geometry, Shape shape, Action saveDesignItem)
{
if (geometry is CombinedGeometry) {
var g = geometry as CombinedGeometry;
var d = ExtendedItem.Services.Component.GetDesignItem(g);
if (d != null)
saveDesignItem = () =>
{
d.Properties["Geometry1"].SetValue(((CombinedGeometry)d.Component).Geometry1);
d.Properties["Geometry2"].SetValue(((CombinedGeometry)d.Component).Geometry2);
};
AddGeometryPoints(list, g.Geometry1, shape, saveDesignItem);
AddGeometryPoints(list, g.Geometry2, shape, saveDesignItem);
} else if (geometry is GeometryGroup) {
var gg = geometry as GeometryGroup;
foreach (var g in gg.Children.ToList()) {
AddGeometryPoints(list, g, shape, saveDesignItem);
}
} else if (geometry is StreamGeometry) {
var sg = geometry as StreamGeometry;
var pg = sg.GetFlattenedPathGeometry().Clone();
var d = ExtendedItem.Services.Component.GetDesignItem(sg);
if (d != null)
saveDesignItem = () =>
{
d.ParentProperty.SetValue(Geometry.Parse(pg.ToString()));
};
if (d != null) {
if (!d.ParentProperty.IsCollection)
((DependencyObject)d.ParentProperty.DesignItem.Component).SetValue(d.ParentProperty.DependencyProperty, pg);
else {
var collection = ((DependencyObject)d.ParentProperty.DesignItem.Component) as GeometryGroup;
var i = collection.Children.IndexOf(geometry);
collection.Children.RemoveAt(i);
collection.Children.Insert(i, pg);
}
}
else
((Path)shape).Data = pg;
AddGeometryPoints(list, pg, shape, saveDesignItem);
} else if (geometry is PathGeometry) {
var g = geometry as PathGeometry;
var d = ExtendedItem.Services.Component.GetDesignItem(g);
if (d != null)
saveDesignItem = () =>
{
d.Properties["Figures"].SetValue(((PathGeometry)d.Component).Figures);
};
if (geometry!=null) {
foreach(var figure in g.Figures) {
var dd = ExtendedItem.Services.Component.GetDesignItem(figure);
if (dd != null)
saveDesignItem = () =>
{
dd.Properties["StartPoint"].SetValue(((PathFigure)dd.Component).StartPoint);
//dd.Properties["Segments"].SetValue(((PathFigure)dd.Component).Segments);
};
list.Add(new PathPoint(figure.StartPoint, figure, null, (p) => figure.StartPoint = p, saveDesignItem, shape));
foreach (var s in figure.Segments) {
var parentp = list.Last();
if (s is LineSegment)
{
var ds = ExtendedItem.Services.Component.GetDesignItem(s);
if (ds != null)
saveDesignItem = () =>
{
ds.Properties["Point"].SetValue(((LineSegment)ds.Component).Point);
};
list.Add(new PathPoint(((LineSegment)s).Point, s, figure, (p) => ((LineSegment)s).Point = p, saveDesignItem, shape) { ParentPathPoint = parentp });
}
else if (s is PolyLineSegment)
{
var ds = ExtendedItem.Services.Component.GetDesignItem(s);
if (ds != null)
saveDesignItem = () =>
{
ds.Properties["Points"].SetValue(((PolyLineSegment)ds.Component).Points);
};
var poly = s as PolyLineSegment;
for (int n = 0; n < poly.Points.Count; n++)
{
var closure_n = n;
list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, ParentPathPoint = parentp });
parentp = list.Last();
}
}
else if (s is BezierSegment)
{
var ds = ExtendedItem.Services.Component.GetDesignItem(s);
if (ds != null)
saveDesignItem = () =>
{
ds.Properties["Point1"].SetValue(((BezierSegment)ds.Component).Point1);
ds.Properties["Point2"].SetValue(((BezierSegment)ds.Component).Point2);
ds.Properties["Point3"].SetValue(((BezierSegment)ds.Component).Point3);
};
var pathp = new PathPoint(((BezierSegment)s).Point3, s, figure, (p) => ((BezierSegment)s).Point3 = p, saveDesignItem, shape) { ParentPathPoint = parentp };
var previous = list.Last();
list.Add(new PathPoint(((BezierSegment)s).Point1, s, figure, (p) => ((BezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = previous });
list.Add(new PathPoint(((BezierSegment)s).Point2, s, figure, (p) => ((BezierSegment)s).Point2 = p, saveDesignItem, shape) { TargetPathPoint = pathp });
list.Add(pathp);
}
else if (s is PolyBezierSegment)
{
var ds = ExtendedItem.Services.Component.GetDesignItem(s);
if (ds != null)
saveDesignItem = () =>
{
ds.Properties["Points"].SetValue(((PolyBezierSegment)ds.Component).Points);
};
var poly = s as PolyBezierSegment;
for (int n = 0; n < poly.Points.Count; n+=3)
{
var closure_n = n;
var previous = list.Last();
var pathp = new PathPoint(poly.Points[closure_n+2], s, figure, (p) => poly.Points[closure_n+2] = p, saveDesignItem, shape) { PolyLineIndex = closure_n+2, ParentPathPoint = parentp };
list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = previous });
list.Add(new PathPoint(poly.Points[closure_n+1], s, figure, (p) => poly.Points[closure_n+1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n+1, TargetPathPoint = pathp });
list.Add(pathp);
parentp = pathp;
}
}
else if (s is QuadraticBezierSegment)
{
var ds = ExtendedItem.Services.Component.GetDesignItem(s);
if (ds != null)
saveDesignItem = () =>
{
ds.Properties["Point1"].SetValue(((QuadraticBezierSegment)ds.Component).Point1);
ds.Properties["Point2"].SetValue(((QuadraticBezierSegment)ds.Component).Point2);
};
var pathp = new PathPoint(((QuadraticBezierSegment)s).Point2, s, figure, (p) => ((QuadraticBezierSegment)s).Point2 = p, saveDesignItem, shape) { ParentPathPoint = parentp };
list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, figure, (p) => ((QuadraticBezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = pathp });
list.Add(pathp);
}
else if (s is PolyQuadraticBezierSegment)
{
var ds = ExtendedItem.Services.Component.GetDesignItem(s);
if (ds != null)
saveDesignItem = () =>
{
ds.Properties["Points"].SetValue(((PolyQuadraticBezierSegment)ds.Component).Points);
};
var poly = s as PolyQuadraticBezierSegment;
for (int n = 0; n < poly.Points.Count; n+=2)
{
var closure_n = n;
var previous = list.Last();
var pathp = new PathPoint(poly.Points[closure_n+1], s, figure, (p) => poly.Points[closure_n+1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n+1, ParentPathPoint = parentp };
list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = pathp });
list.Add(pathp);
parentp = pathp;
}
}
else if (s is ArcSegment)
{
var ds = ExtendedItem.Services.Component.GetDesignItem(s);
if (ds != null)
saveDesignItem = () =>
{
ds.Properties["Size"].SetValue(((ArcSegment)ds.Component).Size);
};
var arc = ((ArcSegment)s);
var pathp = new PathPoint(arc.Point, s, figure, (p) => arc.Point = p, saveDesignItem, shape) { ParentPathPoint = parentp };
list.Add(new PathPoint(arc.Point - new Vector(arc.Size.Width, arc.Size.Height), s, figure, (p) => arc.Size = new Size(Math.Abs(arc.Point.X - p.X), Math.Abs(arc.Point.Y - p.Y)), saveDesignItem, shape) { TargetPathPoint = pathp });
list.Add(pathp);
}
}
}
}
} else if (geometry is RectangleGeometry) {
var g = geometry as RectangleGeometry;
list.Add(new PathPoint(g.Rect.TopLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Left = p.X));
list.Add(new PathPoint(g.Rect.TopRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Width = p.X));
list.Add(new PathPoint(g.Rect.BottomLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Top = p.Y));
list.Add(new PathPoint(g.Rect.BottomRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Height = p.Y));
} else if (geometry is EllipseGeometry) {
var g = geometry as EllipseGeometry;
var d = ExtendedItem.Services.Component.GetDesignItem(g);
if (d != null)
saveDesignItem = () => d.Properties["Center"].SetValue(((EllipseGeometry)d.Component).Center);
list.Add(new PathPoint(g.Center, geometry, null, (p) => g.Center = p, saveDesignItem, shape));
} else if (geometry is LineGeometry) {
var g = geometry as LineGeometry;
var d = ExtendedItem.Services.Component.GetDesignItem(g);
if (d != null)
saveDesignItem = () =>
{
d.Properties["StartPoint"].SetValue(((LineGeometry)d.Component).StartPoint);
d.Properties["EndPoint"].SetValue(((LineGeometry)d.Component).EndPoint);
};
list.Add(new PathPoint(g.StartPoint, geometry, null, (p) => g.StartPoint = p, saveDesignItem, shape));
list.Add(new PathPoint(g.EndPoint, geometry, null, (p) => g.EndPoint = p, saveDesignItem, shape));
}
}
void MovePoints(double displacementX, double displacementY, bool useContainerBehavior = true)
{
var relativeTo = new Vector(operation.PlacedItems[0].Bounds.TopLeft.X, operation.PlacedItems[0].Bounds.TopLeft.Y);
//iterate all selected points
foreach (int i in _selectedThumbs.Keys) {
Point p = pathPoints[i].TranslatedPoint;
//x and y is calculated from the currentl point
double x = _selectedThumbs[i].X + displacementX;
double y = _selectedThumbs[i].Y + displacementY;
p.X = x;
p.Y = y;
if (useContainerBehavior)
p = operation.CurrentContainerBehavior.PlacePoint(p + relativeTo) - relativeTo;
pathPoints[i].TranslatedPoint = p;
}
}
#region IKeyDown
public bool InvokeDefaultAction
{
get { return _selectedThumbs.Count == 0 || _selectedThumbs.Count == pathPoints.Count - 1; }
}
int _movingDistanceX;
int _movingDistanceY;
public void KeyDownAction(object sender, KeyEventArgs e)
{
if (_selectedThumbs.Count > 0) {
if (IsArrowKey(e.Key)) {
if (operation == null) {
SetOperation();
_isKeyboardMoveing = true;
_movingDistanceX = 0;
_movingDistanceY = 0;
}
}
var dx1 = (e.Key == Key.Left) ? Keyboard.IsKeyDown(Key.LeftShift) ? - 10 : - 1 : 0;
var dy1 = (e.Key == Key.Up) ? Keyboard.IsKeyDown(Key.LeftShift) ? - 10 : - 1 : 0;
var dx2 = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? + 10 : + 1 : 0;
var dy2 = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? + 10 : + 1 : 0;
_movingDistanceX += (dx1 + dx2);
_movingDistanceY += (dy1 + dy2);
if (operation != null)
MovePoints(_movingDistanceX, _movingDistanceY, false);
}
}
public void KeyUpAction(object sender, KeyEventArgs e)
{
// if (IsArrowKey(e.Key))
// CommitOperation();
}
bool IsArrowKey(Key key)
{
return (key == Key.Left || key == Key.Right || key == Key.Up || key == Key.Down);
}
#endregion
}
}

148
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PointTrackerPlacementSupport.cs

@ -1,11 +1,21 @@ @@ -1,11 +1,21 @@
/*
* Created by SharpDevelop.
* User: trubra
* Date: 2014-12-22
* Time: 11:05
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
// 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.Shapes;
@ -15,79 +25,57 @@ using ICSharpCode.WpfDesign.Adorners; @@ -15,79 +25,57 @@ using ICSharpCode.WpfDesign.Adorners;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
public class PointTrackerPlacementSupport : AdornerPlacement
{
private Shape shape;
private PlacementAlignment alignment;
public int Index
{
get; set;
}
public PointTrackerPlacementSupport(Shape s, PlacementAlignment align, int index)
{
shape = s;
alignment = align;
Index = index;
}
public PointTrackerPlacementSupport(Shape s, PlacementAlignment align)
{
shape = s;
alignment = align;
Index = -1;
}
/// <summary>
/// Arranges the adorner element on the specified adorner panel.
/// </summary>
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
Point p = new Point(0, 0);
double thumbsize = 7;
double distance = thumbsize / 2;
if (shape as Line != null)
{
Line s = shape as Line;
double x, y;
//will give you the angle of the line if more than 180 degrees it becomes negative from
Double theta = (180 / Math.PI) * Math.Atan2(s.Y2 - s.Y1, s.X2 - s.X1);
//this will give you the x offset from the line x point in parts of half the size of the thumb
double dx = Math.Cos(theta * (Math.PI / 180)) * distance;
//this will give you the y offset from the line y point in parts of half the size of the thumb
double dy = Math.Sin(theta * (Math.PI / 180)) * distance;
if (alignment == PlacementAlignment.BottomRight)
{
//x offset is linear
x = s.X2 - Math.Abs(theta) / (180 / thumbsize) + dx;
//y offset is angular
y = s.Y2 - ((.5 - Math.Sin(theta * (Math.PI / 180)) * .5) * thumbsize) + dy;
}
else
{
x = s.X1 - ((180 - Math.Abs(theta)) / (180 / thumbsize)) - dx;
y = s.Y1 - ((.5 - Math.Sin(theta * (Math.PI / 180) + Math.PI) * .5) * thumbsize) - dy;
}
p = new Point(x, y);
}
Polygon pg = shape as Polygon;
Polyline pl = shape as Polyline;
if (pg != null || pl != null)
{
if (Index > 0)
{
p = pl != null ? pl.Points[Index] : pg.Points[Index];
{
private Shape shape;
private PlacementAlignment alignment;
}
}
adorner.Arrange(new Rect(p, new Size(thumbsize, thumbsize)));
}
public int Index
{
get; set;
}
public PointTrackerPlacementSupport(Shape s, PlacementAlignment align, int index)
{
shape = s;
alignment = align;
Index = index;
}
/// <summary>
/// Arranges the adorner element on the specified adorner panel.
/// </summary>
public override void Arrange(AdornerPanel panel, UIElement adorner, Size adornedElementSize)
{
Point p = new Point(0, 0);
double distance = 0;
if (shape is Line)
{
var s = shape as Line;
double x, y;
if (alignment == PlacementAlignment.BottomRight)
{
x = s.X2;
y = s.Y2;
}
else
{
x = s.X1;
y = s.Y1;
}
p = new Point(x, y);
} else if (shape is Polygon) {
var pg = shape as Polygon;
p = pg.Points[Index];
} else if (shape is Polyline) {
var pg = shape as Polyline;
p = pg.Points[Index];
}
}
var transform = shape.RenderedGeometry.Transform;
p = transform.Transform(p);
adorner.Arrange(new Rect(p.X - 3.5, p.Y - 3.5, 7, 7));
}
}
}

105
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PolyLineHandlerExtension.cs

@ -31,14 +31,15 @@ using System; @@ -31,14 +31,15 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
/// <summary>
/// Description of PolyLineHandlerExtension.
/// </summary>
[ExtensionFor(typeof(Polyline), OverrideExtensions = new Type[] { typeof(ResizeThumbExtension), typeof(SelectedElementRectangleExtension), typeof(CanvasPositionExtension), typeof(QuickOperationMenuExtension), typeof(RotateThumbExtension), typeof(RenderTransformOriginExtension), typeof(InPlaceEditorExtension), typeof(SizeDisplayExtension), typeof(SkewThumbExtension) })]
[ExtensionFor(typeof(Polyline))]
[ExtensionFor(typeof(Polygon))]
internal class PolyLineHandlerExtension : LineExtensionBase, IKeyDown, IKeyUp
{
private readonly Dictionary<int, Bounds> _selectedThumbs = new Dictionary<int, Bounds>();
@ -46,36 +47,36 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -46,36 +47,36 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
ZoomControl _zoom;
#region thumb methods
protected ResizeThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index)
protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index)
{
ResizeThumb resizeThumb = new MultiPointResizeThumb { Index = index, Alignment = alignment, Cursor = cursor, IsPrimarySelection = true };
AdornerPlacement ap = Place(ref resizeThumb, alignment, index);
(resizeThumb as MultiPointResizeThumb).AdornerPlacement = ap;
DesignerThumb designerThumb = new MultiPointThumb { Index = index, Alignment = alignment, Cursor = cursor, IsPrimarySelection = true };
AdornerPlacement ap = Place(ref designerThumb, alignment, index);
(designerThumb as MultiPointThumb).AdornerPlacement = ap;
AdornerPanel.SetPlacement(resizeThumb, ap);
adornerPanel.Children.Add(resizeThumb);
AdornerPanel.SetPlacement(designerThumb, ap);
adornerPanel.Children.Add(designerThumb);
DragListener drag = new DragListener(resizeThumb);
DragListener drag = new DragListener(designerThumb);
WeakEventManager<ResizeThumb, MouseButtonEventArgs>.AddHandler(resizeThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp);
WeakEventManager<DesignerThumb, MouseButtonEventArgs>.AddHandler(designerThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp);
drag.Started += drag_Started;
drag.Changed += drag_Changed;
drag.Completed += drag_Completed;
return resizeThumb;
return designerThumb;
}
private void ResetThumbs()
{
foreach (FrameworkElement rt in adornerPanel.Children)
{
if (rt is ResizeThumb)
(rt as ResizeThumb).IsPrimarySelection = true;
if (rt is DesignerThumb)
(rt as DesignerThumb).IsPrimarySelection = true;
}
_selectedThumbs.Clear();
}
private void SelectThumb(MultiPointResizeThumb mprt)
private void SelectThumb(MultiPointThumb mprt)
{
PointCollection points = GetPointCollection();
Point p = points[mprt.Index];
@ -91,7 +92,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -91,7 +92,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
private void ResizeThumbOnMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
//get current thumb
MultiPointResizeThumb mprt = sender as MultiPointResizeThumb;
MultiPointThumb mprt = sender as MultiPointThumb;
if (mprt != null)
{
//shift+ctrl will remove selected point
@ -103,7 +104,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -103,7 +104,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
PointCollection points = GetPointCollection();
//iterate thumbs to lower index of remaining thumbs
foreach (MultiPointResizeThumb m in adornerPanel.Children)
foreach (MultiPointThumb m in adornerPanel.Children)
{
if (m.Index > mprt.Index)
m.Index--;
@ -135,7 +136,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -135,7 +136,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
protected void drag_Started(DragListener drag)
{
//get current thumb
MultiPointResizeThumb mprt = (drag.Target as MultiPointResizeThumb);
MultiPointThumb mprt = (drag.Target as MultiPointThumb);
if (mprt != null)
{
SetOperation();
@ -156,30 +157,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -156,30 +157,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
_isResizing = true;
}
void ChangeOperation(PointCollection points)
{
//this is for SharpDevelop built in undo functionality
if (operation != null)
{
var info = operation.PlacedItems[0];
var result = info.OriginalBounds;
IEnumerable<double> xs = points.Select(x => x.X);
IEnumerable<double> ys = points.Select(y => y.Y);
result.X = (double)(info.Item.Properties.GetAttachedProperty(Canvas.LeftProperty).ValueOnInstance);
result.Y = (double)(info.Item.Properties.GetAttachedProperty(Canvas.TopProperty).ValueOnInstance);
result.Width = xs.Max() - xs.Min();
result.Height = ys.Max() - ys.Min();
info.Bounds = result.Round();
operation.CurrentContainerBehavior.BeforeSetPosition(operation);
operation.CurrentContainerBehavior.SetPosition(info);
}
ResetWidthHeightProperties();
}
void CommitOperation()
{
if (operation != null)
@ -203,19 +180,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -203,19 +180,18 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
_selectedThumbs[i].Y = points[i].Y;
}
ExtendedItem.Properties.GetProperty(pl != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points);
ResetWidthHeightProperties();
operation.Commit();
operation = null;
}
else
{
changeGroup.Commit();
if (changeGroup != null)
changeGroup.Commit();
changeGroup = null;
}
_isResizing = false;
ResetWidthHeightProperties();
Invalidate();
}
@ -223,7 +199,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -223,7 +199,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
PointCollection points = GetPointCollection();
MultiPointResizeThumb mprt = drag.Target as MultiPointResizeThumb;
MultiPointThumb mprt = drag.Target as MultiPointThumb;
if (mprt != null)
{
double dx = 0;
@ -237,12 +213,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -237,12 +213,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
Double theta;
//if one point selected snapping angle is calculated in relation to previous point
if (_selectedThumbs.Count == 1)
{
if (_selectedThumbs.Count == 1 && mprt.Index > 0) {
theta = (180 / Math.PI) * Math.Atan2(_selectedThumbs[mprt.Index].Y + dy - points[mprt.Index - 1].Y, _selectedThumbs[mprt.Index].X + dx - points[mprt.Index - 1].X);
}
else//if multiple points snapping angle is calculated in relation to mouse dragging angle
{
} else { //if multiple points snapping angle is calculated in relation to mouse dragging angle
theta = (180 / Math.PI) * Math.Atan2(dy, dx);
}
@ -265,14 +238,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -265,14 +238,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
points.Insert(mprt.Index, p);
//create adorner marker
CreateThumb(PlacementAlignment.BottomRight, Cursors.SizeNWSE, mprt.Index);
CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, mprt.Index);
//set index of all points that had a higher index than selected to +1
foreach (FrameworkElement rt in adornerPanel.Children)
{
if (rt is MultiPointResizeThumb)
if (rt is MultiPointThumb)
{
MultiPointResizeThumb t = rt as MultiPointResizeThumb;
MultiPointThumb t = rt as MultiPointThumb;
if (t.Index > mprt.Index)
t.Index++;
}
@ -301,15 +274,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -301,15 +274,13 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
points = MovePoints(points, dx, dy, theta, snapAngle);
}
ChangeOperation(points);
(drag.Target as ResizeThumb).InvalidateArrange();
(drag.Target as DesignerThumb).InvalidateArrange();
}
protected void drag_Completed(DragListener drag)
{
MultiPointResizeThumb mprt = drag.Target as MultiPointResizeThumb;
MultiPointThumb mprt = drag.Target as MultiPointThumb;
if (mprt != null)
{
if (operation != null && drag.IsCanceled)
@ -332,34 +303,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -332,34 +303,21 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
PointCollection points = GetPointCollection();
if (ExtendedItem.Properties[Shape.StrokeProperty].ValueOnInstance == null)
resizeThumbs = new List<DesignerThumb>();
for (int i = 0; i < points.Count; i++)
{
ExtendedItem.Properties[Shape.StrokeProperty].SetValue(Colors.Black);
ExtendedItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
ExtendedItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
points.AddRange(new List<Point> { new Point(0, 0), new Point(20, 20) });
ExtendedItem.Properties.GetProperty(ExtendedItem.View as Polyline != null ? Polyline.PointsProperty : Polygon.PointsProperty).SetValue(points);
}
resizeThumbs = new List<ResizeThumb>();
for (int i = 1; i < points.Count; i++)
{
CreateThumb(PlacementAlignment.BottomRight, Cursors.SizeNWSE, i);
CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, i);
}
Invalidate();
ResetWidthHeightProperties();
ResetThumbs();
_isDragging = false;
extendedItemArray[0] = ExtendedItem;
ExtendedItem.PropertyChanged += OnPropertyChanged;
Services.Selection.PrimarySelectionChanged += OnPrimarySelectionChanged;
resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray);
UpdateAdornerVisibility();
OnPrimarySelectionChanged(null, null);
}
#endregion
@ -433,7 +391,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -433,7 +391,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
var dx2 = (e.Key == Key.Right) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance + 10 : _movingDistance + 1 : 0;
var dy2 = (e.Key == Key.Down) ? Keyboard.IsKeyDown(Key.LeftShift) ? _movingDistance + 10 : _movingDistance + 1 : 0;
ChangeOperation(MovePoints(GetPointCollection(), dx1 + dx2, dy1 + dy2, 0, null));
_movingDistance = (dx1 + dx2 + dy1 + dy2);
}

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

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.SharpDevelop.Widgets;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
@ -43,6 +44,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -43,6 +44,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
base.OnInitialized();
_menu = new QuickOperationMenu();
_menu.Loaded += OnMenuLoaded;
_menu.RenderTransform = ((Transform)this.ExtendedItem.GetCompleteAppliedTransformationToView().Inverse);
var placement = new RelativePlacement(HorizontalAlignment.Right, VerticalAlignment.Top) {XOffset = 7, YOffset = 3.5};
this.AddAdorners(placement, _menu);

25
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RasterPlacementBehavior.cs

@ -23,6 +23,7 @@ using System.Windows.Media; @@ -23,6 +23,7 @@ using System.Windows.Media;
using System.Windows.Shapes;
using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using System.Windows;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
@ -112,6 +113,30 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -112,6 +113,30 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
operation.PlacedItems[0].Bounds = bounds;
}
public override Point PlacePoint(Point point)
{
if (surface == null)
return base.PlacePoint(point);
DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
if (designPanel == null || !designPanel.UseRasterPlacement)
return base.PlacePoint(point);
if (Keyboard.IsKeyDown(Key.LeftCtrl))
{
surface.Children.Clear();
rasterDrawn = false;
return base.PlacePoint(point);
}
drawRaster();
point.Y = ((int)point.Y / raster) * raster;
point.X = ((int)point.X / raster) * raster;
return point;
}
private void drawRaster()
{
if (!rasterDrawn)

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

@ -26,7 +26,7 @@ using ICSharpCode.WpfDesign.Adorners; @@ -26,7 +26,7 @@ using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{
@ -38,7 +38,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -38,7 +38,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
public sealed class ResizeThumbExtension : SelectionAdornerProvider
{
readonly AdornerPanel adornerPanel;
readonly ResizeThumb[] resizeThumbs;
readonly DesignerThumb[] _designerThumbs;
/// <summary>An array containing this.ExtendedItem as only element</summary>
readonly DesignItem[] extendedItemArray = new DesignItem[1];
IPlacementBehavior resizeBehavior;
@ -60,7 +60,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -60,7 +60,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
adornerPanel.Order = AdornerOrder.Foreground;
this.Adorners.Add(adornerPanel);
resizeThumbs = new ResizeThumb[] {
_designerThumbs = new DesignerThumb[] {
CreateThumb(PlacementAlignment.TopLeft, Cursors.SizeNWSE),
CreateThumb(PlacementAlignment.Top, Cursors.SizeNS),
CreateThumb(PlacementAlignment.TopRight, Cursors.SizeNESW),
@ -72,29 +72,29 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -72,29 +72,29 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
};
}
ResizeThumb CreateThumb(PlacementAlignment alignment, Cursor cursor)
DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor)
{
ResizeThumb resizeThumb = new ResizeThumbImpl( cursor == Cursors.SizeNS, cursor == Cursors.SizeWE );
resizeThumb.Cursor = cursor;
resizeThumb.Alignment = alignment;
AdornerPanel.SetPlacement(resizeThumb, Place(ref resizeThumb, alignment));
adornerPanel.Children.Add(resizeThumb);
DesignerThumb designerThumb = new ResizeThumb( cursor == Cursors.SizeNS, cursor == Cursors.SizeWE );
designerThumb.Cursor = cursor;
designerThumb.Alignment = alignment;
AdornerPanel.SetPlacement(designerThumb, Place(ref designerThumb, alignment));
adornerPanel.Children.Add(designerThumb);
DragListener drag = new DragListener(resizeThumb);
DragListener drag = new DragListener(designerThumb);
drag.Started += new DragHandler(drag_Started);
drag.Changed += new DragHandler(drag_Changed);
drag.Completed += new DragHandler(drag_Completed);
return resizeThumb;
return designerThumb;
}
/// <summary>
/// Places resize thumbs at their respective positions
/// and streches out thumbs which are at the center of outline to extend resizability across the whole outline
/// </summary>
/// <param name="resizeThumb"></param>
/// <param name="designerThumb"></param>
/// <param name="alignment"></param>
/// <returns></returns>
private RelativePlacement Place(ref ResizeThumb resizeThumb,PlacementAlignment alignment)
private RelativePlacement Place(ref DesignerThumb designerThumb,PlacementAlignment alignment)
{
RelativePlacement placement = new RelativePlacement(alignment.Horizontal,alignment.Vertical);
@ -102,14 +102,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -102,14 +102,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
placement.WidthRelativeToContentWidth = 1;
placement.HeightOffset = 6;
resizeThumb.Opacity = 0;
designerThumb.Opacity = 0;
return placement;
}
if (alignment.Vertical == VerticalAlignment.Center)
{
placement.HeightRelativeToContentHeight = 1;
placement.WidthOffset = 6;
resizeThumb.Opacity = 0;
designerThumb.Opacity = 0;
return placement;
}
@ -119,14 +119,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -119,14 +119,10 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
Size oldSize;
ZoomControl zoom;
// TODO : Remove all hide/show extensions from here.
void drag_Started(DragListener drag)
{
var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
zoom = designPanel.TryFindParent<ZoomControl>();
/* Abort editing Text if it was editing, because it interferes with the undo stack. */
foreach(var extension in this.ExtendedItem.Extensions){
if(extension is InPlaceEditorExtension){
@ -134,6 +130,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -134,6 +130,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
}
drag.Transform = this.ExtendedItem.GetCompleteAppliedTransformationToView();
oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
if (resizeBehavior != null)
operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
@ -148,12 +146,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -148,12 +146,14 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
{
double dx = 0;
double dy = 0;
var alignment = (drag.Target as ResizeThumb).Alignment;
var alignment = (drag.Target as DesignerThumb).Alignment;
var delta = drag.Delta;
if (alignment.Horizontal == HorizontalAlignment.Left) dx = -drag.Delta.X;
if (alignment.Horizontal == HorizontalAlignment.Right) dx = drag.Delta.X;
if (alignment.Vertical == VerticalAlignment.Top) dy = -drag.Delta.Y;
if (alignment.Vertical == VerticalAlignment.Bottom) dy = drag.Delta.Y;
if (alignment.Horizontal == HorizontalAlignment.Left) dx = -delta.X;
if (alignment.Horizontal == HorizontalAlignment.Right) dx = delta.X;
if (alignment.Vertical == VerticalAlignment.Top) dy = -delta.Y;
if (alignment.Vertical == VerticalAlignment.Bottom) dy = delta.Y;
var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
@ -164,12 +164,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -164,12 +164,6 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
else
dy = dx;
}
if (zoom != null)
{
dx = dx * (1 / zoom.CurrentZoom);
dy = dy * (1 / zoom.CurrentZoom);
}
var newWidth = Math.Max(0, oldSize.Width + dx);
var newHeight = Math.Max(0, oldSize.Height + dy);
@ -253,7 +247,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -253,7 +247,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
void OnPrimarySelectionChanged(object sender, EventArgs e)
{
bool isPrimarySelection = this.Services.Selection.PrimarySelection == this.ExtendedItem;
foreach (ResizeThumb g in adornerPanel.Children) {
foreach (DesignerThumb g in adornerPanel.Children) {
g.IsPrimarySelection = isPrimarySelection;
}
}
@ -261,7 +255,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -261,7 +255,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
void UpdateAdornerVisibility()
{
FrameworkElement fe = this.ExtendedItem.View as FrameworkElement;
foreach (ResizeThumb r in resizeThumbs) {
foreach (DesignerThumb r in _designerThumbs) {
bool isVisible = resizeBehavior != null && resizeBehavior.CanPlace(extendedItemArray, PlacementType.Resize, r.Alignment);
r.Visibility = isVisible ? Visibility.Visible : Visibility.Hidden;
}

6
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RotateThumbExtension.cs

@ -52,9 +52,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -52,9 +52,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
thumb = CreateRotateThumb();
}
ResizeThumb CreateRotateThumb()
DesignerThumb CreateRotateThumb()
{
ResizeThumb rotateThumb = new RotateThumb();
DesignerThumb rotateThumb = new RotateThumb();
rotateThumb.Cursor = Cursors.Hand;
rotateThumb.Cursor = ZoomControl.GetCursor("Images/rotate.cur");
rotateThumb.Alignment = PlacementAlignment.Top;
@ -137,7 +137,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -137,7 +137,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
}
rtTransform.Properties["Angle"].SetValue(destAngle);
((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true);
((DesignPanel) this.ExtendedItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(this.ExtendedItem.View, true);
}
}

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

@ -27,7 +27,7 @@ using ICSharpCode.WpfDesign.Adorners; @@ -27,7 +27,7 @@ using ICSharpCode.WpfDesign.Adorners;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Extensions;
using System.Collections.Generic;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.Extensions
{

137
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/SnaplinePlacementBehavior.cs

@ -77,7 +77,64 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -77,7 +77,64 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
base.LeaveContainer(operation);
DeleteSurface();
}
public override Point PlacePoint(Point point)
{
if (surface == null)
return base.PlacePoint(point);
DesignPanel designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;
if (designPanel == null || !designPanel.UseSnaplinePlacement)
return base.PlacePoint(point); ;
surface.Children.Clear();
if (Keyboard.IsKeyDown(Key.LeftCtrl))
return base.PlacePoint(point); ;
Rect bounds = new Rect(point.X, point.Y, 0, 0);
var horizontalInput = new List<Snapline>();
var verticalInput = new List<Snapline>();
AddLines(bounds, 0, false, horizontalInput, verticalInput, null);
if (baseline.HasValue)
{
var textOffset = bounds.Top + baseline.Value;
horizontalInput.Add(new Snapline() { Group = 1, Offset = textOffset, Start = bounds.Left, End = bounds.Right });
}
List<Snapline> drawLines;
double delta;
var newPoint = base.PlacePoint(point);
if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta))
{
foreach (var d in drawLines)
{
DrawLine(d.Start, d.Offset + d.DrawOffset, d.End, d.Offset + d.DrawOffset);
}
point.Y += delta;
}
else
point.Y = newPoint.Y;
if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta))
{
foreach (var d in drawLines)
{
DrawLine(d.Offset + d.DrawOffset, d.Start, d.Offset + d.DrawOffset, d.End);
}
point.X += delta;
}
else
point.X = newPoint.X;
return point;
}
public override void BeforeSetPosition(PlacementOperation operation)
{
base.BeforeSetPosition(operation);
@ -94,21 +151,25 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -94,21 +151,25 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
foreach (var item in operation.PlacedItems) {
bounds.Union(item.Bounds);
}
var horizontalInput = new List<Snapline>();
var verticalInput = new List<Snapline>();
var info = operation.PlacedItems[0];
if (operation.Type == PlacementType.Resize) {
if (operation.Type == PlacementType.Resize)
{
AddLines(bounds, 0, false, horizontalInput, verticalInput, info.ResizeThumbAlignment);
} else {
}
else
{
AddLines(bounds, 0, false, horizontalInput, verticalInput, null);
if (baseline.HasValue) {
if (baseline.HasValue)
{
var textOffset = bounds.Top + baseline.Value;
horizontalInput.Add(new Snapline() { Group = 1, Offset = textOffset, Start = bounds.Left, End = bounds.Right });
}
}
// debug
//foreach (var t in horizontalMap.Concat(horizontalInput)) {
// surface.Children.Add(new Line() { X1 = t.Start, X2 = t.End, Y1 = t.Offset, Y2 = t.Offset, Stroke = Brushes.Black });
@ -117,57 +178,75 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions @@ -117,57 +178,75 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
// surface.Children.Add(new Line() { X1 = t.Offset, X2 = t.Offset, Y1 = t.Start , Y2 = t.End, Stroke = Brushes.Black });
//}
//return;
List<Snapline> drawLines;
double delta;
if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta)) {
if (operation.Type == PlacementType.Resize) {
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top) {
if (Snap(horizontalInput, horizontalMap, Accuracy, out drawLines, out delta))
{
if (operation.Type == PlacementType.Resize)
{
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Vertical == VerticalAlignment.Top)
{
bounds.Y += delta;
bounds.Height = Math.Max(0, bounds.Height - delta);
} else {
}
else
{
bounds.Height = Math.Max(0, bounds.Height + delta);
}
info.Bounds = bounds;
} else {
foreach (var item in operation.PlacedItems) {
}
else
{
foreach (var item in operation.PlacedItems)
{
var r = item.Bounds;
r.Y += delta;
item.Bounds = r;
}
}
foreach (var d in drawLines) {
foreach (var d in drawLines)
{
DrawLine(d.Start, d.Offset + d.DrawOffset, d.End, d.Offset + d.DrawOffset);
}
}
if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta)) {
if (operation.Type == PlacementType.Resize) {
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left) {
if (Snap(verticalInput, verticalMap, Accuracy, out drawLines, out delta))
{
if (operation.Type == PlacementType.Resize)
{
if (info.ResizeThumbAlignment != null && info.ResizeThumbAlignment.Value.Horizontal == HorizontalAlignment.Left)
{
bounds.X += delta;
bounds.Width = Math.Max(0, bounds.Width - delta);
} else {
}
else
{
bounds.Width = Math.Max(0, bounds.Width + delta);
}
info.Bounds = bounds;
} else {
foreach (var item in operation.PlacedItems) {
}
else
{
foreach (var item in operation.PlacedItems)
{
var r = item.Bounds;
r.X += delta;
item.Bounds = r;
}
}
foreach (var d in drawLines) {
foreach (var d in drawLines)
{
DrawLine(d.Offset + d.DrawOffset, d.Start, d.Offset + d.DrawOffset, d.End);
}
}
}
void CreateSurface(PlacementOperation operation)
{
if (ExtendedItem.Services.GetService<IDesignPanel>() != null) {

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenu.xaml.cs

@ -20,7 +20,7 @@ using System; @@ -20,7 +20,7 @@ using System;
using System.Linq;
using System.Windows;
using ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
using ICSharpCode.WpfDesign.Designer.themes;
namespace ICSharpCode.WpfDesign.Designer.Extensions

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

@ -26,6 +26,7 @@ using System.Windows.Documents; @@ -26,6 +26,7 @@ using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Xps.Serialization;
using ICSharpCode.WpfDesign.Designer.Xaml;
@ -589,5 +590,24 @@ namespace ICSharpCode.WpfDesign.Designer @@ -589,5 +590,24 @@ namespace ICSharpCode.WpfDesign.Designer
operation.Commit();
}
// public static class Path {
//
// public static PathGeometry ConvertToPathGeometry(this TextBlock textBlock)
// {
// //var ft = new FormatedText();
// return null;
// }
//
// public static PathGeometry ConvertToPathGeometry(this Rectangle rectangle)
// {
// return null;
// }
//
// public static PathGeometry ConvertToPathGeometry(this Ellipse ellipse)
// {
// return null;
// }
// }
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/OutlineView/OutlineTreeView.cs

@ -20,7 +20,7 @@ using System; @@ -20,7 +20,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.OutlineView
{

18
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditor.cs

@ -51,10 +51,16 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -51,10 +51,16 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
.GetProperties(BindingFlags.Static | BindingFlags.Public)
.Where(p => p.PropertyType == typeof(Color))
.Select(p => new BrushItem()
{
Name = p.Name,
Brush = new SolidColorBrush((Color)p.GetValue(null, null))
})
{
Name = p.Name,
Brush = new SolidColorBrush((Color)p.GetValue(null, null))
})
.ToArray();
public static BrushItem[] WpfBrushes = typeof(Brushes)
.GetProperties(BindingFlags.Static | BindingFlags.Public)
.Where(p => p.PropertyType == typeof(SolidColorBrush))
.Select(p => new BrushItem() { Name = p.Name, Brush = (Brush)p.GetValue(null, null) })
.ToArray();
SolidColorBrush solidColorBrush = new SolidColorBrush(Colors.White);
@ -176,6 +182,10 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -176,6 +182,10 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
public IEnumerable<BrushItem> AvailableBrushes {
get { return SystemBrushes; }
}
public IEnumerable<BrushItem> AvailableWpfBrushes {
get { return WpfBrushes; }
}
public void MakeGradientHorizontal()
{

9
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
xmlns:Converters="clr-namespace:ICSharpCode.WpfDesign.Designer.Converters"
xmlns:PropertyGrid="clr-namespace:ICSharpCode.WpfDesign.Designer.PropertyGrid"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
Width="395">
Width="395" MinHeight="320">
<UserControl.Resources>
@ -73,7 +73,12 @@ @@ -73,7 +73,12 @@
<BrushEditor:GradientBrushEditor />
</TabItem>
<TabItem Header="Brush List">
<ListBox ItemsSource="{Binding AvailableBrushes}"
<ListBox MaxHeight="320" ItemsSource="{Binding AvailableBrushes}"
SelectedValue="{Binding Brush.Color}"
SelectedValuePath="Brush.Color" />
</TabItem>
<TabItem Header="Wpf Brush List">
<ListBox MaxHeight="320" ItemsSource="{Binding AvailableWpfBrushes}"
SelectedValue="{Binding Brush.Color}"
SelectedValuePath="Brush.Color" />
</TabItem>

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/BrushEditorView.xaml.cs

@ -43,10 +43,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -43,10 +43,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
DataContext = BrushEditor;
SpecialInitializeComponent();
SetBinding(HeightProperty, new Binding("Brush") {
Converter = HeightConverter.Instance
});
}
/// <summary>
@ -64,21 +60,5 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor @@ -64,21 +60,5 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.BrushEditor
}
public BrushEditor BrushEditor { get; private set; }
class HeightConverter : IValueConverter
{
public static HeightConverter Instance = new HeightConverter();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is GradientBrush) return double.NaN;
return 315;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
}

7
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/BrushEditor/SolidBrushEditor.xaml

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
x:Name="this"
Height="284">
Height="320">
<TabControl>
<TabItem Header="Color Picker">
<widgets:ColorPicker Color="{Binding Color, ElementName=this}" />
@ -13,5 +13,10 @@ @@ -13,5 +13,10 @@
SelectedValue="{Binding Color, ElementName=this}"
SelectedValuePath="Brush.Color" />
</TabItem>
<TabItem Header="Wpf Color List">
<ListBox ItemsSource="{Binding AvailableWpfBrushes}"
SelectedValue="{Binding Color, ElementName=this}"
SelectedValuePath="Brush.Color" />
</TabItem>
</TabControl>
</UserControl>

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs

@ -24,7 +24,7 @@ using System.Windows.Controls; @@ -24,7 +24,7 @@ using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using ICSharpCode.WpfDesign.Designer.Xaml;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
using ICSharpCode.WpfDesign.Designer.themes;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor

56
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/NumberEditor.xaml.cs

@ -117,16 +117,20 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors @@ -117,16 +117,20 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
Maximum = range.Max;
}
if (Minimum == 0 && Maximum == 1) {
if (type == typeof(double) || type == typeof(decimal)) {
DecimalPlaces = 2;
SmallChange = 0.01;
LargeChange = 0.1;
}
else {
ClearValue(DecimalPlacesProperty);
ClearValue(SmallChangeProperty);
ClearValue(LargeChangeProperty);
}
// if (Minimum == 0 && Maximum == 1) {
// DecimalPlaces = 2;
// SmallChange = 0.01;
// LargeChange = 0.1;
// }
// else {
// ClearValue(DecimalPlacesProperty);
// ClearValue(SmallChangeProperty);
// ClearValue(LargeChangeProperty);
// }
}
public override void OnApplyTemplate()
@ -147,30 +151,30 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors @@ -147,30 +151,30 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors
double val;
if(double.TryParse(textBox.Text, out val)){
if(PropertyNode.FirstProperty.TypeConverter.IsValid(textBox.Text)){
if(val >= Minimum && val <= Maximum || double.IsNaN(val)){
textBox.Foreground=Brushes.Black;
textBox.ToolTip=textBox.Text;
}else{
textBox.Foreground = Brushes.DarkBlue;
textBox.ToolTip = "Value should be in between "+Minimum+" and "+Maximum;
}
}else{
textBox.Foreground = Brushes.DarkRed;
textBox.ToolTip = "Cannot convert to Type : " + PropertyNode.FirstProperty.ReturnType.Name;
}
}else{
textBox.Foreground = Brushes.DarkRed;
textBox.ToolTip = string.IsNullOrWhiteSpace(textBox.Text)? null:"Value does not belong to any numeric type";
}
if(val >= Minimum && val <= Maximum || double.IsNaN(val)){
textBox.Foreground=Brushes.Black;
textBox.ToolTip=textBox.Text;
}else{
textBox.Foreground = Brushes.DarkBlue;
textBox.ToolTip = "Value should be in between "+Minimum+" and "+Maximum;
}
}else{
textBox.Foreground = Brushes.DarkRed;
textBox.ToolTip = "Cannot convert to Type : " + PropertyNode.FirstProperty.ReturnType.Name;
}
}else{
textBox.Foreground = Brushes.DarkRed;
textBox.ToolTip = string.IsNullOrWhiteSpace(textBox.Text)? null:"Value does not belong to any numeric type";
}
}
ChangeGroup group;
protected override void OnDragStarted()
{
group = PropertyNode.Context.OpenGroup("drag number",
PropertyNode.Properties.Select(p => p.DesignItem).ToArray());
group = PropertyNode.Context.OpenGroup("drag number",
PropertyNode.Properties.Select(p => p.DesignItem).ToArray());
}
protected override void OnDragCompleted()

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/RootItemBehavior.cs

@ -94,5 +94,10 @@ namespace ICSharpCode.WpfDesign.Designer @@ -94,5 +94,10 @@ namespace ICSharpCode.WpfDesign.Designer
{
throw new NotImplementedException();
}
public Point PlacePoint(Point point)
{
return point;
}
}
}

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

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Linq;
using System.Windows;
using System;
using System.Diagnostics;
@ -155,6 +156,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -155,6 +156,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
object newInstance = context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(componentType, null);
DesignItem item = context.Services.Component.RegisterComponentForDesigner(newInstance);
changeGroup = item.OpenGroup("Drop Control");
context.Services.Component.SetDefaultPropertyValues(item);
context.Services.ExtensionManager.ApplyDefaultInitializers(item);
return item;
}
@ -163,7 +165,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -163,7 +165,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services
{
CreateComponentTool cct = new CreateComponentTool(createdItem);
return AddItemWithCustomSize(container, cct.CreateItem(container.Context), position, size);
}
}
public static bool AddItemWithDefaultSize(DesignItem container, Type createdItem, Size size)
{
@ -201,13 +203,20 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -201,13 +203,20 @@ namespace ICSharpCode.WpfDesign.Designer.Services
IDesignPanel designPanel = (IDesignPanel)sender;
DesignPanelHitTestResult result = designPanel.HitTest(e.GetPosition(designPanel), false, true, HitTestType.Default);
if (result.ModelHit != null) {
IPlacementBehavior behavior = result.ModelHit.GetBehavior<IPlacementBehavior>();
if (behavior != null) {
DesignItem createdItem = CreateItem(designPanel.Context);
new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e);
// CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem()
changeGroup = null;
var darwItemBehaviors = result.ModelHit.Extensions.OfType<IDrawItemExtension>();
var drawItembehavior = darwItemBehaviors.FirstOrDefault(x => x.CanItemBeDrawn(componentType));
if (drawItembehavior != null && drawItembehavior.CanItemBeDrawn(componentType)) {
drawItembehavior.StartDrawItem(result.ModelHit, componentType, designPanel, e);
}
else {
var placementBehavior = result.ModelHit.GetBehavior<IPlacementBehavior>();
if (placementBehavior != null) {
var createdItem = CreateItem(designPanel.Context);
new CreateComponentMouseGesture(result.ModelHit, createdItem, changeGroup).Start(designPanel, e);
// CreateComponentMouseGesture now is responsible for the changeGroup created by CreateItem()
changeGroup = null;
}
}
}
}

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

@ -18,6 +18,9 @@ @@ -18,6 +18,9 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign.Designer.Services
@ -71,6 +74,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -71,6 +74,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services
designPanel.MouseMove += OnMouseMove;
designPanel.MouseUp += OnMouseUp;
designPanel.KeyDown += OnKeyDown;
designPanel.PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown;
designPanel.PreviewMouseLeftButtonUp += OnPreviewMouseLeftButtonUp;
designPanel.PreviewMouseRightButtonDown += OnPreviewMouseRightButtonDown;
designPanel.PreviewMouseRightButtonUp += OnPreviewMouseRightButtonUp;
}
void UnRegisterEvents()
@ -80,6 +87,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -80,6 +87,10 @@ namespace ICSharpCode.WpfDesign.Designer.Services
designPanel.MouseMove -= OnMouseMove;
designPanel.MouseUp -= OnMouseUp;
designPanel.KeyDown -= OnKeyDown;
designPanel.PreviewMouseLeftButtonDown -= OnPreviewMouseLeftButtonDown;
designPanel.PreviewMouseLeftButtonUp -= OnPreviewMouseLeftButtonUp;
designPanel.PreviewMouseRightButtonDown -= OnPreviewMouseRightButtonDown;
designPanel.PreviewMouseRightButtonUp -= OnPreviewMouseRightButtonUp;
}
void OnKeyDown(object sender, KeyEventArgs e)
@ -95,10 +106,27 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -95,10 +106,27 @@ namespace ICSharpCode.WpfDesign.Designer.Services
Stop();
}
protected virtual void OnMouseDown(object sender, MouseButtonEventArgs e)
protected virtual void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (MouseButtonHelper.IsDoubleClick(sender, e))
OnMouseDoubleClick(sender, e);
}
protected virtual void OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{ }
protected virtual void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{ }
protected virtual void OnPreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{ }
protected virtual void OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
{ }
protected virtual void OnMouseDown(object sender, MouseButtonEventArgs e)
{ }
protected virtual void OnMouseMove(object sender, MouseEventArgs e)
{
}
@ -119,5 +147,56 @@ namespace ICSharpCode.WpfDesign.Designer.Services @@ -119,5 +147,56 @@ namespace ICSharpCode.WpfDesign.Designer.Services
protected virtual void OnStarted(MouseButtonEventArgs e) {}
protected virtual void OnStopped() {}
static class MouseButtonHelper
{
[DllImport("user32.dll")]
static extern uint GetDoubleClickTime();
static MouseButtonHelper()
{
k_DoubleClickSpeed = GetDoubleClickTime();
}
private static readonly uint k_DoubleClickSpeed;
private const double k_MaxMoveDistance = 10;
private static long _LastClickTicks = 0;
private static Point _LastPosition;
private static WeakReference _LastSender;
internal static bool IsDoubleClick(object sender, MouseButtonEventArgs e)
{
Point position = e.GetPosition(null);
long clickTicks = DateTime.Now.Ticks;
long elapsedTicks = clickTicks - _LastClickTicks;
long elapsedTime = elapsedTicks / TimeSpan.TicksPerMillisecond;
bool quickClick = (elapsedTime <= k_DoubleClickSpeed );
bool senderMatch = (_LastSender != null && sender.Equals(_LastSender.Target));
if (senderMatch && quickClick && Distance(position, _LastPosition) <= k_MaxMoveDistance)
{
// Double click!
_LastClickTicks = 0;
_LastSender = null;
return true;
}
// Not a double click
_LastClickTicks = clickTicks;
_LastPosition = position;
if (!quickClick)
_LastSender = new WeakReference(sender);
return false;
}
private static double Distance(Point pointA, Point pointB)
{
double x = pointA.X - pointB.X;
double y = pointA.Y - pointB.Y;
return Math.Sqrt(x * x + y * y);
}
}
}
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ThumbnailView/ThumbnailView.cs

@ -27,7 +27,7 @@ using System.Windows.Controls.Primitives; @@ -27,7 +27,7 @@ using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Diagnostics;
using ICSharpCode.WpfDesign.Designer.Controls;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Designer.ThumbnailView
{

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

@ -85,7 +85,12 @@ @@ -85,7 +85,12 @@
</Compile>
<Compile Include="ArrangeDirection.cs" />
<Compile Include="Controls\RenderTransformOriginThumb.cs" />
<Compile Include="Controls\Thumbs\PointThumb.cs" />
<Compile Include="Controls\Thumbs\ResizeThumb.cs" />
<Compile Include="Extensions\BorderForImageControl.cs" />
<Compile Include="Extensions\DrawLineExtension.cs" />
<Compile Include="Extensions\DrawPathExtension.cs" />
<Compile Include="Extensions\DrawPolyLineExtension.cs" />
<Compile Include="Extensions\DefaultCommandsContextMenu.xaml.cs">
<DependentUpon>DefaultCommandsContextMenu.xaml</DependentUpon>
<SubType>Code</SubType>
@ -93,11 +98,17 @@ @@ -93,11 +98,17 @@
<Compile Include="Extensions\DefaultCommandsContextMenuExtension.cs" />
<Compile Include="Extensions\LineExtensionBase.cs" />
<Compile Include="Extensions\LineHandlerExtension.cs" />
<Compile Include="Extensions\MultiPointResizeThumb.cs" />
<Compile Include="Controls\Thumbs\MultiPointThumb.cs" />
<Compile Include="Extensions\PartialPanelSelectionHandler.cs" />
<Compile Include="Extensions\EditStyleContextMenu.xaml.cs">
<DependentUpon>EditStyleContextMenu.xaml</DependentUpon>
</Compile>
<Compile Include="Extensions\PathContextMenu.xaml.cs">
<DependentUpon>PathContextMenu.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Extensions\PathContextMenuExtension.cs" />
<Compile Include="Extensions\PathHandlerExtension.cs" />
<Compile Include="Extensions\PointTrackerPlacementSupport.cs" />
<Compile Include="Extensions\PolyLineHandlerExtension.cs" />
<Compile Include="Extensions\TextBlockRightClickContextMenu.xaml.cs">
@ -175,10 +186,10 @@ @@ -175,10 +186,10 @@
<Compile Include="Controls\PageClone.cs" />
<Compile Include="Controls\PanelMoveAdorner.cs" />
<Compile Include="Controls\QuickOperationMenu.cs" />
<Compile Include="Controls\RotateThumb.cs" />
<Compile Include="Controls\Thumbs\RotateThumb.cs" />
<Compile Include="Controls\SelectionFrame.cs" />
<Compile Include="Controls\ErrorBalloon.cs" />
<Compile Include="Controls\ResizeThumb.cs" />
<Compile Include="Controls\Thumbs\DesignerThumb.cs" />
<Compile Include="CallExtension.cs" />
<Compile Include="Controls\DragListener.cs" />
<Compile Include="Controls\SizeDisplay.cs" />
@ -294,7 +305,6 @@ @@ -294,7 +305,6 @@
<Compile Include="Services\XamlErrorService.cs" />
<Compile Include="SharedInstances.cs" />
<Compile Include="ThumbnailView\ThumbnailView.cs" />
<Compile Include="UIExtensions\UIHelpers.cs" />
<Compile Include="Xaml\XamlEditOperations.cs" />
<Compile Include="Xaml\XamlLoadSettings.cs" />
<Compile Include="Xaml\XamlModelCollectionElementsCollection.cs" />
@ -310,6 +320,7 @@ @@ -310,6 +320,7 @@
<Page Include="Extensions\EditStyleContextMenu.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Extensions\PathContextMenu.xaml" />
<Page Include="Extensions\TextBlockRightClickContextMenu.xaml">
<SubType>Designer</SubType>
</Page>

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

@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -29,7 +29,7 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
sealed class XamlComponentService : IComponentService
{
public event EventHandler<DesignItemPropertyChangedEventArgs> PropertyChanged;
#region IdentityEqualityComparer
sealed class IdentityEqualityComparer : IEqualityComparer<object>
{
@ -69,7 +69,17 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -69,7 +69,17 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
_sites.TryGetValue(component, out site);
return site;
}
public void SetDefaultPropertyValues(DesignItem designItem)
{
var values = Metadata.GetDefaultPropertyValues(designItem.ComponentType);
if (values != null) {
foreach (var value in values) {
designItem.Properties[value.Key].SetValue(value.Value);
}
}
}
public DesignItem RegisterComponentForDesigner(object component)
{
if (component == null) {
@ -79,7 +89,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml @@ -79,7 +89,8 @@ namespace ICSharpCode.WpfDesign.Designer.Xaml
}
XamlDesignItem item = new XamlDesignItem(_context.Document.CreateObject(component), _context);
_sites.Add(component, item);
if (!(component is string))
_sites.Add(component, item);
if (ComponentRegistered != null) {
ComponentRegistered(this, new DesignItemEventArgs(item));
}

2
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/XamlDom/NamescopeTest.cs

@ -11,7 +11,7 @@ using System.Xml; @@ -11,7 +11,7 @@ using System.Xml;
using ICSharpCode.WpfDesign.XamlDom;
using NUnit.Framework;
using ICSharpCode.WpfDesign.Designer;
using ICSharpCode.WpfDesign.Designer.UIExtensions;
using ICSharpCode.WpfDesign.UIExtensions;
namespace ICSharpCode.WpfDesign.Tests.XamlDom
{

45
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/CollectionSupport.cs

@ -21,6 +21,7 @@ using System.Diagnostics; @@ -21,6 +21,7 @@ using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Documents;
@ -39,11 +40,11 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -39,11 +40,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
public static bool IsCollectionType(Type type)
{
return type != typeof(LineBreak) && (
typeof(IList).IsAssignableFrom(type)
typeof(IList).IsAssignableFrom(type)
|| type.IsArray
|| typeof(IAddChild).IsAssignableFrom(type)
|| typeof(IDictionary).IsAssignableFrom(type));
}
}
/// <summary>
/// Gets if the collection type <paramref name="col"/> can accepts items of type
@ -85,12 +86,12 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -85,12 +86,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
} else if (collectionInstance is IDictionary) {
object val = newElement.GetValueFor(null);
object key = newElement is XamlObject ? ((XamlObject)newElement).GetXamlAttribute("Key") : null;
if (key == null || key == "")
{
if (val is Style)
key = ((Style)val).TargetType;
}
if (key == null || (key as string) == "")
if (key == null || key == "")
{
if (val is Style)
key = ((Style)val).TargetType;
}
if (key == null || (key as string) == "")
key = val;
((IDictionary)collectionInstance).Add(key, val);
} else {
@ -102,10 +103,10 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -102,10 +103,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
/// <summary>
/// <summary>
/// Adds a value at the specified index in the collection.
/// </summary>
public static void Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
public static bool Insert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
{
object value = newElement.GetValueFor(null);
@ -120,14 +121,22 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -120,14 +121,22 @@ namespace ICSharpCode.WpfDesign.XamlDom
else {
list.Insert(index, value);
}
return true;
} else {
var hasInsert = collectionType.GetMethods().Any(x => x.Name == "Insert");
if (hasInsert) {
collectionType.InvokeMember(
"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, collectionInstance,
new object[] { index, value },
CultureInfo.InvariantCulture);
return true;
}
}
else {
collectionType.InvokeMember(
"Insert", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, collectionInstance,
new object[] { index, value },
CultureInfo.InvariantCulture);
}
return false;
}
/// <summary>
@ -137,7 +146,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -137,7 +146,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal static bool TryInsert(Type collectionType, object collectionInstance, XamlPropertyValue newElement, int index)
{
try {
Insert(collectionType, collectionInstance, newElement, index);
return Insert(collectionType, collectionInstance, newElement, index);
} catch (MissingMethodException) {
return false;
}

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

@ -60,7 +60,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -60,7 +60,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Path");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue);
AppendPropertyValue(sb, p.PropertyValue, false);
properties.Remove(p);
first = false;
}
@ -69,7 +69,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -69,7 +69,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="Name");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue);
AppendPropertyValue(sb, p.PropertyValue, false);
properties.Remove(p);
first = false;
}
@ -78,7 +78,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -78,7 +78,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
var p=obj.Properties.FirstOrDefault(x=>x.PropertyName=="ResourceKey");
if (p!=null && p.IsSet) {
sb.Append(" ");
AppendPropertyValue(sb, p.PropertyValue);
AppendPropertyValue(sb, p.PropertyValue, false);
properties.Remove(p);
first = false;
}
@ -96,13 +96,13 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -96,13 +96,13 @@ namespace ICSharpCode.WpfDesign.XamlDom
sb.Append(property.GetNameForMarkupExtension());
sb.Append("=");
AppendPropertyValue(sb, property.PropertyValue);
AppendPropertyValue(sb, property.PropertyValue, property.ReturnType == typeof(string));
}
sb.Append("}");
return sb.ToString();
}
private static void AppendPropertyValue(StringBuilder sb, XamlPropertyValue value)
private static void AppendPropertyValue(StringBuilder sb, XamlPropertyValue value, bool isStringProperty)
{
var textValue = value as XamlTextValue;
if (textValue != null) {
@ -113,7 +113,10 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -113,7 +113,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
sb.Append('\'');
}
sb.Append(text.Replace("\\", "\\\\"));
if (isStringProperty)
sb.Append(text.Replace("\\", "\\\\").Replace("{", "\\{").Replace("}", "\\}"));
else
sb.Append(text.Replace("\\", "\\\\"));
if(containsSpace) {
sb.Append('\'');

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

@ -94,5 +94,6 @@ @@ -94,5 +94,6 @@
<Compile Include="XamlTextValue.cs" />
<Compile Include="XamlTypeFinder.cs" />
<Compile Include="XamlTypeResolverProvider.cs" />
<Compile Include="XamlXmlWriter.cs" />
</ItemGroup>
</Project>

21
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObjectServiceProvider.cs

@ -18,7 +18,9 @@ @@ -18,7 +18,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Markup;
using System.Xaml;
@ -29,7 +31,7 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -29,7 +31,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
/// A service provider that provides the IProvideValueTarget and IXamlTypeResolver services.
/// No other services (e.g. from the document's service provider) are offered.
/// </summary>
public class XamlObjectServiceProvider : IServiceProvider, IXamlNameResolver, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider
public class XamlObjectServiceProvider : IServiceProvider, IXamlNameResolver, IProvideValueTarget, IXamlSchemaContextProvider, IAmbientProvider, IUriContext
{
/// <summary>
/// Creates a new XamlObjectServiceProvider instance.
@ -75,6 +77,10 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -75,6 +77,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
{
return this;
}
if (serviceType == typeof(IUriContext))
{
return this;
}
return null;
}
@ -119,6 +125,19 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -119,6 +125,19 @@ namespace ICSharpCode.WpfDesign.XamlDom
#endregion
#region IUriContext implementation
public virtual Uri BaseUri {
get {
return new Uri("pack://application:,,,/");
}
set {
}
}
#endregion
#region IXamlSchemaContextProvider Members
private XamlSchemaContext iCsharpXamlSchemaContext;

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

@ -223,8 +223,10 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -223,8 +223,10 @@ namespace ICSharpCode.WpfDesign.XamlDom
ResetInternal();
propertyValue = value;
propertyValue.ParentProperty = this;
propertyValue.AddNodeTo(this);
if (propertyValue != null) {
propertyValue.ParentProperty = this;
propertyValue.AddNodeTo(this);
}
UpdateValueOnInstance();
ParentObject.OnPropertyChanged(this);
@ -261,8 +263,8 @@ namespace ICSharpCode.WpfDesign.XamlDom @@ -261,8 +263,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
((FrameworkElement)this.ParentObject.Instance).Height = (double)ValueOnInstance;
}
}
catch {
Debug.WriteLine("UpdateValueOnInstance() failed");
catch (Exception ex) {
Debug.WriteLine("UpdateValueOnInstance() failed - Exception:" + ex.Message);
}
}
}

156
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlXmlWriter.cs

@ -0,0 +1,156 @@ @@ -0,0 +1,156 @@
/*
* Created by SharpDevelop.
* User: jkuehner
* Date: 30.01.2015
* Time: 09:56
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Xml;
namespace ICSharpCode.WpfDesign.XamlDom
{
/// <summary>
/// Description of XamlXmlWriter.
/// </summary>
public class XamlXmlWriter : XmlWriter
{
protected XmlWriter xmlWriter;
public XamlXmlWriter(System.Text.StringBuilder stringBuilder)
{
this.xmlWriter = XmlWriter.Create(stringBuilder);
}
#region implemented abstract members of XmlWriter
public override void WriteStartDocument()
{
xmlWriter.WriteStartDocument();
}
public override void WriteStartDocument(bool standalone)
{
xmlWriter.WriteStartDocument(standalone);
}
public override void WriteEndDocument()
{
xmlWriter.WriteEndDocument();
}
public override void WriteDocType(string name, string pubid, string sysid, string subset)
{
xmlWriter.WriteDocType(name, pubid, sysid, subset);
}
public override void WriteStartElement(string prefix, string localName, string ns)
{
xmlWriter.WriteStartElement(prefix, localName, ns);
}
public override void WriteEndElement()
{
xmlWriter.WriteEndElement();
}
public override void WriteFullEndElement()
{
xmlWriter.WriteFullEndElement();
}
public override void WriteStartAttribute(string prefix, string localName, string ns)
{
xmlWriter.WriteStartAttribute(prefix, localName, ns);
}
public override void WriteEndAttribute()
{
xmlWriter.WriteEndAttribute();
}
public override void WriteCData(string text)
{
xmlWriter.WriteCData(text);
}
public override void WriteComment(string text)
{
xmlWriter.WriteComment(text);
}
public override void WriteProcessingInstruction(string name, string text)
{
xmlWriter.WriteProcessingInstruction(name, text);
}
public override void WriteEntityRef(string name)
{
xmlWriter.WriteEntityRef(name);
}
public override void WriteCharEntity(char ch)
{
xmlWriter.WriteCharEntity(ch);
}
public override void WriteWhitespace(string ws)
{
xmlWriter.WriteWhitespace(ws);
}
public override void WriteString(string text)
{
xmlWriter.WriteString(text.Replace("&","&amp;").Replace("\"","&quot;"));
}
public override void WriteSurrogateCharEntity(char lowChar, char highChar)
{
xmlWriter.WriteSurrogateCharEntity(lowChar, highChar);
}
public override void WriteChars(char[] buffer, int index, int count)
{
xmlWriter.WriteChars(buffer, index, count);
}
public override void WriteRaw(char[] buffer, int index, int count)
{
xmlWriter.WriteRaw(buffer, index, count);
}
public override void WriteRaw(string data)
{
xmlWriter.WriteRaw(data);
}
public override void WriteBase64(byte[] buffer, int index, int count)
{
xmlWriter.WriteBase64(buffer, index, count);
}
public override void Close()
{
xmlWriter.Close();
}
public override void Flush()
{
xmlWriter.Flush();
}
public override string LookupPrefix(string ns)
{
return xmlWriter.LookupPrefix(ns);
}
public override WriteState WriteState {
get {
return xmlWriter.WriteState;
}
}
#endregion
}
}

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

@ -22,7 +22,11 @@ using System.ComponentModel; @@ -22,7 +22,11 @@ using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ICSharpCode.WpfDesign.UIExtensions;
using ICSharpCode.WpfDesign.Extensions;
using System.Linq;
namespace ICSharpCode.WpfDesign
{
@ -131,9 +135,7 @@ namespace ICSharpCode.WpfDesign @@ -131,9 +135,7 @@ namespace ICSharpCode.WpfDesign
/// </summary>
public IEnumerable<Extension> Extensions {
get {
foreach (ExtensionEntry entry in _extensions) {
yield return entry.Extension;
}
return _extensions.Select(x => x.Extension).ToList();
}
}
@ -196,6 +198,17 @@ namespace ICSharpCode.WpfDesign @@ -196,6 +198,17 @@ namespace ICSharpCode.WpfDesign
});
}
}
public void ReapplyAllExtensions()
{
var manager = this.Services.GetService<Extensions.ExtensionManager>();
foreach (var e in this._extensions.ToList()) {
ApplyUnapplyExtensionServer(manager, false, e.Server);
ApplyUnapplyExtensionServer(manager, true, e.Server);
}
}
#endregion
#region Manage behavior
@ -279,5 +292,24 @@ namespace ICSharpCode.WpfDesign @@ -279,5 +292,24 @@ namespace ICSharpCode.WpfDesign
/// Creates a copy of this design item.
/// </summary>
public abstract DesignItem Clone();
public Transform GetCompleteAppliedTransformationToView()
{
var retVal = new TransformGroup();
var v = this.View as Visual;
while (v != null) {
var fe = v as FrameworkElement;
if (fe != null && fe.LayoutTransform != null)
retVal.Children.Add(fe.LayoutTransform);
if (fe != null && fe.RenderTransform != null)
retVal.Children.Add(fe.RenderTransform);
if (v is ContainerVisual && ((ContainerVisual)v).Transform != null) {
retVal.Children.Add(((ContainerVisual)v).Transform);
}
v = v.TryFindParent<Visual>(true);
}
return retVal;
}
}
}

35
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/DrawItemExtension.cs

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
// 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.Windows;
using System.Windows.Input;
namespace ICSharpCode.WpfDesign
{
/// <summary>
/// Behavior interface implemented by container elements to support resizing
/// drawing new Elements
/// </summary>
public interface IDrawItemExtension
{
bool CanItemBeDrawn(Type createItemType);
void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e);
}
}

32
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/Metadata.cs

@ -45,6 +45,8 @@ namespace ICSharpCode.WpfDesign @@ -45,6 +45,8 @@ namespace ICSharpCode.WpfDesign
// Why not per-design context (as a service?)
static Dictionary<Type, List<object>> standardValues = new Dictionary<Type, List<object>>();
static Dictionary<Type, Dictionary<DependencyProperty, object>> standardPropertyValues = new Dictionary<Type, Dictionary<DependencyProperty, object>>();
/// <summary>
/// Registers a set of standard values for a <paramref name="type"/> by using the
/// public static properties of the type <paramref name="valuesContainer"/>.
@ -321,11 +323,39 @@ namespace ICSharpCode.WpfDesign @@ -321,11 +323,39 @@ namespace ICSharpCode.WpfDesign
if (defaultSizes.TryGetValue(t, out s)) {
return s;
}
t = checkBasetype ? t.BaseType : null;
t = checkBasetype ? t.BaseType : null;
}
}
return null;
}
/// <summary>
/// Registers a default Property Value wich should be used
/// </summary>
public static void AddDefaultPropertyValue(Type t, DependencyProperty p, object value)
{
lock (standardPropertyValues)
{
if (!standardPropertyValues.ContainsKey(t))
standardPropertyValues.Add(t, new Dictionary<DependencyProperty, object>());
standardPropertyValues[t][p] = value;
}
}
/// <summary>
/// Gets Default Propertie Values for a type
/// </summary>
public static Dictionary<DependencyProperty, object> GetDefaultPropertyValues(Type t)
{
lock (standardPropertyValues)
{
if (standardPropertyValues.ContainsKey(t))
return standardPropertyValues[t];
return null;
}
}
}
/// <summary>

5
src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementBehavior.cs

@ -78,6 +78,11 @@ namespace ICSharpCode.WpfDesign @@ -78,6 +78,11 @@ namespace ICSharpCode.WpfDesign
/// Let the placed children enter this container.
/// </summary>
void EnterContainer(PlacementOperation operation);
/// <summary>
/// Place Point.
/// </summary>
Point PlacePoint(Point point);
}
/// <summary>

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

@ -25,6 +25,12 @@ namespace ICSharpCode.WpfDesign @@ -25,6 +25,12 @@ namespace ICSharpCode.WpfDesign
/// </summary>
public sealed class PlacementType
{
/// <summary>
/// Placement is done by Moving a inner Point (for Example on Path, Line, ...)
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly PlacementType MovePoint = Register("MovePoint");
/// <summary>
/// Placement is done by resizing an element in a drag'n'drop operation.
/// </summary>
@ -51,10 +57,10 @@ namespace ICSharpCode.WpfDesign @@ -51,10 +57,10 @@ namespace ICSharpCode.WpfDesign
public static readonly PlacementType Delete = Register("Delete");
/// <summary>
/// Inserting from Cliboard
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly PlacementType PasteItem = Register("PasteItem");
/// Inserting from Cliboard
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly PlacementType PasteItem = Register("PasteItem");
readonly string name;

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

@ -129,6 +129,9 @@ namespace ICSharpCode.WpfDesign @@ -129,6 +129,9 @@ namespace ICSharpCode.WpfDesign
/// <summary>Property Changed</summary>
event EventHandler<DesignItemPropertyChangedEventArgs> PropertyChanged;
/// <summary> Set's default Property Values as defined in Metadata </summary>
void SetDefaultPropertyValues(DesignItem designItem);
}
#endregion

40
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/UIExtensions/UIHelpers.cs → src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/UIExtensions/UIHelpers.cs

@ -23,37 +23,39 @@ using System.Text; @@ -23,37 +23,39 @@ using System.Text;
using System.Windows;
using System.Windows.Media;
namespace ICSharpCode.WpfDesign.Designer.UIExtensions
namespace ICSharpCode.WpfDesign.UIExtensions
{
public static class UIHelpers
{
public static DependencyObject GetParentObject(this DependencyObject child)
public static DependencyObject GetParentObject(this DependencyObject child, bool searchCompleteVisualTree)
{
if (child == null) return null;
var contentElement = child as ContentElement;
if (contentElement != null)
{
DependencyObject parent = ContentOperations.GetParent(contentElement);
if (parent != null) return parent;
var fce = contentElement as FrameworkContentElement;
return fce != null ? fce.Parent : null;
}
var frameworkElement = child as FrameworkElement;
if (frameworkElement != null)
{
DependencyObject parent = frameworkElement.Parent;
if (parent != null) return parent;
if (!searchCompleteVisualTree) {
var contentElement = child as ContentElement;
if (contentElement != null)
{
DependencyObject parent = ContentOperations.GetParent(contentElement);
if (parent != null) return parent;
var fce = contentElement as FrameworkContentElement;
return fce != null ? fce.Parent : null;
}
var frameworkElement = child as FrameworkElement;
if (frameworkElement != null)
{
DependencyObject parent = frameworkElement.Parent;
if (parent != null) return parent;
}
}
return VisualTreeHelper.GetParent(child);
}
public static T TryFindParent<T>(this DependencyObject child) where T : DependencyObject
public static T TryFindParent<T>(this DependencyObject child, bool searchCompleteVisualTree = false) where T : DependencyObject
{
DependencyObject parentObject = GetParentObject(child);
DependencyObject parentObject = GetParentObject(child, searchCompleteVisualTree);
if (parentObject == null) return null;

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

@ -73,6 +73,7 @@ @@ -73,6 +73,7 @@
<Compile Include="Adorners\AdornerProvider.cs" />
<Compile Include="Adorners\AdornerProviderClasses.cs" />
<Compile Include="Adorners\RelativePlacement.cs" />
<Compile Include="DrawItemExtension.cs" />
<Compile Include="DummyValueInsteadOfNullTypeDescriptionProvider.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="Extensions\ExtensionAttribute.cs" />
@ -115,8 +116,12 @@ @@ -115,8 +116,12 @@
<Compile Include="ServiceRequiredException.cs" />
<Compile Include="Services.cs" />
<Compile Include="Tools.cs" />
<Compile Include="UIExtensions\UIHelpers.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="Configuration\CodeAnalysisDictionary.xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="UIExtensions" />
</ItemGroup>
</Project>

78
src/AddIns/Misc/PackageManagement/Project/Src/Design/FakeSettings.cs

@ -26,18 +26,18 @@ namespace ICSharpCode.PackageManagement.Design @@ -26,18 +26,18 @@ namespace ICSharpCode.PackageManagement.Design
{
public class FakeSettings : ISettings
{
public List<KeyValuePair<string, string>> PackageSources
= new List<KeyValuePair<string, string>>();
public List<SettingValue> PackageSources
= new List<SettingValue> ();
public List<KeyValuePair<string, string>> DisabledPackageSources
= new List<KeyValuePair<string, string>>();
public List<SettingValue> DisabledPackageSources
= new List<SettingValue> ();
public List<KeyValuePair<string, string>> ActivePackageSourceSettings =
new List<KeyValuePair<string, string>>();
public List<SettingValue> ActivePackageSourceSettings =
new List<SettingValue> ();
public Dictionary<string, IList<SettingValue>> Sections
= new Dictionary<string, IList<SettingValue>> ();
public Dictionary<string, IList<KeyValuePair<string, string>>> Sections
= new Dictionary<string, IList<KeyValuePair<string, string>>>();
public const string ConfigSectionName = "config";
public FakeSettings()
@ -47,29 +47,24 @@ namespace ICSharpCode.PackageManagement.Design @@ -47,29 +47,24 @@ namespace ICSharpCode.PackageManagement.Design
Sections.Add(RegisteredPackageSourceSettings.DisabledPackageSourceSectionName, DisabledPackageSources);
}
public string GetValue(string section, string key)
public string GetValue(string section, string key, bool isPath)
{
if (!Sections.ContainsKey(section))
return null;
IList<KeyValuePair<string, string>> values = Sections[section];
foreach (KeyValuePair<string, string> keyPair in values) {
if (keyPair.Key == key) {
return keyPair.Value;
}
if (Sections.ContainsKey(section)) {
var matchedSection = Sections[section];
return matchedSection.FirstOrDefault(item => item.Key == key).Value;
}
return null;
}
public IList<KeyValuePair<string, string>> GetValues(string section)
public IList<SettingValue> GetValues(string section, bool isPath)
{
return Sections[section];
}
public void AddFakePackageSource(PackageSource packageSource)
{
var valuePair = new KeyValuePair<string, string>(packageSource.Name, packageSource.Source);
PackageSources.Add(valuePair);
var setting = new SettingValue (packageSource.Name, packageSource.Source, false);
PackageSources.Add(setting);
}
public Dictionary<string, KeyValuePair<string, string>> SavedSectionValues =
@ -134,8 +129,8 @@ namespace ICSharpCode.PackageManagement.Design @@ -134,8 +129,8 @@ namespace ICSharpCode.PackageManagement.Design
public void SetFakeActivePackageSource(PackageSource packageSource)
{
ActivePackageSourceSettings.Clear();
var valuePair = new KeyValuePair<string, string>(packageSource.Name, packageSource.Source);
ActivePackageSourceSettings.Add(valuePair);
var setting = new SettingValue(packageSource.Name, packageSource.Source, false);
ActivePackageSourceSettings.Add(setting);
}
public void MakeActivePackageSourceSectionNull()
@ -157,9 +152,9 @@ namespace ICSharpCode.PackageManagement.Design @@ -157,9 +152,9 @@ namespace ICSharpCode.PackageManagement.Design
}
}
public IList<KeyValuePair<string, string>> GetNestedValues(string section, string key)
public IList<SettingValue> GetNestedValues(string section, string key)
{
return new List<KeyValuePair<string, string>>();
return new List<SettingValue>();
}
public virtual void SetNestedValues(string section, string key, IList<KeyValuePair<string, string>> values)
@ -169,8 +164,8 @@ namespace ICSharpCode.PackageManagement.Design @@ -169,8 +164,8 @@ namespace ICSharpCode.PackageManagement.Design
public void AddDisabledPackageSource(PackageSource packageSource)
{
var valuePair = new KeyValuePair<string, string>(packageSource.Name, packageSource.Source);
DisabledPackageSources.Add(valuePair);
var setting = new SettingValue(packageSource.Name, packageSource.Source, false);
DisabledPackageSources.Add(setting);
}
public IList<KeyValuePair<string, string>> GetValuesPassedToSetValuesForDisabledPackageSourcesSection()
@ -186,8 +181,8 @@ namespace ICSharpCode.PackageManagement.Design @@ -186,8 +181,8 @@ namespace ICSharpCode.PackageManagement.Design
public virtual void SetPackageRestoreSetting(bool enabled)
{
var items = new List<KeyValuePair<string, string>>();
items.Add(new KeyValuePair<string, string>("enabled", enabled.ToString()));
var items = new List<SettingValue> ();
items.Add(new SettingValue("enabled", enabled.ToString(), false));
Sections.Add("packageRestore", items);
}
@ -202,31 +197,10 @@ namespace ICSharpCode.PackageManagement.Design @@ -202,31 +197,10 @@ namespace ICSharpCode.PackageManagement.Design
}
}
public string GetValue(string section, string key, bool isPath)
{
if (Sections.ContainsKey(section)) {
var matchedSection = Sections[section];
return matchedSection.FirstOrDefault(item => item.Key == key).Value;
}
return null;
}
public IList<KeyValuePair<string, string>> GetValues(string section, bool isPath)
{
throw new NotImplementedException();
}
public IList<SettingValue> GetSettingValues(string section, bool isPath)
{
return Sections[section]
.Select(item => new SettingValue(item.Key, item.Value, false))
.ToList();
}
public void SetRepositoryPathSetting(string fullPath)
{
var items = new List<KeyValuePair<string, string>> ();
items.Add (new KeyValuePair<string, string>("repositoryPath", fullPath));
var items = new List<SettingValue>();
items.Add (new SettingValue("repositoryPath", fullPath, false));
Sections.Add(ConfigSectionName, items);
}
}

14
src/AddIns/Misc/PackageManagement/Project/Src/PackageSourceConverter.cs

@ -25,16 +25,16 @@ namespace ICSharpCode.PackageManagement @@ -25,16 +25,16 @@ namespace ICSharpCode.PackageManagement
{
public static class PackageSourceConverter
{
public static IEnumerable<PackageSource> ConvertFromKeyValuePairs(IEnumerable<KeyValuePair<string, string>> packageSources)
public static IEnumerable<PackageSource> ConvertFromSettings(IEnumerable<SettingValue> packageSources)
{
if (HasAny(packageSources)) {
foreach (KeyValuePair<string, string> packageSource in packageSources) {
yield return CreatePackageSourceFromKeyValuePair(packageSource);
foreach (SettingValue packageSource in packageSources) {
yield return CreatePackageSourceFromSetting(packageSource);
}
}
}
static bool HasAny(IEnumerable<KeyValuePair<string, string>> packageSources)
static bool HasAny(IEnumerable<SettingValue> packageSources)
{
if (packageSources != null) {
return packageSources.Any();
@ -42,17 +42,17 @@ namespace ICSharpCode.PackageManagement @@ -42,17 +42,17 @@ namespace ICSharpCode.PackageManagement
return false;
}
static PackageSource CreatePackageSourceFromKeyValuePair(KeyValuePair<string, string> savedPackageSource)
static PackageSource CreatePackageSourceFromSetting(SettingValue savedPackageSource)
{
string source = savedPackageSource.Value;
string name = savedPackageSource.Key;
return new PackageSource(source, name);
}
public static PackageSource ConvertFromFirstKeyValuePair(IEnumerable<KeyValuePair<string, string>> packageSources)
public static PackageSource ConvertFromFirstSetting(IEnumerable<SettingValue> packageSources)
{
if (HasAny(packageSources)) {
return CreatePackageSourceFromKeyValuePair(packageSources.First());
return CreatePackageSourceFromSetting(packageSources.First());
}
return null;
}

4
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourceSettings.cs

@ -76,8 +76,8 @@ namespace ICSharpCode.PackageManagement @@ -76,8 +76,8 @@ namespace ICSharpCode.PackageManagement
void ReadActivePackageSource()
{
IList<KeyValuePair<string, string>> packageSources = settings.GetValues(ActivePackageSourceSectionName);
activePackageSource = PackageSourceConverter.ConvertFromFirstKeyValuePair(packageSources);
IList<SettingValue> packageSources = settings.GetValues(ActivePackageSourceSectionName, false);
activePackageSource = PackageSourceConverter.ConvertFromFirstSetting(packageSources);
}
public RegisteredPackageSources PackageSources {

BIN
src/AddIns/Misc/PackageManagement/RequiredLibraries/NuGet.Console.Types.dll

Binary file not shown.

BIN
src/AddIns/Misc/PackageManagement/RequiredLibraries/NuGet.Core.dll

Binary file not shown.

BIN
src/AddIns/Misc/PackageManagement/RequiredLibraries/NuGet.exe

Binary file not shown.

4
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs

@ -39,9 +39,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -39,9 +39,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
public string DefaultAlias { get; set; }
public Version AssemblyVersion { get; set; }
public string AssemblyVersion { get; set; }
public Version AssemblyFileVersion { get; set; }
public string AssemblyFileVersion { get; set; }
public string InformationalVersion { get; set; }

4
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml

@ -88,10 +88,10 @@ @@ -88,10 +88,10 @@
<TextBox Text="{Binding DefaultAlias, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.AssemblyVersion}" Grid.Column="0" Grid.Row="7"/>
<projectOptions:VersionEditor Version="{Binding AssemblyVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="7"/>
<projectOptions:VersionEditor Version="{Binding AssemblyVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Type="Assembly" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="7"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.FileVersion}" Grid.Column="0" Grid.Row="8"/>
<projectOptions:VersionEditor Version="{Binding AssemblyFileVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="8"/>
<projectOptions:VersionEditor Version="{Binding AssemblyFileVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Type="File" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="8"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.InformationalVersion}" Grid.Column="0" Grid.Row="9"/>
<TextBox Text="{Binding InformationalVersion, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="9"/>

21
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs

@ -122,11 +122,11 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -122,11 +122,11 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
break;
case AssemblyVersion:
case AssemblyVersion + Attribute:
assemblyInfo.AssemblyVersion = GetAttributeValueAsVersion(attribute);
assemblyInfo.AssemblyVersion = GetAttributeValue<string>(attribute);
break;
case AssemblyFileVersion:
case AssemblyFileVersion + Attribute:
assemblyInfo.AssemblyFileVersion = GetAttributeValueAsVersion(attribute);
assemblyInfo.AssemblyFileVersion = GetAttributeValue<string>(attribute);
break;
case AssemblyInformationalVersion:
case AssemblyInformationalVersion + Attribute:
@ -268,23 +268,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -268,23 +268,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
return null;
}
private Version GetAttributeValueAsVersion(Attribute attribute)
{
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray();
if (attributeArguments.Length == 1)
{
var versionString = attributeArguments[0].Value as string;
if (!string.IsNullOrEmpty(versionString))
{
Version version;
if (Version.TryParse(versionString, out version))
return version;
}
}
return null;
}
private AssemblyNameFlags GetAssemblyFlagsFromAttribute(Attribute attribute)
{
if (attribute.Arguments.Count == 1)

4
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoViewModel.cs

@ -92,13 +92,13 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -92,13 +92,13 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
set { assemblyInfo.DefaultAlias = value; OnPropertyChanged(); }
}
public Version AssemblyVersion
public string AssemblyVersion
{
get { return assemblyInfo.AssemblyVersion; }
set { assemblyInfo.AssemblyVersion = value; OnPropertyChanged(); }
}
public Version AssemblyFileVersion
public string AssemblyFileVersion
{
get { return assemblyInfo.AssemblyFileVersion; }
set { assemblyInfo.AssemblyFileVersion = value; OnPropertyChanged(); }

8
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml

@ -11,9 +11,9 @@ @@ -11,9 +11,9 @@
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox Name="majorTextBox" Grid.Column="0" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="minorTextBox" Grid.Column="1" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="buildTextBox" Grid.Column="2" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="revisionTextBox" Grid.Column="3" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="majorTextBox" Grid.Column="0" TextChanged="OnTextChanged"/>
<TextBox Name="minorTextBox" Grid.Column="1" TextChanged="OnTextChanged"/>
<TextBox Name="buildTextBox" Grid.Column="2" TextChanged="OnTextChanged"/>
<TextBox Name="revisionTextBox" Grid.Column="3" TextChanged="OnTextChanged"/>
</Grid>
</UserControl>

186
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
@ -30,26 +31,129 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions @@ -30,26 +31,129 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions
public partial class VersionEditor
{
public static DependencyProperty VersionProperty =
DependencyProperty.Register("Version", typeof(Version), typeof(VersionEditor), new PropertyMetadata(OnVersionChanged));
DependencyProperty.Register("Version", typeof(string), typeof(VersionEditor), new PropertyMetadata(OnVersionChanged));
public static DependencyProperty TypeProperty =
DependencyProperty.Register("Type", typeof(VersionType), typeof(VersionEditor));
public VersionEditor()
{
InitializeComponent();
}
public Version Version
public string Version
{
get { return GetValue(VersionProperty) as Version; }
get { return GetValue(VersionProperty) as string; }
set { SetValue(VersionProperty, value); }
}
private void OnTextBoxPreviewTextInput(object sender, TextCompositionEventArgs e)
public VersionType Type
{
// Block any non-character input
if (!e.Text.All(char.IsDigit))
get { return (VersionType)GetValue(TypeProperty); }
set { SetValue(TypeProperty, value); }
}
public enum VersionType
{
Assembly,
File,
Info,
}
enum AllowedType
{
Integer,
Star,
Empty,
String,
}
static readonly AllowedType[][] assemblyVersionTypes =
{
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Integer },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Star },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Star, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Empty, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Star, AllowedType.Empty, AllowedType.Empty },
};
static readonly AllowedType[][] fileVersionTypes =
{
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Integer },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Empty, AllowedType.Empty, AllowedType.Empty },
};
static readonly AllowedType[][] infoVersionTypes =
{
new [] { AllowedType.String, AllowedType.String, AllowedType.String, AllowedType.String },
new [] { AllowedType.String, AllowedType.String, AllowedType.String, AllowedType.Empty },
new [] { AllowedType.String, AllowedType.String, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.String, AllowedType.Empty, AllowedType.Empty, AllowedType.Empty },
};
static readonly int[] assemblyVersionRange = { 0, 65534 };
static readonly int[] fileVersionRange = { 0, 65535 };
AllowedType[] GetAllowedType(string[] parts)
{
AllowedType[][] types = GetAllowedTypes();
int[] range = GetAllowedRange();
bool allowed = false;
foreach (var element in types)
{
e.Handled = true;
allowed = true;
for (int i = 0; i < parts.Length; i++)
{
int t;
switch (element[i])
{
case AllowedType.Integer:
if (!int.TryParse(parts[i], out t))
allowed = false;
if (range != null && (t < range[0] || t > range[1]))
allowed = false;
break;
case AllowedType.Star:
if (parts[i] != "*")
allowed = false;
break;
case AllowedType.Empty:
if (!string.IsNullOrEmpty(parts[i]))
allowed = false;
break;
case AllowedType.String:
if (string.IsNullOrEmpty(parts[i]))
allowed = false;
break;
}
if (!allowed)
break;
}
if (allowed)
return element;
}
return null;
}
AllowedType[][] GetAllowedTypes()
{
if (this.Type == VersionType.Assembly)
return assemblyVersionTypes;
if (this.Type == VersionType.File)
return fileVersionTypes;
return infoVersionTypes;
}
int[] GetAllowedRange()
{
if (this.Type == VersionType.Assembly)
return assemblyVersionRange;
if (this.Type == VersionType.File)
return fileVersionRange;
return null;
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
@ -60,39 +164,67 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions @@ -60,39 +164,67 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions
string buildPart = buildTextBox.Text;
string revisionPart = revisionTextBox.Text;
int majorVersion = 0, minorVersion = 0, build = 0, revision = 0;
var majorVersionWasSet = !string.IsNullOrEmpty(majorPart) && int.TryParse(majorPart, out majorVersion);
var minorVersionWasSet = !string.IsNullOrEmpty(minorPart) && int.TryParse(minorPart, out minorVersion);
var buildWasSet = !string.IsNullOrEmpty(buildPart) && int.TryParse(buildPart, out build);
var revisionWasSet = !string.IsNullOrEmpty(revisionPart) && int.TryParse(revisionPart, out revision);
AllowedType[] type = GetAllowedType(new string[] { majorPart, minorPart, buildPart, revisionPart });
if (type == null)
type = GetAllowedType(new string[] { majorPart, minorPart, buildPart, "" });
if (type == null)
type = GetAllowedType(new string[] { majorPart, minorPart, "", "" });
if (type == null)
type = GetAllowedType(new string[] { majorPart, "", "", "" });
Version newVersion;
if (revisionWasSet)
newVersion = new Version(majorVersion, minorVersion, build, revision);
else if (buildWasSet)
newVersion = new Version(majorVersion, minorVersion, build);
else if (majorVersionWasSet || minorVersionWasSet)
newVersion = new Version(majorVersion, minorVersion);
string newVersion;
if (type != null)
{
if (type[3] != AllowedType.Empty)
newVersion = majorPart + "." + minorPart + "." + buildPart + "." + revisionPart;
else if (type[2] != AllowedType.Empty)
newVersion = majorPart + "." + minorPart + "." + buildPart;
else if (type[1] != AllowedType.Empty)
newVersion = majorPart + "." + minorPart;
else if (type[0] != AllowedType.Empty)
newVersion = majorPart;
else
newVersion = "";
}
else
newVersion = new Version();
newVersion = "";
if (!newVersion.Equals(Version))
Version = newVersion;
}
static string[] SplitNParts(string s, char c, int count)
{
var parts = new List<string>();
int pos = 0;
for (int i = 0; i < s.Length; i++)
{
if (s[i] == c)
{
if (parts.Count + 1 == count)
break;
parts.Add(s.Substring(pos, i - pos));
pos = i + 1;
}
}
parts.Add(s.Substring(pos));
return parts.ToArray();
}
private static void OnVersionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var versionEditor = d as VersionEditor;
var newVersion = e.NewValue as Version;
var newVersion = e.NewValue as string;
if (versionEditor != null && newVersion != null)
{
var parts = SplitNParts(newVersion, '.', 4);
// Update textboxes values when version property changes
versionEditor.majorTextBox.Text = newVersion.Major >= 0 ? newVersion.Major.ToString() : string.Empty;
versionEditor.minorTextBox.Text = newVersion.Minor >= 0 ? newVersion.Minor.ToString() : string.Empty;
versionEditor.buildTextBox.Text = newVersion.Build >= 0 ? newVersion.Build.ToString() : string.Empty;
versionEditor.revisionTextBox.Text = newVersion.Revision >= 0 ? newVersion.Revision.ToString() : string.Empty;
versionEditor.majorTextBox.Text = parts.Length > 0 ? parts[0] : string.Empty;
versionEditor.minorTextBox.Text = parts.Length > 1 ? parts[1] : string.Empty;
versionEditor.buildTextBox.Text = parts.Length > 2 ? parts[2] : string.Empty;
versionEditor.revisionTextBox.Text = parts.Length > 3 ? parts[3] : string.Empty;
}
}
}

24
src/Main/Base/Test/ProjectOptions/AssemblyInfoProviderTests.cs

@ -101,8 +101,8 @@ using System.Runtime.InteropServices; @@ -101,8 +101,8 @@ using System.Runtime.InteropServices;
Assert.AreEqual("Copyright 2014", assemblyInfo.Copyright);
Assert.AreEqual("Trademark", assemblyInfo.Trademark);
Assert.AreEqual("Alias", assemblyInfo.DefaultAlias);
Assert.AreEqual(new Version(1, 2, 3, 1), assemblyInfo.AssemblyVersion);
Assert.AreEqual(new Version(1, 2, 3, 2), assemblyInfo.AssemblyFileVersion);
Assert.AreEqual(new Version(1, 2, 3, 1).ToString(), assemblyInfo.AssemblyVersion);
Assert.AreEqual(new Version(1, 2, 3, 2).ToString(), assemblyInfo.AssemblyFileVersion);
Assert.AreEqual(new Version(1, 2, 3, 3).ToString(), assemblyInfo.InformationalVersion);
Assert.AreEqual(new Guid("0c8c889f-ced2-4167-b155-2d48a99d8c72"), assemblyInfo.Guid);
Assert.AreEqual("ru-RU", assemblyInfo.NeutralLanguage);
@ -134,8 +134,8 @@ using System.Runtime.InteropServices; @@ -134,8 +134,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyInformationalVersion (""Incorrect version"")]";
var assemblyInfo = ReadAssemblyInfo(assemblyInfoFile);
Assert.IsNull(assemblyInfo.AssemblyVersion);
Assert.IsNull(assemblyInfo.AssemblyFileVersion);
Assert.AreEqual("Incorrect version", assemblyInfo.AssemblyVersion);
Assert.AreEqual("Incorrect version", assemblyInfo.AssemblyFileVersion);
Assert.AreEqual("Incorrect version", assemblyInfo.InformationalVersion);
}
@ -200,8 +200,8 @@ using System.Runtime.InteropServices; @@ -200,8 +200,8 @@ using System.Runtime.InteropServices;
Assert.AreEqual("", assemblyInfo.Copyright);
Assert.AreEqual("", assemblyInfo.Trademark);
Assert.AreEqual("", assemblyInfo.DefaultAlias);
Assert.IsNull(assemblyInfo.AssemblyVersion);
Assert.IsNull(assemblyInfo.AssemblyFileVersion);
Assert.AreEqual("", assemblyInfo.AssemblyVersion);
Assert.AreEqual("", assemblyInfo.AssemblyFileVersion);
Assert.AreEqual("", assemblyInfo.InformationalVersion);
Assert.IsNull(assemblyInfo.Guid);
Assert.AreEqual("", assemblyInfo.NeutralLanguage);
@ -289,8 +289,8 @@ using System.Runtime.InteropServices; @@ -289,8 +289,8 @@ using System.Runtime.InteropServices;
Assert.AreEqual("Copyright 2014", assemblyInfo.Copyright);
Assert.AreEqual("Trademark", assemblyInfo.Trademark);
Assert.AreEqual("Alias", assemblyInfo.DefaultAlias);
Assert.AreEqual(new Version(1, 2, 3, 1), assemblyInfo.AssemblyVersion);
Assert.AreEqual(new Version(1, 2, 3, 2), assemblyInfo.AssemblyFileVersion);
Assert.AreEqual(new Version(1, 2, 3, 1).ToString(), assemblyInfo.AssemblyVersion);
Assert.AreEqual(new Version(1, 2, 3, 2).ToString(), assemblyInfo.AssemblyFileVersion);
Assert.AreEqual(new Version(1, 2, 3, 3).ToString(), assemblyInfo.InformationalVersion);
Assert.AreEqual(new Guid("0c8c889f-ced2-4167-b155-2d48a99d8c72"), assemblyInfo.Guid);
Assert.AreEqual("ru-RU", assemblyInfo.NeutralLanguage);
@ -398,8 +398,8 @@ using System.Reflection; @@ -398,8 +398,8 @@ using System.Reflection;
Copyright = "Copyright 2014",
Trademark = "Trademark",
DefaultAlias = "Alias",
AssemblyVersion = new Version(1, 2, 3, 4),
AssemblyFileVersion = new Version(1, 2, 3, 4),
AssemblyVersion = new Version(1, 2, 3, 4).ToString(),
AssemblyFileVersion = new Version(1, 2, 3, 4).ToString(),
InformationalVersion = new Version(1, 2, 3, 4).ToString(),
Guid = new Guid("0c8c889f-ced2-4167-b155-2d48a99d8c72"),
NeutralLanguage = "ru-RU",
@ -449,8 +449,8 @@ using System.Runtime.InteropServices; @@ -449,8 +449,8 @@ using System.Runtime.InteropServices;
Copyright = "Copyright 2014-changed",
Trademark = "Trademark-changed",
DefaultAlias = "Alias-changed",
AssemblyVersion = new Version(4, 3, 2, 1),
AssemblyFileVersion = new Version(4, 3, 2, 1),
AssemblyVersion = new Version(4, 3, 2, 1).ToString(),
AssemblyFileVersion = new Version(4, 3, 2, 1).ToString(),
InformationalVersion = new Version(4, 3, 2, 1).ToString(),
Guid = new Guid("dc8c889f-ced2-4167-b155-2d48a99d8c72"),
NeutralLanguage = "en-US",

Loading…
Cancel
Save