Browse Source

Don't reuse the TextView's text formatter - this causes crashes on some machines (e.g. Tomáš)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6202 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 16 years ago
parent
commit
e0ea8ea238
  1. 3
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs
  2. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/FormattedTextElement.cs
  3. 3
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/SingleCharacterElementGenerator.cs
  4. 8
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs
  5. 8
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextViewCachedElements.cs

3
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Folding/FoldingElementGenerator.cs

@ -66,7 +66,8 @@ namespace ICSharpCode.AvalonEdit.Folding @@ -66,7 +66,8 @@ namespace ICSharpCode.AvalonEdit.Folding
title = "...";
var p = new VisualLineElementTextRunProperties(CurrentContext.GlobalTextRunProperties);
p.SetForegroundBrush(Brushes.Gray);
var text = FormattedTextElement.PrepareText(CurrentContext.TextView.TextFormatter, title, p);
var textFormatter = TextFormatterFactory.Create(CurrentContext.TextView);
var text = FormattedTextElement.PrepareText(textFormatter, title, p);
return new FoldingLineElement(text, foldedUntil - offset);
} else {
return null;

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/FormattedTextElement.cs

@ -9,6 +9,7 @@ using System; @@ -9,6 +9,7 @@ using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Rendering
{
@ -78,7 +79,8 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -78,7 +79,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
public override TextRun CreateTextRun(int startVisualColumn, ITextRunConstructionContext context)
{
if (textLine == null) {
textLine = PrepareText(context.TextView.TextFormatter, this.text, this.TextRunProperties);
var formatter = TextFormatterFactory.Create(context.TextView);
textLine = PrepareText(formatter, this.text, this.TextRunProperties);
this.text = null;
}
return new FormattedTextRun(this, this.TextRunProperties);

3
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/SingleCharacterElementGenerator.cs

@ -98,7 +98,8 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -98,7 +98,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
} else if (ShowBoxForControlCharacters && char.IsControl(c)) {
var p = new VisualLineElementTextRunProperties(CurrentContext.GlobalTextRunProperties);
p.SetForegroundBrush(Brushes.White);
var text = FormattedTextElement.PrepareText(CurrentContext.TextView.TextFormatter,
var textFormatter = TextFormatterFactory.Create(CurrentContext.TextView);
var text = FormattedTextElement.PrepareText(textFormatter,
TextUtilities.GetControlCharacterName(c), p);
return new SpecialCharacterBoxElement(text);
} else {

8
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextView.cs

@ -777,14 +777,6 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -777,14 +777,6 @@ namespace ICSharpCode.AvalonEdit.Rendering
TextFormatter formatter;
internal TextViewCachedElements cachedElements;
/// <summary>
/// Gets the TextFormatter used by the text view.
/// Returns null if no document is assigned to the text view.
/// </summary>
public TextFormatter TextFormatter {
get { return formatter; }
}
TextRunProperties CreateGlobalTextRunProperties()
{
return new GlobalTextRunProperties {

8
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/TextViewCachedElements.cs

@ -9,11 +9,13 @@ using System; @@ -9,11 +9,13 @@ using System;
using System.Collections.Generic;
using System.Windows.Media;
using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.AvalonEdit.Rendering
{
sealed class TextViewCachedElements : IDisposable
{
TextFormatter formatter;
Dictionary<string, TextLine> simpleLightGrayTexts;
public TextLine GetSimpleLightGrayText(string text, ITextRunConstructionContext context)
@ -24,7 +26,9 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -24,7 +26,9 @@ namespace ICSharpCode.AvalonEdit.Rendering
if (!simpleLightGrayTexts.TryGetValue(text, out textLine)) {
var p = new VisualLineElementTextRunProperties(context.GlobalTextRunProperties);
p.SetForegroundBrush(Brushes.LightGray);
textLine = FormattedTextElement.PrepareText(context.TextView.TextFormatter, text, p);
if (formatter == null)
formatter = TextFormatterFactory.Create(context.TextView);
textLine = FormattedTextElement.PrepareText(formatter, text, p);
simpleLightGrayTexts[text] = textLine;
}
return textLine;
@ -36,6 +40,8 @@ namespace ICSharpCode.AvalonEdit.Rendering @@ -36,6 +40,8 @@ namespace ICSharpCode.AvalonEdit.Rendering
foreach (TextLine line in simpleLightGrayTexts.Values)
line.Dispose();
}
if (formatter != null)
formatter.Dispose();
}
}
}

Loading…
Cancel
Save