Browse Source

Use a copy of the text/color in the SearchResultPad instead of accessing the real document in the OnPaint method. This fixes some bugs when switching to the SearchResultPad after modifying the document.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@623 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
4a3b169576
  1. 41
      doc/ChangeLog.xml
  2. 1
      src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj
  3. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/TextWord.cs
  4. 2
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs
  5. 162
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/DrawableLine.cs
  6. 129
      src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Pad/Nodes/SearchResultNode.cs

41
doc/ChangeLog.xml

@ -1,4 +1,45 @@ @@ -1,4 +1,45 @@
<ChangeLog project="SharpDevelop">
<Change author="Daniel Grunwald" date="10/25/2005">Update default layouts.</Change>
<Change author="Daniel Grunwald" date="10/25/2005">Fixed SD2-465: Linked files are not imported</Change>
<Change author="Daniel Grunwald" date="10/25/2005">Fixed SD2-497: Allow adding existing files as links.
Boo.Microsoft.Build.Tasks now can embed .resource files.</Change>
<Change author="Daniel Grunwald" date="10/24/2005">Fixed SD2-503: WindowActive condition fails</Change>
<Change author="Daniel Grunwald" date="10/24/2005">Add InterpreterWrapper.boo.</Change>
<Change author="Daniel Grunwald" date="10/24/2005">Fixed BOO-542: CodeCompletion on interfaces doesn't list inherited Object members.
Fixed crash when cursor was at end of document and the DefinitionViewPad was opened.</Change>
<Change author="Daniel Grunwald" date="10/24/2005">Add Boo.InterpreterAddIn.</Change>
<Change author="Daniel Grunwald" date="10/24/2005">Fixed possible StackOverflowException in BooBinding. CodeGenerator can now created "Changed"-events and OnEvent-methods.</Change>
<Change author="Daniel Grunwald" date="10/23/2005">Allow generating interface implementations using the new CodeGenerator.</Change>
<Change author="Daniel Grunwald" date="10/23/2005">Fixed BOO-539: Forms designer does not hook up events to event handlers.
and BOO-538: Syntax colorization of doc-strings with slashes goes awry</Change>
<Change author="Daniel Grunwald" date="10/22/2005">Fixed possible endless loop in Boo ExpressionFinder.</Change>
<Change author="Daniel Grunwald" date="10/22/2005">Added FormattingStrategy for Boo and fixed BOO-535: Code completion for generator syntax.</Change>
<Change author="Daniel Grunwald" date="10/22/2005">Improved BooBinding:
Allow for code completion on ArrayReturnType and ConstructedReturnType even if they are encapsulated by an InferredReturnType.
Fixed code completion on arrays created through array literals or the "array" builtin.
Recognize variables created by "for" statements if their type is inferred from the element type of the enumerable object.</Change>
<Change author="Daniel Grunwald" date="10/22/2005">Fixed BOO-300: #region folding</Change>
<Change author="Daniel Grunwald" date="10/22/2005">Fixed BOO-516: Tooltips don't work in last line of the document</Change>
<Change author="Daniel Grunwald" date="10/22/2005">The commands "Create getter" and "Create property" now generate code using NRefactory. (part of SD2-436)</Change>
<Change author="Daniel Grunwald" date="10/21/2005">Fixed bugs in boo code completion.</Change>
<Change author="Daniel Grunwald" date="10/21/2005">Fixed problems with RegexpTk.</Change>
<Change author="Daniel Grunwald" date="10/21/2005">Fixed SD2-502: Find/Replace dialog toolbar doesn't respect visual style option</Change>
<Change author="Daniel Grunwald" date="10/21/2005">- allow code completion bindings to handle ReturnEditAction by handling '\n'.
- add dummy token "?" to VB lexer.
- use IntegerLiteralResolveResult that doesn't do code completion instead of returning no ResolveResult at all when resolving an integer literal.
- Implemented SD2-501: type inference when typing for both C# and VB.NET.
You can now type "? name = expr;" or "Dim name as ? = expr" and SharpDevelop will fill in the type for you.</Change>
<Change author="Daniel Grunwald" date="10/21/2005">Fixed SD2-496: TODO task entries removed after building solution.</Change>
<Change author="Daniel Grunwald" date="10/21/2005">Changes in the highlighting are shown when closing the options box, no need to restart SharpDevelop anymore.</Change>
<Change author="Daniel Grunwald" date="10/21/2005">Fixed BOO-524 (Autocompletion on import doesn't list only namespaces) in Boo and VB: now only classes that contain public static members are shown in the "import" completion.</Change>
<Change author="Daniel Grunwald" date="10/20/2005">Add quotation marks around the post-build event batch file to fix compiling in paths containing a space.</Change>
<Change author="Daniel Grunwald" date="10/19/2005">Update conditions in the AddIn schema.</Change>
<Change author="Daniel Grunwald" date="10/19/2005">Improved lazy-loading: fixed loading of BackendBindings when text editor was opened.</Change>
<Change author="Daniel Grunwald" date="10/19/2005">BuildAddinDocumentation now updates the AddIn schema.</Change>
<Change author="Matt Ward" date="10/18/2005">NAnt addin now included in main SharpDevelop solution.</Change>
<Change author="Matt Ward" date="10/18/2005">NAnt addin now using SolutionOpen condition.</Change>
<Change author="Matt Ward" date="10/17/2005">The Mono build task attempts to locate the Mono install path by reading the registry before falling back to its original method of assuming that the Mcs/Gmcs compilers have been added to the Path.</Change>
<Change author="Daniel Grunwald" date="10/17/2005">Fixed C# ExpressionFinder bug when typing "\." inside a string literal.</Change>
<Change author="Daniel Grunwald" date="10/17/2005">Add documentation for conditions, rename CombineOpen to SolutionOpen.</Change>
<Change author="Daniel Grunwald" date="10/17/2005">Add list with documentation about the doozers.</Change>
<Change author="Daniel Grunwald" date="10/17/2005">Fixed SD2-477: Solution import error.</Change>

1
src/Libraries/ICSharpCode.TextEditor/Project/ICSharpCode.TextEditor.csproj

@ -183,6 +183,7 @@ @@ -183,6 +183,7 @@
<Compile Include="Src\Document\TextBufferStrategy\PieceTableTextBufferStrategy.cs" />
<Compile Include="Src\Util\FileReader.cs" />
<EmbeddedResource Include="Resources\Boo.xshd" />
<Compile Include="Src\Gui\DrawableLine.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>

4
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/TextWord.cs

@ -30,7 +30,7 @@ namespace ICSharpCode.TextEditor.Document @@ -30,7 +30,7 @@ namespace ICSharpCode.TextEditor.Document
int offset;
int length;
public class SpaceTextWord : TextWord
public sealed class SpaceTextWord : TextWord
{
public SpaceTextWord()
{
@ -61,7 +61,7 @@ namespace ICSharpCode.TextEditor.Document @@ -61,7 +61,7 @@ namespace ICSharpCode.TextEditor.Document
}
}
public class TabTextWord : TextWord
public sealed class TabTextWord : TextWord
{
public TabTextWord()
{

2
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/LineManager/LineSegment.cs

@ -12,7 +12,7 @@ using System.Text; @@ -12,7 +12,7 @@ using System.Text;
namespace ICSharpCode.TextEditor.Document
{
public class LineSegment : AbstractSegment
public sealed class LineSegment : AbstractSegment
{
int delimiterLength;

162
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/DrawableLine.cs

@ -0,0 +1,162 @@ @@ -0,0 +1,162 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 25.10.2005
* Time: 16:55
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using ICSharpCode.TextEditor.Document;
namespace ICSharpCode.TextEditor
{
/// <summary>
/// A class that is able to draw a line on any control (outside the text editor)
/// </summary>
public class DrawableLine
{
static StringFormat sf = (StringFormat)System.Drawing.StringFormat.GenericTypographic.Clone();
List<SimpleTextWord> words = new List<SimpleTextWord>();
SizeF spaceSize;
Font monospacedFont;
Font boldMonospacedFont;
private class SimpleTextWord {
internal TextWordType Type;
internal string Word;
internal bool Bold;
internal Color Color;
public SimpleTextWord(TextWordType Type, string Word, bool Bold, Color Color)
{
this.Type = Type;
this.Word = Word;
this.Bold = Bold;
this.Color = Color;
}
internal readonly static SimpleTextWord Space = new SimpleTextWord(TextWordType.Space, " ", false, Color.Black);
internal readonly static SimpleTextWord Tab = new SimpleTextWord(TextWordType.Tab, "\t", false, Color.Black);
}
public DrawableLine(IDocument document, LineSegment line, Font monospacedFont, Font boldMonospacedFont)
{
this.monospacedFont = monospacedFont;
this.boldMonospacedFont = boldMonospacedFont;
if (line.Words != null) {
foreach (TextWord word in line.Words) {
if (word.Type == TextWordType.Space) {
words.Add(SimpleTextWord.Space);
} else if (word.Type == TextWordType.Tab) {
words.Add(SimpleTextWord.Tab);
} else {
words.Add(new SimpleTextWord(TextWordType.Word, word.Word, word.Font.Bold, word.Color));
}
}
} else {
words.Add(new SimpleTextWord(TextWordType.Word, document.GetText(line), false, Color.Black));
}
}
public int LineLength {
get {
int length = 0;
foreach (SimpleTextWord word in words) {
length += word.Word.Length;
}
return length;
}
}
public void SetBold(int startIndex, int endIndex, bool bold)
{
if (startIndex < 0)
throw new ArgumentException("startIndex must be >= 0");
if (startIndex > endIndex)
throw new ArgumentException("startIndex must be <= endIndex");
if (startIndex == endIndex) return;
int pos = 0;
for (int i = 0; i < words.Count; i++) {
SimpleTextWord word = words[i];
if (pos >= endIndex)
break;
int wordEnd = pos + word.Word.Length;
// 3 possibilities:
if (startIndex <= pos && endIndex >= wordEnd) {
// word is fully in region:
word.Bold = bold;
} else if (startIndex <= pos) {
// beginning of word is in region
int inRegionLength = endIndex - pos;
SimpleTextWord newWord = new SimpleTextWord(word.Type, word.Word.Substring(inRegionLength), word.Bold, word.Color);
words.Insert(i + 1, newWord);
word.Bold = bold;
word.Word = word.Word.Substring(0, inRegionLength);
} else if (startIndex < wordEnd) {
// end of word is in region (or middle of word is in region)
int notInRegionLength = startIndex - pos;
SimpleTextWord newWord = new SimpleTextWord(word.Type, word.Word.Substring(notInRegionLength), word.Bold, word.Color);
// newWord.Bold will be set in the next iteration
words.Insert(i + 1, newWord);
word.Word = word.Word.Substring(0, notInRegionLength);
}
pos = wordEnd;
}
}
public static float DrawDocumentWord(Graphics g, string word, PointF position, Font font, Color foreColor)
{
if (word == null || word.Length == 0) {
return 0f;
}
SizeF wordSize = g.MeasureString(word, font, 32768, sf);
g.DrawString(word,
font,
BrushRegistry.GetBrush(foreColor),
position,
sf);
return wordSize.Width;
}
public SizeF GetSpaceSize(Graphics g)
{
if (spaceSize.IsEmpty) {
spaceSize = g.MeasureString("-", boldMonospacedFont, new PointF(0, 0), sf);
}
return spaceSize;
}
public void DrawLine(Graphics g, ref float xPos, float yPos)
{
SizeF spaceSize = GetSpaceSize(g);
foreach (SimpleTextWord word in words) {
switch (word.Type) {
case TextWordType.Space:
xPos += spaceSize.Width;
break;
case TextWordType.Tab:
float tabWidth = spaceSize.Width * 4;
xPos += tabWidth;
xPos = (int)((xPos + 2) / tabWidth) * tabWidth;
break;
case TextWordType.Word:
xPos += DrawDocumentWord(g,
word.Word,
new PointF(xPos, yPos),
word.Bold ? boldMonospacedFont : monospacedFont,
word.Color
);
break;
}
}
}
}
}

129
src/Main/Base/Project/Src/TextEditor/SearchAndReplace/Pad/Nodes/SearchResultNode.cs

@ -22,16 +22,15 @@ namespace SearchAndReplace @@ -22,16 +22,15 @@ namespace SearchAndReplace
/// </summary>
public class SearchResultNode : ExtTreeNode
{
IDocument document;
SearchResult result;
SizeF spaceSize;
static StringFormat sf = (StringFormat)System.Drawing.StringFormat.GenericTypographic.Clone();
Point startPosition;
Point endPosition;
string positionText;
string displayText;
string specialText;
bool showFileName = false;
DrawableLine drawableLine;
public bool ShowFileName {
get {
return showFileName;
@ -39,72 +38,72 @@ namespace SearchAndReplace @@ -39,72 +38,72 @@ namespace SearchAndReplace
set {
showFileName = value;
if (showFileName) {
Text = DisplayText + FileNameText;
Text = displayText + FileNameText;
} else {
Text = DisplayText;
Text = displayText;
}
}
}
string DisplayText {
get {
if (specialText != null) {
return positionText + specialText;
} else if (document.TotalNumberOfLines > startPosition.Y) {
LineSegment line = document.GetLineSegment(startPosition.Y);
return positionText + document.GetText(line).Replace("\t", " ");
} else {
return positionText;
}
}
}
string FileNameText {
get {
return " in " + Path.GetFileName(result.FileName) + "(" + Path.GetDirectoryName(result.FileName) +")";
}
}
public SearchResultNode(IDocument document, SearchResult result)
{
drawDefault = false;
this.document = document;
this.result = result;
startPosition = result.GetStartPosition(document);
endPosition = result.GetEndPosition(document);
Point endPosition = result.GetEndPosition(document);
positionText = "(" + (startPosition.Y + 1) + ", " + (startPosition.X + 1) + ") ";
LineSegment line = document.GetLineSegment(startPosition.Y);
drawableLine = new DrawableLine(document, line, MonospacedFont, BoldMonospacedFont);
drawableLine.SetBold(0, drawableLine.LineLength, false);
drawableLine.SetBold(startPosition.X, endPosition.X, true);
specialText = result.DisplayText;
Text = DisplayText;
if (specialText != null) {
displayText = positionText + specialText;
} else {
displayText = positionText + document.GetText(line).Replace("\t", " ");
}
Text = displayText;
}
protected override int MeasureItemWidth(DrawTreeNodeEventArgs e)
{
Graphics g = e.Graphics;
int x = MeasureTextWidth(g, DisplayText, BoldMonospacedFont);
int x = MeasureTextWidth(g, displayText, BoldMonospacedFont);
if (ShowFileName) {
float tabWidth = drawableLine.GetSpaceSize(g).Width * 6;
x = (int)((int)((x + 2 + tabWidth) / tabWidth) * tabWidth);
x += MeasureTextWidth(g, FileNameText, ItalicFont);
}
return x;
}
protected override void DrawForeground(DrawTreeNodeEventArgs e)
{
Graphics g = e.Graphics;
float x = e.Bounds.X;
DrawText(g, positionText, Brushes.Black, Font, ref x, e.Bounds.Y);
spaceSize = g.MeasureString("-", Font, new PointF(0, 0), StringFormat.GenericTypographic);
if (specialText != null) {
DrawText(g, specialText, Brushes.Black, Font, ref x, e.Bounds.Y);
} else {
x += DrawLine(g, document.GetLineSegment(startPosition.Y), e.Bounds.Y, x);
drawableLine.DrawLine(g, ref x, e.Bounds.Y);
}
if (ShowFileName) {
x += DrawDocumentWord(g,
FileNameText,
new PointF(x, e.Bounds.Y),
ItalicMonospacedFont,
Color.Gray
);
float tabWidth = drawableLine.GetSpaceSize(g).Width * 6;
x = (int)((int)((x + 2 + tabWidth) / tabWidth) * tabWidth);
DrawText(g,
FileNameText,
Brushes.Gray,
ItalicFont,
ref x, e.Bounds.Y);
}
}
@ -112,73 +111,5 @@ namespace SearchAndReplace @@ -112,73 +111,5 @@ namespace SearchAndReplace
{
FileService.JumpToFilePosition(result.FileName, startPosition.Y, startPosition.X);
}
float DrawDocumentWord(Graphics g, string word, PointF position, Font font, Color foreColor)
{
if (word == null || word.Length == 0) {
return 0f;
}
SizeF wordSize = g.MeasureString(word, font, 32768, sf);
g.DrawString(word,
font,
BrushRegistry.GetBrush(foreColor),
position,
sf);
return wordSize.Width;
}
float DrawLine(Graphics g, LineSegment line, float yPos, float xPos)
{
int logicalX = 0;
if (line.Words != null) {
foreach (TextWord word in line.Words) {
switch (word.Type) {
case TextWordType.Space:
xPos += spaceSize.Width;
logicalX++;
break;
case TextWordType.Tab:
xPos += spaceSize.Width * 4;
logicalX++;
break;
case TextWordType.Word:
int offset1 = Math.Min(word.Length, Math.Max(0, startPosition.X - logicalX));
int offset2 = Math.Max(offset1, Math.Min(word.Length, endPosition.X - logicalX));
xPos += DrawDocumentWord(g,
word.Word.Substring(0, offset1),
new PointF(xPos, yPos),
MonospacedFont,
word.Color
);
xPos += DrawDocumentWord(g,
word.Word.Substring(offset1, offset2 - offset1),
new PointF(xPos, yPos),
BoldMonospacedFont,
word.Color
);
xPos += DrawDocumentWord(g,
word.Word.Substring(offset2),
new PointF(xPos, yPos),
MonospacedFont,
word.Color
);
logicalX += word.Word.Length;
break;
}
}
} else {
xPos += DrawDocumentWord(g,
document.GetText(line),
new PointF(xPos, yPos),
MonospacedFont,
Color.Black
);
}
return xPos;
}
}
}

Loading…
Cancel
Save