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. 2
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/Initializers.cs
  3. 7
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/RightClickMultipleItemsContextMenuExtension.cs
  4. 20
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs
  5. 32
      src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/ModelTools.cs
  6. 94
      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 @@ -34,7 +34,7 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions
/// <summary>
/// Extends In-Place editor to edit any text in the designer which is wrapped in the Visual tree under TexBlock
/// </summary>
//[ExtensionFor(typeof(FrameworkElement))]
[ExtensionFor(typeof(TextBlock))]
public class InPlaceEditorExtension : PrimarySelectionAdornerProvider
{
AdornerPanel adornerPanel;

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

@ -63,6 +63,8 @@ namespace ICSharpCode.WpfDesign.Designer.Extensions.Initializers @@ -63,6 +63,8 @@ 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"];

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

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

20
src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Project/Extensions/TextBlockRightClickContextMenuExtension.cs

@ -1,4 +1,22 @@ @@ -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;

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

@ -122,18 +122,21 @@ namespace ICSharpCode.WpfDesign.Designer @@ -122,18 +122,21 @@ 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);
//var f = new XpsSerializerFactory();
//var w = f.CreateSerializerWriter(new MemoryStream());
//w.Write(fixedDoc);
//fixedPage.Children.Remove(element);
}
catch (Exception)
{ }
@ -143,6 +146,9 @@ namespace ICSharpCode.WpfDesign.Designer @@ -143,6 +146,9 @@ namespace ICSharpCode.WpfDesign.Designer
{
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,9 +199,15 @@ namespace ICSharpCode.WpfDesign.Designer @@ -193,9 +199,15 @@ namespace ICSharpCode.WpfDesign.Designer
public static void Resize(DesignItem item, double newWidth, double newHeight)
{
if (newWidth != GetWidth(item.View)) {
if(double.IsNaN(newWidth))
item.Properties.GetProperty(FrameworkElement.WidthProperty).Reset();
else
item.Properties.GetProperty(FrameworkElement.WidthProperty).SetValue(newWidth);
}
if (newHeight != GetHeight(item.View)) {
if (double.IsNaN(newHeight))
item.Properties.GetProperty(FrameworkElement.HeightProperty).Reset();
else
item.Properties.GetProperty(FrameworkElement.HeightProperty).SetValue(newHeight);
}
}

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

@ -1,20 +1,28 @@ @@ -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
{
@ -30,6 +38,19 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor @@ -30,6 +38,19 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
InitializeComponent();
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)
@ -48,8 +69,7 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor @@ -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 @@ -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,8 +141,22 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor @@ -96,8 +141,22 @@ 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 @@ -119,7 +178,6 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
foreach (var inline in inlines)
{
inlinesProperty.CollectionElements.Add(inline);
}

Loading…
Cancel
Save