Browse Source

Moved a few classes and methods in AvalonEdit to eliminate dependency cycles between namespaces.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4679 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
fa870bc2db
  1. 30
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ISegment.cs
  2. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextUtilities.cs
  3. 28
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Selection.cs
  4. 26
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HtmlClipboard.cs
  5. 4
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj
  6. 29
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ExtensionMethods.cs
  7. 2
      src/Main/Base/Project/Src/Editor/IDocumentLine.cs

30
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/ISegment.cs

@ -32,6 +32,36 @@ namespace ICSharpCode.AvalonEdit.Document @@ -32,6 +32,36 @@ namespace ICSharpCode.AvalonEdit.Document
int EndOffset { get; }
}
static class SegmentExtensions
{
/// <summary>
/// Gets whether the segment contains the offset.
/// </summary>
/// <returns>
/// True, if offset is between segment.Start and segment.End (inclusive); otherwise, false.
/// </returns>
public static bool Contains(this ISegment segment, int offset)
{
int start = segment.Offset;
int end = start + segment.Length;
return offset >= start && offset <= end;
}
/// <summary>
/// Gets the overlapping portion of the segments.
/// Returns SimpleSegment.Invalid if the segments don't overlap.
/// </summary>
public static SimpleSegment GetOverlap(this ISegment segment, ISegment other)
{
int start = Math.Max(segment.Offset, other.Offset);
int end = Math.Min(segment.EndOffset, other.EndOffset);
if (end < start)
return SimpleSegment.Invalid;
else
return new SimpleSegment(start, end - start);
}
}
/// <summary>
/// Represents a simple segment (Offset,Length pair) that is not automatically updated
/// on document changes.

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/TextUtilities.cs → src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextUtilities.cs

@ -9,9 +9,7 @@ using System; @@ -9,9 +9,7 @@ using System;
using System.Globalization;
using System.Windows.Documents;
using ICSharpCode.AvalonEdit.Document;
namespace ICSharpCode.AvalonEdit.Utils
namespace ICSharpCode.AvalonEdit.Document
{
/// <summary>
/// Static helper methods for working with text.

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

@ -8,10 +8,10 @@ @@ -8,10 +8,10 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Utils;
using System.Windows;
using ICSharpCode.AvalonEdit.Highlighting;
namespace ICSharpCode.AvalonEdit.Editing
{
@ -118,6 +118,28 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -118,6 +118,28 @@ namespace ICSharpCode.AvalonEdit.Editing
}
}
/// <summary>
/// Creates a HTML fragment for the selected text.
/// </summary>
public string CreateHtmlFragment(TextArea textArea, HtmlOptions options)
{
if (textArea == null)
throw new ArgumentNullException("textArea");
if (options == null)
throw new ArgumentNullException("options");
DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter;
StringBuilder html = new StringBuilder();
bool first = true;
foreach (ISegment selectedSegment in textArea.Selection.Segments) {
if (first)
first = false;
else
html.AppendLine("<br>");
html.Append(HtmlClipboard.CreateHtmlFragment(textArea.Document, highlighter, selectedSegment, options));
}
return html.ToString();
}
/// <inheritdoc/>
public abstract override bool Equals(object obj);
@ -156,7 +178,7 @@ namespace ICSharpCode.AvalonEdit.Editing @@ -156,7 +178,7 @@ namespace ICSharpCode.AvalonEdit.Editing
// Also copy text in HTML format to clipboard - good for pasting text into Word
// or to the SharpDevelop forums.
HtmlClipboard.SetHtml(data, HtmlClipboard.CreateHtmlFragmentForSelection(textArea, new HtmlOptions(textArea.Options)));
HtmlClipboard.SetHtml(data, CreateHtmlFragment(textArea, new HtmlOptions(textArea.Options)));
return data;
}
}

26
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/HtmlClipboard.cs → src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Highlighting/HtmlClipboard.cs

@ -12,10 +12,8 @@ using System.Text; @@ -12,10 +12,8 @@ using System.Text;
using System.Windows;
using ICSharpCode.AvalonEdit.Document;
using ICSharpCode.AvalonEdit.Editing;
using ICSharpCode.AvalonEdit.Highlighting;
namespace ICSharpCode.AvalonEdit.Utils
namespace ICSharpCode.AvalonEdit.Highlighting
{
/// <summary>
/// Allows copying HTML text to the clipboard.
@ -98,28 +96,6 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -98,28 +96,6 @@ namespace ICSharpCode.AvalonEdit.Utils
return html.ToString();
}
/// <summary>
/// Creates a HTML fragment for the selected part of the document.
/// </summary>
public static string CreateHtmlFragmentForSelection(TextArea textArea, HtmlOptions options)
{
if (textArea == null)
throw new ArgumentNullException("textArea");
if (options == null)
throw new ArgumentNullException("options");
DocumentHighlighter highlighter = textArea.GetService(typeof(DocumentHighlighter)) as DocumentHighlighter;
StringBuilder html = new StringBuilder();
bool first = true;
foreach (ISegment selectedSegment in textArea.Selection.Segments) {
if (first)
first = false;
else
html.AppendLine("<br>");
html.Append(CreateHtmlFragment(textArea.Document, highlighter, selectedSegment, options));
}
return html.ToString();
}
/// <summary>
/// Escapes text and writes the result to the StringBuilder.
/// </summary>

4
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/ICSharpCode.AvalonEdit.csproj

@ -117,6 +117,7 @@ @@ -117,6 +117,7 @@
</Compile>
<Compile Include="Document\TextLocation.cs" />
<Compile Include="Document\TextSegment.cs" />
<Compile Include="Document\TextUtilities.cs" />
<Compile Include="Document\UndoOperationGroup.cs">
<DependentUpon>UndoStack.cs</DependentUpon>
</Compile>
@ -182,6 +183,7 @@ @@ -182,6 +183,7 @@
<Compile Include="Highlighting\HighlightingColorizer.cs" />
<Compile Include="Highlighting\HighlightingDefinitionInvalidException.cs" />
<Compile Include="Highlighting\HighlightingManager.cs" />
<Compile Include="Highlighting\HtmlClipboard.cs" />
<Compile Include="Highlighting\IHighlightingDefinition.cs" />
<Compile Include="Highlighting\HighlightingRule.cs" />
<Compile Include="Highlighting\Resources\Resources.cs" />
@ -301,7 +303,6 @@ @@ -301,7 +303,6 @@
<Compile Include="Utils\Empty.cs" />
<Compile Include="Utils\ExtensionMethods.cs" />
<Compile Include="Utils\FileReader.cs" />
<Compile Include="Utils\HtmlClipboard.cs" />
<Compile Include="Utils\ImmutableStack.cs" />
<Compile Include="Utils\NullSafeCollection.cs" />
<Compile Include="Utils\ObserveAddRemoveCollection.cs" />
@ -309,7 +310,6 @@ @@ -309,7 +310,6 @@
<Compile Include="Utils\Rope.cs" />
<Compile Include="Utils\RopeNode.cs" />
<Compile Include="Utils\RopeTextReader.cs" />
<Compile Include="Utils\TextUtilities.cs" />
<Compile Include="Utils\WeakEventManagerBase.cs" />
<Compile Include="Utils\PixelSnapHelpers.cs" />
<Compile Include="Utils\ThrowUtil.cs" />

29
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Utils/ExtensionMethods.cs

@ -132,35 +132,6 @@ namespace ICSharpCode.AvalonEdit.Utils @@ -132,35 +132,6 @@ namespace ICSharpCode.AvalonEdit.Utils
}
#endregion
#region ISegment extensions
/// <summary>
/// Gets whether the segment contains the offset.
/// </summary>
/// <returns>
/// True, if offset is between segment.Start and segment.End (inclusive); otherwise, false.
/// </returns>
public static bool Contains(this ISegment segment, int offset)
{
int start = segment.Offset;
int end = start + segment.Length;
return offset >= start && offset <= end;
}
/// <summary>
/// Gets the overlapping portion of the segments.
/// Returns SimpleSegment.Invalid if the segments don't overlap.
/// </summary>
public static SimpleSegment GetOverlap(this ISegment segment, ISegment other)
{
int start = Math.Max(segment.Offset, other.Offset);
int end = Math.Min(segment.EndOffset, other.EndOffset);
if (end < start)
return SimpleSegment.Invalid;
else
return new SimpleSegment(start, end - start);
}
#endregion
#region DPI independence
public static Rect TransformToDevice(this Rect rect, Visual visual)
{

2
src/Main/Base/Project/Src/Editor/IDocumentLine.cs

@ -9,7 +9,7 @@ using System; @@ -9,7 +9,7 @@ using System;
namespace ICSharpCode.SharpDevelop.Editor
{
/// <summary>
/// <summary>
/// A line inside a <see cref="IDocument"/>.
/// </summary>
public interface IDocumentLine

Loading…
Cancel
Save