Browse Source

Fixes for Formated Text Editor

pull/584/head
jogibear9988 11 years ago
parent
commit
a269a4aa48
  1. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/InPlaceEditorExtension.cs
  2. 4
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs
  3. 23
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs
  4. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs
  5. 42
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  6. 96
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/PropertyGrid/Editors/FormatedTextEditor/FormatedTextEditor.xaml.cs

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

@ -34,7 +34,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <summary> /// <summary>
/// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock /// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock
/// </summary> /// </summary>
//[ExtensionFor(typeof(FrameworkElement))] [ExtensionFor(typeof(TextBlock))]
public class InPlaceEditorExtension : PrimarySelectionAdornerProvider public class InPlaceEditorExtension : PrimarySelectionAdornerProvider
{ {
AdornerPanel adornerPanel; AdornerPanel adornerPanel;

4
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() == "") if (textProperty.ValueOnInstance == null || textProperty.ValueOnInstance.ToString() == "")
{ {
textProperty.SetValue(item.ComponentType.Name); textProperty.SetValue(item.ComponentType.Name);
} item.Properties[FrameworkElement.WidthProperty].Reset();
item.Properties[FrameworkElement.HeightProperty].Reset();
}
DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"]; DesignItemProperty verticalAlignmentProperty = item.Properties["VerticalAlignment"];
if (verticalAlignmentProperty.ValueOnInstance == null) if (verticalAlignmentProperty.ValueOnInstance == null)

23
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs

@ -18,6 +18,7 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using System.Windows.Shapes;
@ -34,21 +35,23 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
[ExtensionFor(typeof(UIElement))] [ExtensionFor(typeof(UIElement))]
public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider public class RightClickMultipleItemsContextMenuExtension : SelectionAdornerProvider
{ {
DesignPanel panel; DesignPanel panel;
ContextMenu contextMenu;
protected override void OnInitialized()
protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel; contextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem);
panel.ContextMenu = new RightClickMultipleItemsContextMenu(ExtendedItem); panel = ExtendedItem.Context.Services.DesignPanel as DesignPanel;
} panel.AddContextMenu(contextMenu);
}
protected override void OnRemove() protected override void OnRemove()
{ {
panel.ContextMenu = null; panel.RemoveContextMenu(contextMenu);
base.OnRemove(); base.OnRemove();
} }
} }
} }

20
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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

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

@ -122,27 +122,33 @@ namespace ICSharpCode.WpfDesign.Designer
internal static void CreateVisualTree(this UIElement element) internal static void CreateVisualTree(this UIElement element)
{ {
try { try {
var fixedDoc = new FixedDocument(); element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
var pageContent = new PageContent(); element.Arrange(new Rect(element.DesiredSize));
var fixedPage = new FixedPage();
fixedPage.Children.Add(element);
(pageContent as IAddChild).AddChild(fixedPage);
fixedDoc.Pages.Add(pageContent);
var f = new XpsSerializerFactory(); //var fixedDoc = new FixedDocument();
var w = f.CreateSerializerWriter(new MemoryStream()); //var pageContent = new PageContent();
w.Write(fixedDoc); //var fixedPage = new FixedPage();
//fixedPage.Children.Add(element);
//(pageContent as IAddChild).AddChild(fixedPage);
//fixedDoc.Pages.Add(pageContent);
fixedPage.Children.Remove(element); //var f = new XpsSerializerFactory();
} //var w = f.CreateSerializerWriter(new MemoryStream());
catch (Exception) //w.Write(fixedDoc);
//fixedPage.Children.Remove(element);
}
catch (Exception)
{ } { }
} }
internal static Size GetDefaultSize(DesignItem createdItem) internal static Size GetDefaultSize(DesignItem createdItem)
{ {
CreateVisualTree(createdItem.View); CreateVisualTree(createdItem.View);
if (createdItem.View.GetType() == typeof (TextBlock))
return new Size(double.NaN, double.NaN);
var s = Metadata.GetDefaultSize(createdItem.ComponentType, false); var s = Metadata.GetDefaultSize(createdItem.ComponentType, false);
if (double.IsNaN(s.Width) && createdItem.View.DesiredSize.Width > 0) 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) public static void Resize(DesignItem item, double newWidth, double newHeight)
{ {
if (newWidth != GetWidth(item.View)) { 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)) { 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);
} }
} }

96
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.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using ICSharpCode.WpfDesign.Designer.Xaml;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
{ {
@ -29,7 +37,20 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
{ {
InitializeComponent(); InitializeComponent();
this.designItem = designItem; this.designItem = designItem;
IEnumerable<Inline> 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<Block> blocks, List<DesignItem> list) private void GetDesignItems(TextElementCollection<Block> blocks, List<DesignItem> list)
@ -48,8 +69,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
foreach (var inline in ((Paragraph) block).Inlines) foreach (var inline in ((Paragraph) block).Inlines)
{ {
//yield return inline; list.Add(InlineToDesignItem(inline));
list.Add(CloneInline(inline));
} }
} }
else if (block is Section) 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) if (inline is Run)
{ {
var run = inline as 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); d.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle);
if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue) if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue)
d.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight); d.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight);
if (inline.ReadLocalValue(TextElement.TextEffectsProperty) != DependencyProperty.UnsetValue) if (inline.TextDecorations.Count > 0)
d.Properties.GetProperty(TextElement.TextEffectsProperty).SetValue(inline.TextEffects); {
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; return d;
} }
@ -119,7 +178,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
foreach (var inline in inlines) foreach (var inline in inlines)
{ {
inlinesProperty.CollectionElements.Add(inline); inlinesProperty.CollectionElements.Add(inline);
} }

Loading…
Cancel
Save