From 19406653eab146c301c2b8e81bd7314ba0c90af5 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sun, 30 Aug 2009 07:38:54 +0000 Subject: [PATCH] - improved WPF designer in some areas - added missing implementations of methods in VBNetFormattingStrategy git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4823 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- samples/XamlDesigner/Document.cs | 22 +++++++-------- samples/XamlDesigner/DocumentView.xaml.cs | 1 + samples/XamlDesigner/MainWindow.xaml.cs | 2 ++ samples/XamlDesigner/NewFileTemplate.xaml | 2 +- samples/XamlDesigner/XamlDesigner.csproj | 14 +++++++++- .../VBNetFormattingStrategy.cs | 7 ++++- .../WpfDesign.Designer/Project/DesignPanel.cs | 3 +-- .../Extensions/DefaultPlacementBehavior.cs | 21 +++++++++------ .../Project/Extensions/Initializers.cs | 7 ++++- .../Extensions/PanelInstanceFactory.cs | 24 +++++++++++++++++ .../Extensions/ResizeThumbExtension.cs | 2 +- .../Project/Services/CreateComponentTool.cs | 6 ++--- .../Project/Services/MoveLogic.cs | 4 +-- .../Project/XamlConstants.cs | 4 +-- .../WpfDesign.XamlDom/Project/XamlObject.cs | 3 +++ .../WpfDesign.XamlDom/Project/XamlProperty.cs | 6 ++++- .../WpfDesign/Project/ExtensionMethods.cs | 27 +++++++++++++++++++ .../WpfDesign/Project/PlacementInformation.cs | 2 ++ .../WpfDesign/Project/PlacementOperation.cs | 2 +- .../WpfDesign/Project/WpfDesign.csproj | 1 + 20 files changed, 124 insertions(+), 36 deletions(-) create mode 100644 src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ExtensionMethods.cs diff --git a/samples/XamlDesigner/Document.cs b/samples/XamlDesigner/Document.cs index 4998e87618..95d1580700 100644 --- a/samples/XamlDesigner/Document.cs +++ b/samples/XamlDesigner/Document.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.XamlDesigner this.filePath = filePath; ReloadFile(); } - + string tempName; DesignSurface designSurface = new DesignSurface(); @@ -145,11 +145,11 @@ namespace ICSharpCode.XamlDesigner } public XamlErrorService XamlErrorService { - get { - if (DesignContext != null) { - return DesignContext.Services.GetService(); - } - return null; + get { + if (DesignContext != null) { + return DesignContext.Services.GetService(); + } + return null; } } @@ -195,12 +195,10 @@ namespace ICSharpCode.XamlDesigner void UpdateXaml() { - if (DesignContext.CanSave && UndoService.CanUndo) { - var sb = new StringBuilder(); - using (var xmlWriter = XmlWriter.Create(sb)) { - DesignSurface.SaveDesigner(xmlWriter); - Text = XamlFormatter.Format(sb.ToString()); - } + var sb = new StringBuilder(); + using (var xmlWriter = XmlWriter.Create(sb)) { + DesignSurface.SaveDesigner(xmlWriter); + Text = XamlFormatter.Format(sb.ToString()); } } diff --git a/samples/XamlDesigner/DocumentView.xaml.cs b/samples/XamlDesigner/DocumentView.xaml.cs index b9bbcb53f4..fa1e25d878 100644 --- a/samples/XamlDesigner/DocumentView.xaml.cs +++ b/samples/XamlDesigner/DocumentView.xaml.cs @@ -27,6 +27,7 @@ namespace ICSharpCode.XamlDesigner uxTextEditor.SetHighlighting("XML"); uxTextEditor.DataBindings.Add("Text", doc, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged); + Document.Mode = DocumentMode.Design; } public Document Document { get; private set; } diff --git a/samples/XamlDesigner/MainWindow.xaml.cs b/samples/XamlDesigner/MainWindow.xaml.cs index 3874cc1a47..117441dca6 100644 --- a/samples/XamlDesigner/MainWindow.xaml.cs +++ b/samples/XamlDesigner/MainWindow.xaml.cs @@ -39,6 +39,8 @@ namespace ICSharpCode.XamlDesigner LoadSettings(); ProcessPaths(App.Args); + + ApplicationCommands.New.Execute(null, this); } public static MainWindow Instance; diff --git a/samples/XamlDesigner/NewFileTemplate.xaml b/samples/XamlDesigner/NewFileTemplate.xaml index a2b830f012..5241a58a98 100644 --- a/samples/XamlDesigner/NewFileTemplate.xaml +++ b/samples/XamlDesigner/NewFileTemplate.xaml @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/samples/XamlDesigner/XamlDesigner.csproj b/samples/XamlDesigner/XamlDesigner.csproj index 832461c724..aaec0d7d01 100644 --- a/samples/XamlDesigner/XamlDesigner.csproj +++ b/samples/XamlDesigner/XamlDesigner.csproj @@ -14,10 +14,13 @@ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 Configuration\app.manifest + False + False + false true - full + Full false bin\Debug\ DEBUG;TRACE @@ -32,6 +35,15 @@ prompt 4 + + False + + + False + Auto + 4194304 + x86 + False diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs index bcc6d76a31..16cc02f79d 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/FormattingStrategy/VBNetFormattingStrategy.cs @@ -851,7 +851,12 @@ namespace VBNetBinding public override void IndentLine(ITextEditor editor, IDocumentLine line) { - base.IndentLine(editor, line); + IndentLines(editor, line.LineNumber, line.LineNumber); + } + + public override void SurroundSelectionWithComment(ITextEditor editor) + { + SurroundSelectionWithSingleLineComment(editor, "'"); } #region SearchBracket diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs index 4f4ac2d93b..d885ee664c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/DesignPanel.cs @@ -141,8 +141,7 @@ namespace ICSharpCode.WpfDesign.Designer public DesignPanel() { this.Focusable = true; - this.AllowDrop = false; - this.ClipToBounds = true; + this.Margin = new Thickness(16); DesignerProperties.SetIsInDesignMode(this, true); _eatAllHitTestRequests = new EatAllHitTestRequests(); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs index 5898c7aeca..e5bba7db24 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/DefaultPlacementBehavior.cs @@ -12,14 +12,15 @@ using System.Windows.Media; namespace ICSharpCode.WpfDesign.Designer.Extensions { - [ExtensionFor(typeof(UIElement))] + [ExtensionFor(typeof(Panel))] + [ExtensionFor(typeof(ContentControl))] public class DefaultPlacementBehavior : BehaviorExtension, IPlacementBehavior { protected override void OnInitialized() { base.OnInitialized(); if (ExtendedItem.ContentProperty == null || - Metadata.IsPlacementDisabled(ExtendedItem.ComponentType)) + Metadata.IsPlacementDisabled(ExtendedItem.ComponentType)) return; ExtendedItem.AddBehavior(typeof(IPlacementBehavior), this); } @@ -45,7 +46,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions return new Rect(p, item.View.RenderSize); } - public virtual void BeforeSetPosition(PlacementOperation operation) + public virtual void BeforeSetPosition(PlacementOperation operation) { } @@ -67,16 +68,20 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } } else { ExtendedItem.ContentProperty.Reset(); - } + } } public virtual bool CanEnterContainer(PlacementOperation operation) { - if (ExtendedItem.ContentProperty.IsCollection && - CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType, - operation.PlacedItems.Select(p => p.Item.Component))) + if (ExtendedItem.ContentProperty.IsCollection) + return CollectionSupport.CanCollectionAdd(ExtendedItem.ContentProperty.ReturnType, + operation.PlacedItems.Select(p => p.Item.Component)); + if (!ExtendedItem.ContentProperty.IsSet) return true; - return !ExtendedItem.ContentProperty.IsSet; + + object value = ExtendedItem.ContentProperty.ValueOnInstance; + // don't overwrite non-primitive values like bindings + return ExtendedItem.ContentProperty.Value == null && (value is string && string.IsNullOrEmpty(value as string)); } public virtual void EnterContainer(PlacementOperation operation) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs index 4df3dd8482..756be86e1f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers } } - [ExtensionFor(typeof(HeaderedContentControl))] + [ExtensionFor(typeof(HeaderedContentControl), OverrideExtension = typeof(ContentControlInitializer))] public class HeaderedContentControlInitializer : DefaultInitializer { public override void InitializeDefaults(DesignItem item) @@ -35,6 +35,11 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers if (headerProperty.ValueOnInstance == null) { headerProperty.SetValue(item.ComponentType.Name); } + + DesignItemProperty contentProperty = item.Properties["Content"]; + if (contentProperty.ValueOnInstance == null) { + contentProperty.SetValue(new PanelInstanceFactory().CreateInstance(typeof(Canvas))); + } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelInstanceFactory.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelInstanceFactory.cs index 7ab77750f3..9707891ee6 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelInstanceFactory.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/PanelInstanceFactory.cs @@ -44,6 +44,30 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions } } + [ExtensionFor(typeof(HeaderedContentControl))] + public sealed class HeaderedContentControlInstanceFactory : CustomInstanceFactory + { + Brush _transparentBrush = new SolidColorBrush(Colors.Transparent); + + /// + /// Creates an instance of the specified type, passing the specified arguments to its constructor. + /// + public override object CreateInstance(Type type, params object[] arguments) + { + object instance = base.CreateInstance(type, arguments); + Control control = instance as Control; + if (control != null) { + if (control.Background == null) { + control.Background = _transparentBrush; + } + TypeDescriptionProvider provider = new DummyValueInsteadOfNullTypeDescriptionProvider( + TypeDescriptor.GetProvider(control), "Background", _transparentBrush); + TypeDescriptor.AddProvider(provider, control); + } + return instance; + } + } + sealed class DummyValueInsteadOfNullTypeDescriptionProvider : TypeDescriptionProvider { // By using a TypeDescriptionProvider, we can intercept all access to the property that is diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs index c8208f2051..656d576075 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/ResizeThumbExtension.cs @@ -104,7 +104,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions result.Width = newWidth; result.Height = newHeight; - info.Bounds = result; + info.Bounds = result.Round(); info.ResizeThumbAlignment = alignment; operation.CurrentContainerBehavior.BeforeSetPosition(operation); operation.CurrentContainerBehavior.SetPosition(info); diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs index 7d8695dbf0..953115ed02 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/CreateComponentTool.cs @@ -150,7 +150,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents( container, new DesignItem[] { createdItem }, - new Rect[] { new Rect(position, size) }, + new Rect[] { new Rect(position, size).Round() }, PlacementType.AddItem ); if (operation != null) { @@ -212,7 +212,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services { operation = PlacementOperation.TryStartInsertNewComponents(container, new DesignItem[] { createdItem }, - new Rect[] { GetStartToEndRect(e) }, + new Rect[] { GetStartToEndRect(e).Round() }, PlacementType.Resize); if (operation != null) { services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); @@ -224,7 +224,7 @@ namespace ICSharpCode.WpfDesign.Designer.Services base.OnMouseMove(sender, e); if (operation != null) { foreach (PlacementInformation info in operation.PlacedItems) { - info.Bounds = GetStartToEndRect(e); + info.Bounds = GetStartToEndRect(e).Round(); operation.CurrentContainerBehavior.SetPosition(info); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs index 6a2a5a935e..d28354e2b1 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Services/MoveLogic.cs @@ -65,8 +65,8 @@ namespace ICSharpCode.WpfDesign.Designer.Services } foreach (PlacementInformation info in operation.PlacedItems) { - info.Bounds = new Rect(info.OriginalBounds.Left + v.X, - info.OriginalBounds.Top + v.Y, + info.Bounds = new Rect(info.OriginalBounds.Left + Math.Round(v.X, PlacementInformation.BoundsPrecision), + info.OriginalBounds.Top + Math.Round(v.Y, PlacementInformation.BoundsPrecision), info.OriginalBounds.Width, info.OriginalBounds.Height); } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlConstants.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlConstants.cs index af639b33ae..cc64d34a2f 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlConstants.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlConstants.cs @@ -28,8 +28,8 @@ namespace ICSharpCode.WpfDesign.XamlDom /// /// The namespace used for the WPF schema. - /// Value: "http://schemas.microsoft.com/netfx/2007/xaml/presentation" + /// Value: "http://schemas.microsoft.com/winfx/2006/xaml/presentation" /// - public const string PresentationNamespace = "http://schemas.microsoft.com/netfx/2007/xaml/presentation"; + public const string PresentationNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"; } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs index 32aa56c0d0..3421fbf18c 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlObject.cs @@ -261,6 +261,9 @@ namespace ICSharpCode.WpfDesign.XamlDom if (propertyName == null) throw new ArgumentNullException("propertyName"); +// if (propertyName == ContentPropertyName) +// return + foreach (XamlProperty p in properties) { if (!p.IsAttached && p.PropertyName == propertyName) return p; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs index 4f8fb853a2..90d215b971 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/XamlProperty.cs @@ -267,6 +267,10 @@ namespace ICSharpCode.WpfDesign.XamlDom return; } if (_propertyElement == null) { + if (PropertyName == parentObject.ContentPropertyName) { + parentObject.XmlElement.InsertBefore(newChildNode, parentObject.XmlElement.FirstChild); + return; + } _propertyElement = parentObject.OwnerDocument.XmlDocument.CreateElement( this.PropertyTargetType.Name + "." + this.PropertyName, parentObject.OwnerDocument.GetNamespaceFor(this.PropertyTargetType) @@ -281,7 +285,7 @@ namespace ICSharpCode.WpfDesign.XamlDom Debug.Assert(index >= 0 && index <= collectionElements.Count); XmlElement collection = _propertyElement; if (collection == null) { - if (collectionElements.Count == 0) { + if (collectionElements.Count == 0 && this.PropertyName != this.ParentObject.ContentPropertyName) { // we have to create the collection element _propertyElement = parentObject.OwnerDocument.XmlDocument.CreateElement( this.PropertyTargetType.Name + "." + this.PropertyName, diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ExtensionMethods.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ExtensionMethods.cs new file mode 100644 index 0000000000..69d3d59837 --- /dev/null +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/ExtensionMethods.cs @@ -0,0 +1,27 @@ +// +// +// +// +// $Revision$ +// +using System; +using System.Windows; + +namespace ICSharpCode.WpfDesign +{ + /// + /// Description of ExtensionMethods. + /// + public static class ExtensionMethods + { + public static Rect Round(this Rect rect) + { + return new Rect( + Math.Round(rect.X, PlacementInformation.BoundsPrecision), + Math.Round(rect.Y, PlacementInformation.BoundsPrecision), + Math.Round(rect.Width, PlacementInformation.BoundsPrecision), + Math.Round(rect.Height, PlacementInformation.BoundsPrecision) + ); + } + } +} diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs index 512858f991..5399ac23af 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementInformation.cs @@ -15,6 +15,8 @@ namespace ICSharpCode.WpfDesign /// public sealed class PlacementInformation { + public const int BoundsPrecision = 8; + Rect originalBounds, bounds; readonly DesignItem item; readonly PlacementOperation operation; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs index b3f4b2cd84..57870f6273 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/PlacementOperation.cs @@ -99,7 +99,7 @@ namespace ICSharpCode.WpfDesign foreach (PlacementInformation info in placedItems) { info.OriginalBounds = TransformRectByMiddlePoint(transform, info.OriginalBounds); - info.Bounds = TransformRectByMiddlePoint(transform, info.Bounds); + info.Bounds = TransformRectByMiddlePoint(transform, info.Bounds).Round(); } currentContainer = newContainer; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj index aba21e4cdd..db9297e95d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign/Project/WpfDesign.csproj @@ -68,6 +68,7 @@ +