diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs index 7fd51036ee..1207c684ce 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions /// /// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock /// - //[ExtensionFor(typeof(FrameworkElement))] + [ExtensionFor(typeof(TextBlock))] public class InPlaceEditorExtension : PrimarySelectionAdornerProvider { AdornerPanel adornerPanel; 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 433d48f307..05e79f50ed 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs @@ -63,7 +63,9 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "") { textProperty.SetValue(item.ComponentType.Name); - } + item.Properties[FrameworkElement.WidthProperty].Reset(); + item.Properties[FrameworkElement.HeightProperty].Reset(); + } DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"]; if (verticalAlignmentProperty.ValueOnInstance == null) diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs index 5f24f5caff..eea059067d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs @@ -18,6 +18,7 @@ using System; using System.Windows; +using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; @@ -34,21 +35,23 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions [ExtensionFor(typeof(UIElement))] public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider { - DesignPanel panel; - - protected override void OnInitialized() + DesignPanel panel; + ContextMenu contextMenu; + + protected override void OnInitialized() { base.OnInitialized(); - - panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; - panel.ContextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem); - } + + contextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem); + panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; + panel.AddContextMenu(contextMenu); + } protected override void OnRemove() { - panel.ContextMenu = null; - - base.OnRemove(); + panel.RemoveContextMenu(contextMenu); + + base.OnRemove(); } } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs index e54c136d8b..0553b5aa2d 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs @@ -1,4 +1,22 @@ -using System; +// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +// to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs index f8c8d22406..8e690d1b24 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs @@ -122,27 +122,33 @@ namespace ICSharpCode.WpfDesign.Designer internal static void CreateVisualTree(this UIElement element) { try { - var fixedDoc = new FixedDocument(); - var pageContent = new PageContent(); - var fixedPage = new FixedPage(); - fixedPage.Children.Add(element); - (pageContent as IAddChild).AddChild(fixedPage); - fixedDoc.Pages.Add(pageContent); + element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); + element.Arrange(new Rect(element.DesiredSize)); - var f = new XpsSerializerFactory(); - var w = f.CreateSerializerWriter(new MemoryStream()); - w.Write(fixedDoc); + //var fixedDoc = new FixedDocument(); + //var pageContent = new PageContent(); + //var fixedPage = new FixedPage(); + //fixedPage.Children.Add(element); + //(pageContent as IAddChild).AddChild(fixedPage); + //fixedDoc.Pages.Add(pageContent); - fixedPage.Children.Remove(element); - } - catch (Exception) + //var f = new XpsSerializerFactory(); + //var w = f.CreateSerializerWriter(new MemoryStream()); + //w.Write(fixedDoc); + + //fixedPage.Children.Remove(element); + } + catch (Exception) { } } internal static Size GetDefaultSize(DesignItem createdItem) { CreateVisualTree(createdItem.View); - + + if (createdItem.View.GetType() == typeof (TextBlock)) + return new Size(double.NaN, double.NaN); + var s = Metadata.GetDefaultSize(createdItem.ComponentType, false); if (double.IsNaN(s.Width) && createdItem.View.DesiredSize.Width > 0) @@ -193,10 +199,16 @@ namespace ICSharpCode.WpfDesign.Designer public static void Resize(DesignItem item, double newWidth, double newHeight) { if (newWidth != GetWidth(item.View)) { - item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth); + if(double.IsNaN(newWidth)) + item.Properties.GetProperty(FrameworkElement.WidthProperty).Reset(); + else + item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth); } if (newHeight != GetHeight(item.View)) { - item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight); + if (double.IsNaN(newHeight)) + item.Properties.GetProperty(FrameworkElement.HeightProperty).Reset(); + else + item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight); } } diff --git a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs index 148997aa40..7c9926e1aa 100644 --- a/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs +++ b/src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs @@ -1,20 +1,28 @@ -using System; +// 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.Collections.Generic; -using System.ComponentModel; using System.Linq; -using System.Security; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; using System.Windows.Documents; -using System.Windows.Input; using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; -using System.Xml; +using ICSharpCode.WpfDesign.Designer.Xaml; namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor { @@ -29,7 +37,20 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor { InitializeComponent(); - this.designItem = designItem; + this.designItem = designItem; + + IEnumerable inlines = null; + var tb = ((TextBlock) designItem.Component); + + inlines = tb.Inlines.Select(x => CloneInline(x)).ToList(); + + var paragraph = richTextBox.Document.Blocks.First() as Paragraph; + paragraph.Inlines.AddRange(inlines); + + richTextBox.Document.Blocks.Add(paragraph); + + richTextBox.Foreground = tb.Foreground; + richTextBox.Background = tb.Background; } private void GetDesignItems(TextElementCollection blocks, List list) @@ -48,8 +69,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor foreach (var inline in ((Paragraph) block).Inlines) { - //yield return inline; - list.Add(CloneInline(inline)); + list.Add(InlineToDesignItem(inline)); } } else if (block is Section) @@ -61,9 +81,34 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor } } - private DesignItem CloneInline(Inline inline) + private Inline CloneInline(Inline inline) { - DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(inline); + Inline retVal = null; + if (inline is LineBreak) + retVal = new LineBreak(); + else if (inline is Span) + retVal = new Span(); + else if (inline is Run) + { + retVal = new Run(((Run) inline).Text); + } + + retVal.Background = inline.Background; + retVal.Foreground = inline.Foreground; + retVal.FontFamily = inline.FontFamily; + retVal.FontSize = inline.FontSize; + retVal.FontStretch = inline.FontStretch; + retVal.FontStyle = inline.FontStyle; + retVal.FontWeight = inline.FontWeight; + retVal.TextEffects = inline.TextEffects; + retVal.TextDecorations = inline.TextDecorations; + + return retVal; + } + + private DesignItem InlineToDesignItem(Inline inline) + { + DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(inline)); if (inline is Run) { var run = inline as Run; @@ -96,9 +141,23 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor d.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle); if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue) d.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight); - if (inline.ReadLocalValue(TextElement.TextEffectsProperty) != DependencyProperty.UnsetValue) - d.Properties.GetProperty(TextElement.TextEffectsProperty).SetValue(inline.TextEffects); + if (inline.TextDecorations.Count > 0) + { + d.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection()); + var tdColl = d.Properties.GetProperty("TextDecorations"); + foreach (var td in inline.TextDecorations) + { + var newTd = designItem.Services.Component.RegisterComponentForDesigner(new TextDecoration()); + if (inline.ReadLocalValue(TextDecoration.LocationProperty) != DependencyProperty.UnsetValue) + newTd.Properties.GetProperty(TextDecoration.LocationProperty).SetValue(td.Location); + if (inline.ReadLocalValue(TextDecoration.PenProperty) != DependencyProperty.UnsetValue) + newTd.Properties.GetProperty(TextDecoration.PenProperty).SetValue(td.Pen); + + tdColl.CollectionElements.Add(newTd); + } + } + return d; } @@ -119,7 +178,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor foreach (var inline in inlines) { - inlinesProperty.CollectionElements.Add(inline); }