Browse Source

AvalonEdit: code cleanup

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4686 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
d17ab897c4
  1. 38
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CaretPositioningMode.cs
  2. 27
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextUtilities.cs
  3. 62
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/FoldingMargin.cs
  4. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Selection.cs
  5. 3
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionMouseHandler.cs
  6. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj
  7. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineElement.cs
  8. 12
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs
  9. 1
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlAttribute.cs

38
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/CaretPositioningMode.cs

@ -1,38 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
namespace ICSharpCode.AvalonEdit
{
/// <summary>
/// Specifies the mode for getting the next caret position.
/// </summary>
public enum CaretPositioningMode
{
/// <summary>
/// Normal positioning (stop at every caret position)
/// </summary>
Normal,
/// <summary>
/// Stop only on word borders.
/// </summary>
WordBorder,
/// <summary>
/// Stop only at the beginning of words. This is used for Ctrl+Left/Ctrl+Right.
/// </summary>
WordStart,
/// <summary>
/// Stop only at the beginning of words, and anywhere in the middle of symbols.
/// </summary>
WordStartOrSymbol,
/// <summary>
/// Stop only on word borders, and anywhere in the middle of symbols.
/// </summary>
WordBorderOrSymbol
}
}

27
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextUtilities.cs

@ -11,6 +11,33 @@ using System.Windows.Documents;
namespace ICSharpCode.AvalonEdit.Document namespace ICSharpCode.AvalonEdit.Document
{ {
/// <summary>
/// Specifies the mode for getting the next caret position.
/// </summary>
public enum CaretPositioningMode
{
/// <summary>
/// Normal positioning (stop at every caret position)
/// </summary>
Normal,
/// <summary>
/// Stop only on word borders.
/// </summary>
WordBorder,
/// <summary>
/// Stop only at the beginning of words. This is used for Ctrl+Left/Ctrl+Right.
/// </summary>
WordStart,
/// <summary>
/// Stop only at the beginning of words, and anywhere in the middle of symbols.
/// </summary>
WordStartOrSymbol,
/// <summary>
/// Stop only on word borders, and anywhere in the middle of symbols.
/// </summary>
WordBorderOrSymbol
}
/// <summary> /// <summary>
/// Static helper methods for working with text. /// Static helper methods for working with text.
/// </summary> /// </summary>

62
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/FoldingMargin.cs

@ -111,6 +111,16 @@ namespace ICSharpCode.AvalonEdit.Editing
return markers[index]; return markers[index];
} }
static readonly Pen grayPen = MakeFrozenPen(Brushes.Gray);
static readonly Pen blackPen = MakeFrozenPen(Brushes.Black);
static Pen MakeFrozenPen(Brush brush)
{
Pen pen = new Pen(brush, 1);
pen.Freeze();
return pen;
}
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnRender(DrawingContext drawingContext) protected override void OnRender(DrawingContext drawingContext)
{ {
@ -119,18 +129,25 @@ namespace ICSharpCode.AvalonEdit.Editing
if (TextView.VisualLines.Count == 0 || FoldingManager == null) if (TextView.VisualLines.Count == 0 || FoldingManager == null)
return; return;
Pen grayPen = new Pen(Brushes.Gray, 1);
grayPen.Freeze();
Pen blackPen = new Pen(Brushes.Black, 1);
blackPen.Freeze();
var allTextLines = TextView.VisualLines.SelectMany(vl => vl.TextLines).ToList(); var allTextLines = TextView.VisualLines.SelectMany(vl => vl.TextLines).ToList();
Pen[] colors = new Pen[allTextLines.Count + 1]; Pen[] colors = new Pen[allTextLines.Count + 1];
Pen[] endMarker = new Pen[allTextLines.Count]; Pen[] endMarker = new Pen[allTextLines.Count];
CalculateFoldLinesForFoldingsActiveAtStart(allTextLines, colors, endMarker);
CalculateFoldLinesForMarkers(allTextLines, colors, endMarker);
DrawFoldLines(drawingContext, colors, endMarker);
base.OnRender(drawingContext);
}
/// <summary>
/// Calculates fold lines for all folding sections that start in front of the current view
/// and run into the current view.
/// </summary>
void CalculateFoldLinesForFoldingsActiveAtStart(List<TextLine> allTextLines, Pen[] colors, Pen[] endMarker)
{
int viewStartOffset = TextView.VisualLines[0].FirstDocumentLine.Offset; int viewStartOffset = TextView.VisualLines[0].FirstDocumentLine.Offset;
DocumentLine lastVisibleLine = TextView.VisualLines.Last().LastDocumentLine; int viewEndOffset = TextView.VisualLines.Last().LastDocumentLine.EndOffset;
int viewEndOffset = lastVisibleLine.Offset + lastVisibleLine.Length;
var foldings = FoldingManager.GetFoldingsContaining(viewStartOffset); var foldings = FoldingManager.GetFoldingsContaining(viewStartOffset);
int maxEndOffset = 0; int maxEndOffset = 0;
foreach (FoldingSection fs in foldings) { foreach (FoldingSection fs in foldings) {
@ -157,7 +174,13 @@ namespace ICSharpCode.AvalonEdit.Editing
} }
} }
} }
}
/// <summary>
/// Calculates fold lines for all folding sections that start inside the current view
/// </summary>
void CalculateFoldLinesForMarkers(List<TextLine> allTextLines, Pen[] colors, Pen[] endMarker)
{
foreach (FoldingMarginMarker marker in markers) { foreach (FoldingMarginMarker marker in markers) {
int end = marker.FoldingSection.EndOffset; int end = marker.FoldingSection.EndOffset;
int endTextLineNr = GetTextLineIndexFromOffset(allTextLines, end); int endTextLineNr = GetTextLineIndexFromOffset(allTextLines, end);
@ -177,7 +200,14 @@ namespace ICSharpCode.AvalonEdit.Editing
} }
} }
} }
}
/// <summary>
/// Draws the lines for the folding sections (vertical line with 'color', horizontal lines with 'endMarker')
/// Each entry in the input arrays corresponds to one TextLine.
/// </summary>
void DrawFoldLines(DrawingContext drawingContext, Pen[] colors, Pen[] endMarker)
{
double markerXPos = Math.Round(RenderSize.Width / 2); double markerXPos = Math.Round(RenderSize.Width / 2);
double startY = 0; double startY = 0;
Pen currentPen = colors[0]; Pen currentPen = colors[0];
@ -186,16 +216,12 @@ namespace ICSharpCode.AvalonEdit.Editing
foreach (TextLine tl in vl.TextLines) { foreach (TextLine tl in vl.TextLines) {
if (endMarker[tlNumber] != null) { if (endMarker[tlNumber] != null) {
double visualPos = GetVisualPos(vl, tl); double visualPos = GetVisualPos(vl, tl);
drawingContext.DrawLine(endMarker[tlNumber], drawingContext.DrawLine(endMarker[tlNumber], new Point(markerXPos, visualPos), new Point(RenderSize.Width, visualPos));
new Point(markerXPos, visualPos),
new Point(RenderSize.Width, visualPos));
} }
if (colors[tlNumber + 1] != currentPen) { if (colors[tlNumber + 1] != currentPen) {
double visualPos = GetVisualPos(vl, tl); double visualPos = GetVisualPos(vl, tl);
if (currentPen != null) { if (currentPen != null) {
drawingContext.DrawLine(currentPen, drawingContext.DrawLine(currentPen, new Point(markerXPos, startY), new Point(markerXPos, visualPos));
new Point(markerXPos, startY),
new Point(markerXPos, visualPos));
} }
currentPen = colors[tlNumber + 1]; currentPen = colors[tlNumber + 1];
startY = visualPos; startY = visualPos;
@ -204,12 +230,8 @@ namespace ICSharpCode.AvalonEdit.Editing
} }
} }
if (currentPen != null) { if (currentPen != null) {
drawingContext.DrawLine(currentPen, drawingContext.DrawLine(currentPen, new Point(markerXPos, startY), new Point(markerXPos, RenderSize.Height));
new Point(markerXPos, startY),
new Point(markerXPos, RenderSize.Height));
} }
base.OnRender(drawingContext);
} }
double GetVisualPos(VisualLine vl, TextLine tl) double GetVisualPos(VisualLine vl, TextLine tl)

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Selection.cs

@ -130,7 +130,7 @@ namespace ICSharpCode.AvalonEdit.Editing
DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter; DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter;
StringBuilder html = new StringBuilder(); StringBuilder html = new StringBuilder();
bool first = true; bool first = true;
foreach (ISegment selectedSegment in textArea.Selection.Segments) { foreach (ISegment selectedSegment in this.Segments) {
if (first) if (first)
first = false; first = false;
else else

3
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/SelectionMouseHandler.cs

@ -158,6 +158,7 @@ namespace ICSharpCode.AvalonEdit.Editing
return DragDropEffects.None; return DragDropEffects.None;
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
void textArea_DragLeave(object sender, DragEventArgs e) void textArea_DragLeave(object sender, DragEventArgs e)
{ {
try { try {
@ -224,6 +225,7 @@ namespace ICSharpCode.AvalonEdit.Editing
})); }));
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
void textArea_GiveFeedback(object sender, GiveFeedbackEventArgs e) void textArea_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{ {
try { try {
@ -234,6 +236,7 @@ namespace ICSharpCode.AvalonEdit.Editing
} }
} }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
void textArea_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) void textArea_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{ {
try { try {

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj

@ -77,7 +77,6 @@
<Link>Properties\GlobalAssemblyInfo.cs</Link> <Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile> </Compile>
<Compile Include="AvalonEditCommands.cs" /> <Compile Include="AvalonEditCommands.cs" />
<Compile Include="CaretPositioningMode.cs" />
<Compile Include="CodeCompletion\CompletionListBox.cs" /> <Compile Include="CodeCompletion\CompletionListBox.cs" />
<Compile Include="CodeCompletion\CompletionWindowBase.cs" /> <Compile Include="CodeCompletion\CompletionWindowBase.cs" />
<Compile Include="CodeCompletion\CompletionList.cs" /> <Compile Include="CodeCompletion\CompletionList.cs" />

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Rendering/VisualLineElement.cs

@ -11,6 +11,8 @@ using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media.TextFormatting; using System.Windows.Media.TextFormatting;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.Rendering namespace ICSharpCode.AvalonEdit.Rendering
{ {
/// <summary> /// <summary>

12
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/TextEditor.cs

@ -604,8 +604,10 @@ namespace ICSharpCode.AvalonEdit
public string SelectedText { public string SelectedText {
get { get {
TextArea textArea = this.TextArea; TextArea textArea = this.TextArea;
if (textArea != null && textArea.Document != null) // We'll get the text from the whole surrounding segment.
return textArea.Selection.GetText(textArea.Document); // This is done to ensure that SelectedText.Length == SelectionLength.
if (textArea != null && textArea.Document != null && !textArea.Selection.IsEmpty)
return textArea.Document.GetText(textArea.Selection.SurroundingSegment);
else else
return string.Empty; return string.Empty;
} }
@ -614,7 +616,11 @@ namespace ICSharpCode.AvalonEdit
throw new ArgumentNullException("value"); throw new ArgumentNullException("value");
TextArea textArea = this.TextArea; TextArea textArea = this.TextArea;
if (textArea != null && textArea.Document != null) { if (textArea != null && textArea.Document != null) {
textArea.ReplaceSelectionWithText(value); int offset = this.SelectionStart;
int length = this.SelectionLength;
textArea.Document.Replace(offset, length, value);
// keep inserted text selected
textArea.Selection = new SimpleSelection(offset, offset + value.Length);
} }
} }
} }

1
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Xml/AXmlAttribute.cs

@ -19,6 +19,7 @@ namespace ICSharpCode.AvalonEdit.Xml
/// <summary> /// <summary>
/// Name-value pair in a tag /// Name-value pair in a tag
/// </summary> /// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
public class AXmlAttribute: AXmlObject public class AXmlAttribute: AXmlObject
{ {
/// <summary> Name with namespace prefix - exactly as in source file </summary> /// <summary> Name with namespace prefix - exactly as in source file </summary>

Loading…
Cancel
Save