Bufix Inline Text Editor should use TextBox Properties when no Inlines needed
This commit is contained in:
Родитель
672e73a54a
Коммит
36753f4cb0
|
@ -76,8 +76,8 @@ namespace ICSharpCode.WpfDesign.Designer.Controls
|
|||
};
|
||||
ToolTip = "Edit the Text. Press" + Environment.NewLine + "Enter to make changes." + Environment.NewLine + "Shift+Enter to insert a newline." + Environment.NewLine + "Esc to cancel editing.";
|
||||
|
||||
FormatedTextEditor.SetRichTextBoxTextFromTextBlock(editor, ((TextBlock)designItem.Component));
|
||||
editor.TextChanged += editor_TextChanged;
|
||||
FormatedTextEditor.SetRichTextBoxTextFromTextBlock(editor, ((TextBlock)designItem.Component));
|
||||
}
|
||||
|
||||
void editor_TextChanged(object sender, TextChangedEventArgs e)
|
||||
|
|
|
@ -16,12 +16,11 @@
|
|||
// 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Documents;
|
||||
using ICSharpCode.WpfDesign.UIExtensions;
|
||||
using ICSharpCode.WpfDesign.Designer.themes;
|
||||
|
@ -139,64 +138,76 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private static DesignItem InlineToDesignItem(DesignItem designItem, Inline inline)
|
||||
{
|
||||
DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(inline));
|
||||
if (inline is Run)
|
||||
{
|
||||
var run = inline as Run;
|
||||
|
||||
if (run.ReadLocalValue(Run.TextProperty) != DependencyProperty.UnsetValue)
|
||||
{
|
||||
d.Properties.GetProperty(Run.TextProperty).SetValue(run.Text);
|
||||
}
|
||||
}
|
||||
else if (inline is Span)
|
||||
{ }
|
||||
else if (inline is LineBreak)
|
||||
{ }
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (inline.ReadLocalValue(TextElement.BackgroundProperty) != DependencyProperty.UnsetValue)
|
||||
d.Properties.GetProperty(TextElement.BackgroundProperty).SetValue(inline.Background);
|
||||
if (inline.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue)
|
||||
d.Properties.GetProperty(TextElement.ForegroundProperty).SetValue(inline.Foreground);
|
||||
if (inline.ReadLocalValue(TextElement.FontFamilyProperty) != DependencyProperty.UnsetValue)
|
||||
d.Properties.GetProperty(TextElement.FontFamilyProperty).SetValue(inline.FontFamily);
|
||||
if (inline.ReadLocalValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue)
|
||||
d.Properties.GetProperty(TextElement.FontSizeProperty).SetValue(inline.FontSize);
|
||||
if (inline.ReadLocalValue(TextElement.FontStretchProperty) != DependencyProperty.UnsetValue)
|
||||
d.Properties.GetProperty(TextElement.FontStretchProperty).SetValue(inline.FontStretch);
|
||||
if (inline.ReadLocalValue(TextElement.FontStyleProperty) != DependencyProperty.UnsetValue)
|
||||
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.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);
|
||||
}
|
||||
private static DesignItem InlineToDesignItem(DesignItem designItem, Inline inline)
|
||||
{
|
||||
DesignItem d = d = designItem.Services.Component.RegisterComponentForDesigner(CloneInline(inline));
|
||||
if (inline is Run)
|
||||
{
|
||||
var run = inline as Run;
|
||||
|
||||
if (run.ReadLocalValue(Run.TextProperty) != DependencyProperty.UnsetValue)
|
||||
{
|
||||
d.Properties.GetProperty(Run.TextProperty).SetValue(run.Text);
|
||||
}
|
||||
}
|
||||
else if (inline is Span)
|
||||
{ }
|
||||
else if (inline is LineBreak)
|
||||
{ }
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
SetDesignItemTextpropertiesFromInline(d, inline);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
private static void SetDesignItemTextpropertiesFromInline(DesignItem targetDesignItem, Inline inline)
|
||||
{
|
||||
if (inline.ReadLocalValue(TextElement.BackgroundProperty) != DependencyProperty.UnsetValue)
|
||||
targetDesignItem.Properties.GetProperty(TextElement.BackgroundProperty).SetValue(inline.Background);
|
||||
if (inline.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue)
|
||||
targetDesignItem.Properties.GetProperty(TextElement.ForegroundProperty).SetValue(inline.Foreground);
|
||||
if (inline.ReadLocalValue(TextElement.FontFamilyProperty) != DependencyProperty.UnsetValue)
|
||||
targetDesignItem.Properties.GetProperty(TextElement.FontFamilyProperty).SetValue(inline.FontFamily);
|
||||
if (inline.ReadLocalValue(TextElement.FontSizeProperty) != DependencyProperty.UnsetValue)
|
||||
targetDesignItem.Properties.GetProperty(TextElement.FontSizeProperty).SetValue(inline.FontSize);
|
||||
if (inline.ReadLocalValue(TextElement.FontStretchProperty) != DependencyProperty.UnsetValue)
|
||||
targetDesignItem.Properties.GetProperty(TextElement.FontStretchProperty).SetValue(inline.FontStretch);
|
||||
if (inline.ReadLocalValue(TextElement.FontStyleProperty) != DependencyProperty.UnsetValue)
|
||||
targetDesignItem.Properties.GetProperty(TextElement.FontStyleProperty).SetValue(inline.FontStyle);
|
||||
if (inline.ReadLocalValue(TextElement.FontWeightProperty) != DependencyProperty.UnsetValue)
|
||||
targetDesignItem.Properties.GetProperty(TextElement.FontWeightProperty).SetValue(inline.FontWeight);
|
||||
if (inline.TextDecorations.Count > 0) {
|
||||
targetDesignItem.Properties.GetProperty("TextDecorations").SetValue(new TextDecorationCollection());
|
||||
var tdColl = targetDesignItem.Properties.GetProperty("TextDecorations");
|
||||
|
||||
foreach (var td in inline.TextDecorations) {
|
||||
var newTd = targetDesignItem.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetTextBlockTextFromRichTextBlox(DesignItem designItem, RichTextBox richTextBox)
|
||||
{
|
||||
designItem.Properties.GetProperty(TextBlock.TextProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.TextProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.FontSizeProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.FontFamilyProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.FontStretchProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.FontWeightProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.BackgroundProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.ForegroundProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.FontStyleProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.TextEffectsProperty).Reset();
|
||||
designItem.Properties.GetProperty(TextBlock.TextDecorationsProperty).Reset();
|
||||
|
||||
var inlinesProperty = designItem.Properties.GetProperty("Inlines");
|
||||
inlinesProperty.CollectionElements.Clear();
|
||||
|
@ -205,12 +216,18 @@ namespace ICSharpCode.WpfDesign.Designer.PropertyGrid.Editors.FormatedTextEditor
|
|||
//richTextBox.Document = new FlowDocument();
|
||||
|
||||
var inlines = new List<DesignItem>();
|
||||
GetDesignItems(designItem, doc.Blocks, inlines);
|
||||
|
||||
foreach (var inline in inlines)
|
||||
{
|
||||
inlinesProperty.CollectionElements.Add(inline);
|
||||
}
|
||||
GetDesignItems(designItem, doc.Blocks, inlines);
|
||||
|
||||
if (inlines.Count == 1 && inlines.First().Component is Run) {
|
||||
var run = inlines.First().Component as Run;
|
||||
SetDesignItemTextpropertiesFromInline(designItem, run);
|
||||
designItem.Properties.GetProperty(TextBlock.TextProperty).SetValue(run.Text);
|
||||
}
|
||||
else {
|
||||
foreach (var inline in inlines) {
|
||||
inlinesProperty.CollectionElements.Add(inline);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Ok_Click(object sender, RoutedEventArgs e)
|
||||
|
|
|
@ -21,6 +21,7 @@ using System.Linq;
|
|||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Markup;
|
||||
|
@ -304,6 +305,9 @@ namespace ICSharpCode.WpfDesign.PropertyGrid
|
|||
}
|
||||
} else {
|
||||
foreach (var p in Properties) {
|
||||
if (p.DesignItem.Component is TextBlock && p.DependencyProperty == TextBlock.TextProperty) {
|
||||
p.DesignItem.ContentProperty.CollectionElements.Clear();
|
||||
}
|
||||
p.SetValue(value);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче