Browse Source

AvalonEdit: code cleanup

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4686 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 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 @@ @@ -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; @@ -11,6 +11,33 @@ using System.Windows.Documents;
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>
/// Static helper methods for working with text.
/// </summary>

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

@ -111,6 +111,16 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -111,6 +111,16 @@ namespace ICSharpCode.AvalonEdit.Editing
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/>
protected override void OnRender(DrawingContext drawingContext)
{
@ -119,18 +129,25 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -119,18 +129,25 @@ namespace ICSharpCode.AvalonEdit.Editing
if (TextView.VisualLines.Count == 0 || FoldingManager == null)
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();
Pen[] colors = new Pen[allTextLines.Count + 1];
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;
DocumentLine lastVisibleLine = TextView.VisualLines.Last().LastDocumentLine;
int viewEndOffset = lastVisibleLine.Offset + lastVisibleLine.Length;
int viewEndOffset = TextView.VisualLines.Last().LastDocumentLine.EndOffset;
var foldings = FoldingManager.GetFoldingsContaining(viewStartOffset);
int maxEndOffset = 0;
foreach (FoldingSection fs in foldings) {
@ -157,7 +174,13 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -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) {
int end = marker.FoldingSection.EndOffset;
int endTextLineNr = GetTextLineIndexFromOffset(allTextLines, end);
@ -177,7 +200,14 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -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 startY = 0;
Pen currentPen = colors[0];
@ -186,16 +216,12 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -186,16 +216,12 @@ namespace ICSharpCode.AvalonEdit.Editing
foreach (TextLine tl in vl.TextLines) {
if (endMarker[tlNumber] != null) {
double visualPos = GetVisualPos(vl, tl);
drawingContext.DrawLine(endMarker[tlNumber],
new Point(markerXPos, visualPos),
new Point(RenderSize.Width, visualPos));
drawingContext.DrawLine(endMarker[tlNumber], new Point(markerXPos, visualPos), new Point(RenderSize.Width, visualPos));
}
if (colors[tlNumber + 1] != currentPen) {
double visualPos = GetVisualPos(vl, tl);
if (currentPen != null) {
drawingContext.DrawLine(currentPen,
new Point(markerXPos, startY),
new Point(markerXPos, visualPos));
drawingContext.DrawLine(currentPen, new Point(markerXPos, startY), new Point(markerXPos, visualPos));
}
currentPen = colors[tlNumber + 1];
startY = visualPos;
@ -204,12 +230,8 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -204,12 +230,8 @@ namespace ICSharpCode.AvalonEdit.Editing
}
}
if (currentPen != null) {
drawingContext.DrawLine(currentPen,
new Point(markerXPos, startY),
new Point(markerXPos, RenderSize.Height));
drawingContext.DrawLine(currentPen, new Point(markerXPos, startY), new Point(markerXPos, RenderSize.Height));
}
base.OnRender(drawingContext);
}
double GetVisualPos(VisualLine vl, TextLine tl)

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

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

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

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

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

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

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

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

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

@ -604,8 +604,10 @@ namespace ICSharpCode.AvalonEdit @@ -604,8 +604,10 @@ namespace ICSharpCode.AvalonEdit
public string SelectedText {
get {
TextArea textArea = this.TextArea;
if (textArea != null && textArea.Document != null)
return textArea.Selection.GetText(textArea.Document);
// We'll get the text from the whole surrounding segment.
// 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
return string.Empty;
}
@ -614,7 +616,11 @@ namespace ICSharpCode.AvalonEdit @@ -614,7 +616,11 @@ namespace ICSharpCode.AvalonEdit
throw new ArgumentNullException("value");
TextArea textArea = this.TextArea;
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 @@ -19,6 +19,7 @@ namespace ICSharpCode.AvalonEdit.Xml
/// <summary>
/// Name-value pair in a tag
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")]
public class AXmlAttribute: AXmlObject
{
/// <summary> Name with namespace prefix - exactly as in source file </summary>

Loading…
Cancel
Save