mirror of https://github.com/icsharpcode/ILSpy.git
62 changed files with 1871 additions and 1140 deletions
@ -1,442 +0,0 @@ |
|||||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.Diagnostics; |
|
||||||
using System.Linq; |
|
||||||
|
|
||||||
using ICSharpCode.AvalonEdit.Document; |
|
||||||
using ICSharpCode.NRefactory; |
|
||||||
|
|
||||||
namespace ILSpy.Debugger.AvalonEdit.Editor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Wraps the AvalonEdit TextDocument to provide the IDocument interface.
|
|
||||||
/// </summary>
|
|
||||||
public class AvalonEditDocumentAdapter : IDocument |
|
||||||
{ |
|
||||||
internal readonly TextDocument document; |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new AvalonEditDocumentAdapter instance.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="document">The document to wrap.</param>
|
|
||||||
public AvalonEditDocumentAdapter(TextDocument document) |
|
||||||
{ |
|
||||||
if (document == null) |
|
||||||
throw new ArgumentNullException("document"); |
|
||||||
this.document = document; |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new document.
|
|
||||||
/// </summary>
|
|
||||||
public AvalonEditDocumentAdapter() |
|
||||||
{ |
|
||||||
this.document = new TextDocument(); |
|
||||||
} |
|
||||||
|
|
||||||
sealed class LineAdapter : IDocumentLine |
|
||||||
{ |
|
||||||
readonly TextDocument document; |
|
||||||
readonly DocumentLine line; |
|
||||||
|
|
||||||
public LineAdapter(TextDocument document, DocumentLine line) |
|
||||||
{ |
|
||||||
Debug.Assert(document != null); |
|
||||||
Debug.Assert(line != null); |
|
||||||
this.document = document; |
|
||||||
this.line = line; |
|
||||||
} |
|
||||||
|
|
||||||
public int Offset { |
|
||||||
get { return line.Offset; } |
|
||||||
} |
|
||||||
|
|
||||||
public int Length { |
|
||||||
get { return line.Length; } |
|
||||||
} |
|
||||||
|
|
||||||
public int EndOffset { |
|
||||||
get { return line.EndOffset; } |
|
||||||
} |
|
||||||
|
|
||||||
public int TotalLength { |
|
||||||
get { return line.TotalLength; } |
|
||||||
} |
|
||||||
|
|
||||||
public int DelimiterLength { |
|
||||||
get { return line.DelimiterLength; } |
|
||||||
} |
|
||||||
|
|
||||||
public int LineNumber { |
|
||||||
get { return line.LineNumber; } |
|
||||||
} |
|
||||||
|
|
||||||
public string Text { |
|
||||||
get { return document.GetText(line); } |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public int TextLength { |
|
||||||
get { return document.TextLength; } |
|
||||||
} |
|
||||||
|
|
||||||
public int TotalNumberOfLines { |
|
||||||
get { return document.LineCount; } |
|
||||||
} |
|
||||||
|
|
||||||
public string Text { |
|
||||||
get { return document.Text; } |
|
||||||
set { document.Text = value; } |
|
||||||
} |
|
||||||
|
|
||||||
public event EventHandler TextChanged { |
|
||||||
add { document.TextChanged += value; } |
|
||||||
remove { document.TextChanged -= value; } |
|
||||||
} |
|
||||||
|
|
||||||
public IDocumentLine GetLine(int lineNumber) |
|
||||||
{ |
|
||||||
return new LineAdapter(document, document.GetLineByNumber(lineNumber)); |
|
||||||
} |
|
||||||
|
|
||||||
public IDocumentLine GetLineForOffset(int offset) |
|
||||||
{ |
|
||||||
return new LineAdapter(document, document.GetLineByOffset(offset)); |
|
||||||
} |
|
||||||
|
|
||||||
public int PositionToOffset(int line, int column) |
|
||||||
{ |
|
||||||
try { |
|
||||||
return document.GetOffset(new TextLocation(line, column)); |
|
||||||
} catch (ArgumentOutOfRangeException e) { |
|
||||||
// for UDC: re-throw exception so that stack trace identifies the caller (instead of the adapter)
|
|
||||||
throw new ArgumentOutOfRangeException(e.ParamName, e.ActualValue, e.Message); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public Location OffsetToPosition(int offset) |
|
||||||
{ |
|
||||||
try { |
|
||||||
return ToLocation(document.GetLocation(offset)); |
|
||||||
} catch (ArgumentOutOfRangeException e) { |
|
||||||
// for UDC: re-throw exception so that stack trace identifies the caller (instead of the adapter)
|
|
||||||
throw new ArgumentOutOfRangeException(e.ParamName, e.ActualValue, e.Message); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public static Location ToLocation(TextLocation position) |
|
||||||
{ |
|
||||||
return new Location(position.Column, position.Line); |
|
||||||
} |
|
||||||
|
|
||||||
public static TextLocation ToPosition(Location location) |
|
||||||
{ |
|
||||||
return new TextLocation(location.Line, location.Column); |
|
||||||
} |
|
||||||
|
|
||||||
public void Insert(int offset, string text) |
|
||||||
{ |
|
||||||
document.Insert(offset, text); |
|
||||||
} |
|
||||||
|
|
||||||
public void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType) |
|
||||||
{ |
|
||||||
if (defaultAnchorMovementType == AnchorMovementType.BeforeInsertion) { |
|
||||||
document.Replace(offset, 0, text, OffsetChangeMappingType.KeepAnchorBeforeInsertion); |
|
||||||
} else { |
|
||||||
document.Insert(offset, text); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void Remove(int offset, int length) |
|
||||||
{ |
|
||||||
document.Remove(offset, length); |
|
||||||
} |
|
||||||
|
|
||||||
public void Replace(int offset, int length, string newText) |
|
||||||
{ |
|
||||||
document.Replace(offset, length, newText); |
|
||||||
} |
|
||||||
|
|
||||||
public void Replace(int offset, int length, string newText, AnchorMovementType defaultAnchorMovementType) |
|
||||||
{ |
|
||||||
document.Replace(offset, length, newText); |
|
||||||
} |
|
||||||
|
|
||||||
public char GetCharAt(int offset) |
|
||||||
{ |
|
||||||
return document.GetCharAt(offset); |
|
||||||
} |
|
||||||
|
|
||||||
public string GetText(int offset, int length) |
|
||||||
{ |
|
||||||
return document.GetText(offset, length); |
|
||||||
} |
|
||||||
|
|
||||||
public System.IO.TextReader CreateReader() |
|
||||||
{ |
|
||||||
return document.CreateSnapshot().CreateReader(); |
|
||||||
} |
|
||||||
|
|
||||||
public System.IO.TextReader CreateReader(int offset, int length) |
|
||||||
{ |
|
||||||
return document.CreateSnapshot(offset, length).CreateReader(); |
|
||||||
} |
|
||||||
|
|
||||||
#region Snapshots and ITextBufferVersion
|
|
||||||
public ITextBuffer CreateSnapshot() |
|
||||||
{ |
|
||||||
ChangeTrackingCheckpoint checkpoint; |
|
||||||
ITextSource textSource = document.CreateSnapshot(out checkpoint); |
|
||||||
return new Snapshot(textSource, checkpoint); |
|
||||||
} |
|
||||||
|
|
||||||
public ITextBuffer CreateSnapshot(int offset, int length) |
|
||||||
{ |
|
||||||
return new AvalonEditTextSourceAdapter(document.CreateSnapshot(offset, length)); |
|
||||||
} |
|
||||||
|
|
||||||
public ITextBufferVersion Version { |
|
||||||
get { |
|
||||||
return new SnapshotVersion(ChangeTrackingCheckpoint.Create(document)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
sealed class Snapshot : AvalonEditTextSourceAdapter |
|
||||||
{ |
|
||||||
readonly ITextBufferVersion version; |
|
||||||
|
|
||||||
public Snapshot(ITextSource textSource, ChangeTrackingCheckpoint checkpoint) |
|
||||||
: base(textSource) |
|
||||||
{ |
|
||||||
this.version = new SnapshotVersion(checkpoint); |
|
||||||
} |
|
||||||
|
|
||||||
public override ITextBuffer CreateSnapshot() |
|
||||||
{ |
|
||||||
// Snapshot is immutable
|
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public override ITextBufferVersion Version { |
|
||||||
get { return version; } |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
sealed class SnapshotVersion : ITextBufferVersion |
|
||||||
{ |
|
||||||
readonly ChangeTrackingCheckpoint checkpoint; |
|
||||||
|
|
||||||
public SnapshotVersion(ChangeTrackingCheckpoint checkpoint) |
|
||||||
{ |
|
||||||
Debug.Assert(checkpoint != null); |
|
||||||
this.checkpoint = checkpoint; |
|
||||||
} |
|
||||||
|
|
||||||
public bool BelongsToSameDocumentAs(ITextBufferVersion other) |
|
||||||
{ |
|
||||||
SnapshotVersion otherVersion = other as SnapshotVersion; |
|
||||||
return otherVersion != null && checkpoint.BelongsToSameDocumentAs(otherVersion.checkpoint); |
|
||||||
} |
|
||||||
|
|
||||||
public int CompareAge(ITextBufferVersion other) |
|
||||||
{ |
|
||||||
SnapshotVersion otherVersion = other as SnapshotVersion; |
|
||||||
if (otherVersion == null) |
|
||||||
throw new ArgumentException("Does not belong to same document"); |
|
||||||
return checkpoint.CompareAge(otherVersion.checkpoint); |
|
||||||
} |
|
||||||
|
|
||||||
public IEnumerable<TextChangeEventArgs> GetChangesTo(ITextBufferVersion other) |
|
||||||
{ |
|
||||||
SnapshotVersion otherVersion = other as SnapshotVersion; |
|
||||||
if (otherVersion == null) |
|
||||||
throw new ArgumentException("Does not belong to same document"); |
|
||||||
return checkpoint.GetChangesTo(otherVersion.checkpoint).Select(c => new TextChangeEventArgs(c.Offset, c.RemovedText, c.InsertedText)); |
|
||||||
} |
|
||||||
|
|
||||||
public int MoveOffsetTo(ITextBufferVersion other, int oldOffset, AnchorMovementType movement) |
|
||||||
{ |
|
||||||
SnapshotVersion otherVersion = other as SnapshotVersion; |
|
||||||
if (otherVersion == null) |
|
||||||
throw new ArgumentException("Does not belong to same document"); |
|
||||||
switch (movement) { |
|
||||||
case AnchorMovementType.AfterInsertion: |
|
||||||
return checkpoint.MoveOffsetTo(otherVersion.checkpoint, oldOffset, ICSharpCode.AvalonEdit.Document.AnchorMovementType.AfterInsertion); |
|
||||||
case AnchorMovementType.BeforeInsertion: |
|
||||||
return checkpoint.MoveOffsetTo(otherVersion.checkpoint, oldOffset, ICSharpCode.AvalonEdit.Document.AnchorMovementType.BeforeInsertion); |
|
||||||
default: |
|
||||||
throw new NotSupportedException(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
public void StartUndoableAction() |
|
||||||
{ |
|
||||||
document.BeginUpdate(); |
|
||||||
} |
|
||||||
|
|
||||||
public void EndUndoableAction() |
|
||||||
{ |
|
||||||
document.EndUpdate(); |
|
||||||
} |
|
||||||
|
|
||||||
public IDisposable OpenUndoGroup() |
|
||||||
{ |
|
||||||
return document.RunUpdate(); |
|
||||||
} |
|
||||||
|
|
||||||
public ITextAnchor CreateAnchor(int offset) |
|
||||||
{ |
|
||||||
return new AnchorAdapter(document.CreateAnchor(offset)); |
|
||||||
} |
|
||||||
|
|
||||||
#region AnchorAdapter
|
|
||||||
sealed class AnchorAdapter : ITextAnchor |
|
||||||
{ |
|
||||||
readonly TextAnchor anchor; |
|
||||||
|
|
||||||
public AnchorAdapter(TextAnchor anchor) |
|
||||||
{ |
|
||||||
this.anchor = anchor; |
|
||||||
} |
|
||||||
|
|
||||||
#region Forward Deleted Event
|
|
||||||
EventHandler deleted; |
|
||||||
|
|
||||||
public event EventHandler Deleted { |
|
||||||
add { |
|
||||||
// we cannot simply forward the event handler because
|
|
||||||
// that would raise the event with an incorrect sender
|
|
||||||
if (deleted == null && value != null) |
|
||||||
anchor.Deleted += OnDeleted; |
|
||||||
deleted += value; |
|
||||||
} |
|
||||||
remove { |
|
||||||
deleted -= value; |
|
||||||
if (deleted == null) |
|
||||||
anchor.Deleted -= OnDeleted; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void OnDeleted(object sender, EventArgs e) |
|
||||||
{ |
|
||||||
// raise event with correct sender
|
|
||||||
if (deleted != null) |
|
||||||
deleted(this, e); |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
public Location Location { |
|
||||||
get { return ToLocation(anchor.Location); } |
|
||||||
} |
|
||||||
|
|
||||||
public int Offset { |
|
||||||
get { return anchor.Offset; } |
|
||||||
} |
|
||||||
|
|
||||||
public ILSpy.Debugger.AvalonEdit.Editor.AnchorMovementType MovementType { |
|
||||||
get { |
|
||||||
return (ILSpy.Debugger.AvalonEdit.Editor.AnchorMovementType)anchor.MovementType; |
|
||||||
} |
|
||||||
set { |
|
||||||
anchor.MovementType = (ICSharpCode.AvalonEdit.Document.AnchorMovementType)value; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public bool SurviveDeletion { |
|
||||||
get { return anchor.SurviveDeletion; } |
|
||||||
set { anchor.SurviveDeletion = value; } |
|
||||||
} |
|
||||||
|
|
||||||
public bool IsDeleted { |
|
||||||
get { return anchor.IsDeleted; } |
|
||||||
} |
|
||||||
|
|
||||||
public int Line { |
|
||||||
get { return anchor.Line; } |
|
||||||
} |
|
||||||
|
|
||||||
public int Column { |
|
||||||
get { return anchor.Column; } |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Changing/Changed events
|
|
||||||
EventHandler<TextChangeEventArgs> changing, changed; |
|
||||||
bool eventsAreAttached; |
|
||||||
|
|
||||||
void AttachEvents() |
|
||||||
{ |
|
||||||
if (!eventsAreAttached && (changing != null || changed != null)) { |
|
||||||
eventsAreAttached = true; |
|
||||||
document.Changing += document_Changing; |
|
||||||
document.Changed += document_Changed; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DetachEvents() |
|
||||||
{ |
|
||||||
if (eventsAreAttached && changing == null && changed == null) { |
|
||||||
eventsAreAttached = false; |
|
||||||
document.Changing -= document_Changing; |
|
||||||
document.Changed -= document_Changed; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void document_Changing(object sender, DocumentChangeEventArgs e) |
|
||||||
{ |
|
||||||
if (changing != null) |
|
||||||
changing(this, new TextChangeEventArgs(e.Offset, e.RemovedText, e.InsertedText)); |
|
||||||
} |
|
||||||
|
|
||||||
void document_Changed(object sender, DocumentChangeEventArgs e) |
|
||||||
{ |
|
||||||
if (changed != null) |
|
||||||
changed(this, new TextChangeEventArgs(e.Offset, e.RemovedText, e.InsertedText)); |
|
||||||
} |
|
||||||
|
|
||||||
public event EventHandler<TextChangeEventArgs> Changing { |
|
||||||
add { |
|
||||||
changing += value; |
|
||||||
AttachEvents(); |
|
||||||
} |
|
||||||
remove { |
|
||||||
changing -= value; |
|
||||||
DetachEvents(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public event EventHandler<TextChangeEventArgs> Changed { |
|
||||||
add { |
|
||||||
changed += value; |
|
||||||
AttachEvents(); |
|
||||||
} |
|
||||||
remove { |
|
||||||
changed -= value; |
|
||||||
DetachEvents(); |
|
||||||
} |
|
||||||
} |
|
||||||
#endregion
|
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,98 +0,0 @@ |
|||||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using ICSharpCode.AvalonEdit.Document; |
|
||||||
using System; |
|
||||||
|
|
||||||
namespace ILSpy.Debugger.AvalonEdit.Editor |
|
||||||
{ |
|
||||||
public class AvalonEditTextSourceAdapter : ITextBuffer |
|
||||||
{ |
|
||||||
internal readonly ITextSource textSource; |
|
||||||
|
|
||||||
public AvalonEditTextSourceAdapter(ITextSource textSource) |
|
||||||
{ |
|
||||||
if (textSource == null) |
|
||||||
throw new ArgumentNullException("textSource"); |
|
||||||
this.textSource = textSource; |
|
||||||
} |
|
||||||
|
|
||||||
public virtual ITextBufferVersion Version { |
|
||||||
get { return null; } |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an immutable snapshot of this text buffer.
|
|
||||||
/// </summary>
|
|
||||||
public virtual ITextBuffer CreateSnapshot() |
|
||||||
{ |
|
||||||
return new AvalonEditTextSourceAdapter(textSource.CreateSnapshot()); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an immutable snapshot of a part of this text buffer.
|
|
||||||
/// Unlike all other methods in this interface, this method is thread-safe.
|
|
||||||
/// </summary>
|
|
||||||
public ITextBuffer CreateSnapshot(int offset, int length) |
|
||||||
{ |
|
||||||
return new AvalonEditTextSourceAdapter(textSource.CreateSnapshot(offset, length)); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new TextReader to read from this text buffer.
|
|
||||||
/// </summary>
|
|
||||||
public System.IO.TextReader CreateReader() |
|
||||||
{ |
|
||||||
return textSource.CreateReader(); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new TextReader to read from this text buffer.
|
|
||||||
/// </summary>
|
|
||||||
public System.IO.TextReader CreateReader(int offset, int length) |
|
||||||
{ |
|
||||||
return textSource.CreateSnapshot(offset, length).CreateReader(); |
|
||||||
} |
|
||||||
|
|
||||||
public int TextLength { |
|
||||||
get { return textSource.TextLength; } |
|
||||||
} |
|
||||||
|
|
||||||
public string Text { |
|
||||||
get { return textSource.Text; } |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Is raised when the Text property changes.
|
|
||||||
/// </summary>
|
|
||||||
public event EventHandler TextChanged { |
|
||||||
add { textSource.TextChanged += value; } |
|
||||||
remove { textSource.TextChanged -= value; } |
|
||||||
} |
|
||||||
|
|
||||||
public char GetCharAt(int offset) |
|
||||||
{ |
|
||||||
return textSource.GetCharAt(offset); |
|
||||||
} |
|
||||||
|
|
||||||
public string GetText(int offset, int length) |
|
||||||
{ |
|
||||||
return textSource.GetText(offset, length); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,85 +0,0 @@ |
|||||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using ICSharpCode.NRefactory.CSharp; |
|
||||||
|
|
||||||
namespace ILSpy.Debugger.AvalonEdit.Editor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// A document representing a source code file for refactoring.
|
|
||||||
/// Line and column counting starts at 1.
|
|
||||||
/// Offset counting starts at 0.
|
|
||||||
/// </summary>
|
|
||||||
public interface IDocument : ITextBuffer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Gets/Sets the whole text as string.
|
|
||||||
/// </summary>
|
|
||||||
new string Text { get; set; } // hides TextBuffer.Text to add the setter
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total number of lines in the document.
|
|
||||||
/// </summary>
|
|
||||||
int TotalNumberOfLines { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the document line with the specified number.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="lineNumber">The number of the line to retrieve. The first line has number 1.</param>
|
|
||||||
IDocumentLine GetLine(int lineNumber); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the document line that contains the specified offset.
|
|
||||||
/// </summary>
|
|
||||||
IDocumentLine GetLineForOffset(int offset); |
|
||||||
|
|
||||||
int PositionToOffset(int line, int column); |
|
||||||
AstLocation OffsetToPosition(int offset); |
|
||||||
|
|
||||||
void Insert(int offset, string text); |
|
||||||
void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType); |
|
||||||
void Remove(int offset, int length); |
|
||||||
void Replace(int offset, int length, string newText); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Make the document combine the following actions into a single
|
|
||||||
/// action for undo purposes.
|
|
||||||
/// </summary>
|
|
||||||
void StartUndoableAction(); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Ends the undoable action started with <see cref="StartUndoableAction"/>.
|
|
||||||
/// </summary>
|
|
||||||
void EndUndoableAction(); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an undo group. Dispose the returned value to close the undo group.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>An object that closes the undo group when Dispose() is called.</returns>
|
|
||||||
IDisposable OpenUndoGroup(); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new text anchor at the specified position.
|
|
||||||
/// </summary>
|
|
||||||
ITextAnchor CreateAnchor(int offset); |
|
||||||
|
|
||||||
event EventHandler<TextChangeEventArgs> Changing; |
|
||||||
event EventHandler<TextChangeEventArgs> Changed; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,98 +0,0 @@ |
|||||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using ICSharpCode.NRefactory.CSharp; |
|
||||||
|
|
||||||
namespace ILSpy.Debugger.AvalonEdit.Editor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Represents an anchored location inside an <see cref="IDocument"/>.
|
|
||||||
/// </summary>
|
|
||||||
public interface ITextAnchor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Gets the text location of this anchor.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
|
||||||
AstLocation Location { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the offset of the text anchor.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
|
||||||
int Offset { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Controls how the anchor moves.
|
|
||||||
/// </summary>
|
|
||||||
AnchorMovementType MovementType { get; set; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Specifies whether the anchor survives deletion of the text containing it.
|
|
||||||
/// <c>false</c>: The anchor is deleted when the a selection that includes the anchor is deleted.
|
|
||||||
/// <c>true</c>: The anchor is not deleted.
|
|
||||||
/// </summary>
|
|
||||||
bool SurviveDeletion { get; set; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets whether the anchor was deleted.
|
|
||||||
/// </summary>
|
|
||||||
bool IsDeleted { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Occurs after the anchor was deleted.
|
|
||||||
/// </summary>
|
|
||||||
event EventHandler Deleted; |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the line number of the anchor.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
|
||||||
int Line { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the column number of this anchor.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
|
||||||
int Column { get; } |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defines how a text anchor moves.
|
|
||||||
/// </summary>
|
|
||||||
public enum AnchorMovementType |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// When text is inserted at the anchor position, the type of the insertion
|
|
||||||
/// determines where the caret moves to. For normal insertions, the anchor will stay
|
|
||||||
/// behind the inserted text.
|
|
||||||
/// </summary>
|
|
||||||
Default = ICSharpCode.AvalonEdit.Document.AnchorMovementType.Default, |
|
||||||
/// <summary>
|
|
||||||
/// Behaves like a start marker - when text is inserted at the anchor position, the anchor will stay
|
|
||||||
/// before the inserted text.
|
|
||||||
/// </summary>
|
|
||||||
BeforeInsertion = ICSharpCode.AvalonEdit.Document.AnchorMovementType.BeforeInsertion, |
|
||||||
/// <summary>
|
|
||||||
/// Behave like an end marker - when text is insered at the anchor position, the anchor will move
|
|
||||||
/// after the inserted text.
|
|
||||||
/// </summary>
|
|
||||||
AfterInsertion = ICSharpCode.AvalonEdit.Document.AnchorMovementType.AfterInsertion |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,146 +0,0 @@ |
|||||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
||||||
// software and associated documentation files (the "Software"), to deal in the Software
|
|
||||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
||||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
||||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all copies or
|
|
||||||
// substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
||||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
||||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
||||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
||||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
// DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
using System; |
|
||||||
using System.Collections.Generic; |
|
||||||
using System.IO; |
|
||||||
|
|
||||||
using ICSharpCode.AvalonEdit.Document; |
|
||||||
|
|
||||||
namespace ILSpy.Debugger.AvalonEdit.Editor |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// A read-only view on a (potentially mutable) text buffer.
|
|
||||||
/// The IDocument interfaces derives from this interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface ITextBuffer |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Gets a version identifier for this text buffer.
|
|
||||||
/// Returns null for unversioned text buffers.
|
|
||||||
/// </summary>
|
|
||||||
ITextBufferVersion Version { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an immutable snapshot of this text buffer.
|
|
||||||
/// Unlike all other methods in this interface, this method is thread-safe.
|
|
||||||
/// </summary>
|
|
||||||
ITextBuffer CreateSnapshot(); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an immutable snapshot of a part of this text buffer.
|
|
||||||
/// Unlike all other methods in this interface, this method is thread-safe.
|
|
||||||
/// </summary>
|
|
||||||
ITextBuffer CreateSnapshot(int offset, int length); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new TextReader to read from this text buffer.
|
|
||||||
/// </summary>
|
|
||||||
TextReader CreateReader(); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new TextReader to read from this text buffer.
|
|
||||||
/// </summary>
|
|
||||||
TextReader CreateReader(int offset, int length); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the total text length.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The length of the text, in characters.</returns>
|
|
||||||
/// <remarks>This is the same as Text.Length, but is more efficient because
|
|
||||||
/// it doesn't require creating a String object.</remarks>
|
|
||||||
int TextLength { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the whole text as string.
|
|
||||||
/// </summary>
|
|
||||||
string Text { get; } |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Is raised when the Text property changes.
|
|
||||||
/// </summary>
|
|
||||||
event EventHandler TextChanged; |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a character at the specified position in the document.
|
|
||||||
/// </summary>
|
|
||||||
/// <paramref name="offset">The index of the character to get.</paramref>
|
|
||||||
/// <exception cref="ArgumentOutOfRangeException">Offset is outside the valid range (0 to TextLength-1).</exception>
|
|
||||||
/// <returns>The character at the specified position.</returns>
|
|
||||||
/// <remarks>This is the same as Text[offset], but is more efficient because
|
|
||||||
/// it doesn't require creating a String object.</remarks>
|
|
||||||
char GetCharAt(int offset); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves the text for a portion of the document.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
|
|
||||||
/// <remarks>This is the same as Text.Substring, but is more efficient because
|
|
||||||
/// it doesn't require creating a String object for the whole document.</remarks>
|
|
||||||
string GetText(int offset, int length); |
|
||||||
} |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a version identifier for a text buffer.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// This is SharpDevelop's equivalent to AvalonEdit ChangeTrackingCheckpoint.
|
|
||||||
/// It is used by the ParserService to efficiently detect whether a document has changed and needs reparsing.
|
|
||||||
/// It is a separate class from ITextBuffer to allow the GC to collect the text buffer while the version checkpoint
|
|
||||||
/// is still in use.
|
|
||||||
/// </remarks>
|
|
||||||
public interface ITextBufferVersion |
|
||||||
{ |
|
||||||
/// <summary>
|
|
||||||
/// Gets whether this checkpoint belongs to the same document as the other checkpoint.
|
|
||||||
/// </summary>
|
|
||||||
bool BelongsToSameDocumentAs(ITextBufferVersion other); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares the age of this checkpoint to the other checkpoint.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>This method is thread-safe.</remarks>
|
|
||||||
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this version.</exception>
|
|
||||||
/// <returns>-1 if this version is older than <paramref name="other"/>.
|
|
||||||
/// 0 if <c>this</c> version instance represents the same version as <paramref name="other"/>.
|
|
||||||
/// 1 if this version is newer than <paramref name="other"/>.</returns>
|
|
||||||
int CompareAge(ITextBufferVersion other); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the changes from this checkpoint to the other checkpoint.
|
|
||||||
/// If 'other' is older than this checkpoint, reverse changes are calculated.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>This method is thread-safe.</remarks>
|
|
||||||
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception>
|
|
||||||
IEnumerable<TextChangeEventArgs> GetChangesTo(ITextBufferVersion other); |
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Calculates where the offset has moved in the other buffer version.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception>
|
|
||||||
int MoveOffsetTo(ITextBufferVersion other, int oldOffset, AnchorMovementType movement); |
|
||||||
} |
|
||||||
|
|
||||||
public sealed class StringTextBuffer : AvalonEditTextSourceAdapter |
|
||||||
{ |
|
||||||
public StringTextBuffer(string text) |
|
||||||
: base(new StringTextSource(text)) |
|
||||||
{ |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -0,0 +1,50 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
using System; |
||||||
|
using System.Windows; |
||||||
|
using ICSharpCode.Decompiler; |
||||||
|
using ICSharpCode.ILSpy.AvalonEdit; |
||||||
|
using ICSharpCode.ILSpy.Debugger.Services; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.Debugger.Commands |
||||||
|
{ |
||||||
|
[ExportBookmarkActionEntry(Icon = "images/Breakpoint.png", Category="Debugger")] |
||||||
|
public class BreakpointCommand : IBookmarkActionEntry |
||||||
|
{ |
||||||
|
public bool IsEnabled() |
||||||
|
{ |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
public void Execute(int line) |
||||||
|
{ |
||||||
|
if (DebugData.CodeMappings != null && DebugData.CodeMappings.Count > 0) { |
||||||
|
|
||||||
|
// check if the codemappings exists for this line
|
||||||
|
var storage = DebugData.CodeMappings; |
||||||
|
int token = 0; |
||||||
|
foreach (var key in storage.Keys) { |
||||||
|
var instruction = storage[key].GetInstructionByLineNumber(line, out token); |
||||||
|
|
||||||
|
if (instruction == null) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
|
||||||
|
// no bookmark on the line: create a new breakpoint
|
||||||
|
DebuggerService.ToggleBreakpointAt( |
||||||
|
DebugData.DecompiledMemberReferences[key], |
||||||
|
line, |
||||||
|
instruction.ILInstructionOffset, |
||||||
|
DebugData.Language); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
if (token == 0) { |
||||||
|
MessageBox.Show(string.Format("Missing code mappings at line {0}.", line), |
||||||
|
"Code mappings", MessageBoxButton.OK, MessageBoxImage.Information); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.AvalonEdit |
||||||
|
{ |
||||||
|
public interface ITextEditorListener : IWeakEventListener |
||||||
|
{ |
||||||
|
new bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e); |
||||||
|
void ClosePopup(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,123 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Windows.Media; |
||||||
|
|
||||||
|
using ICSharpCode.ILSpy.Bookmarks; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.AvalonEdit |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Represents a text marker.
|
||||||
|
/// </summary>
|
||||||
|
public interface ITextMarker |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Gets the start offset of the marked text region.
|
||||||
|
/// </summary>
|
||||||
|
int StartOffset { get; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the end offset of the marked text region.
|
||||||
|
/// </summary>
|
||||||
|
int EndOffset { get; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the length of the marked region.
|
||||||
|
/// </summary>
|
||||||
|
int Length { get; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the text marker.
|
||||||
|
/// </summary>
|
||||||
|
void Delete(); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether the text marker was deleted.
|
||||||
|
/// </summary>
|
||||||
|
bool IsDeleted { get; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Event that occurs when the text marker is deleted.
|
||||||
|
/// </summary>
|
||||||
|
event EventHandler Deleted; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/Sets the background color.
|
||||||
|
/// </summary>
|
||||||
|
Color? BackgroundColor { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/Sets the foreground color.
|
||||||
|
/// </summary>
|
||||||
|
Color? ForegroundColor { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/Sets the type of the marker. Use TextMarkerType.None for normal markers.
|
||||||
|
/// </summary>
|
||||||
|
TextMarkerType MarkerType { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/Sets the color of the marker.
|
||||||
|
/// </summary>
|
||||||
|
Color MarkerColor { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/Sets an object with additional data for this text marker.
|
||||||
|
/// </summary>
|
||||||
|
object Tag { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets/Sets an object that will be displayed as tooltip in the text editor.
|
||||||
|
/// </summary>
|
||||||
|
object ToolTip { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets if the marker is visible or not.
|
||||||
|
/// </summary>
|
||||||
|
Predicate<object> IsVisible { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the bookmark.
|
||||||
|
/// </summary>
|
||||||
|
IBookmark Bookmark { get; set; } |
||||||
|
} |
||||||
|
|
||||||
|
public enum TextMarkerType |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Use no marker
|
||||||
|
/// </summary>
|
||||||
|
None, |
||||||
|
/// <summary>
|
||||||
|
/// Use squiggly underline marker
|
||||||
|
/// </summary>
|
||||||
|
SquigglyUnderline |
||||||
|
} |
||||||
|
|
||||||
|
public interface ITextMarkerService |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Creates a new text marker. The text marker will be invisible at first,
|
||||||
|
/// you need to set one of the Color properties to make it visible.
|
||||||
|
/// </summary>
|
||||||
|
ITextMarker Create(int startOffset, int length); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of text markers.
|
||||||
|
/// </summary>
|
||||||
|
IEnumerable<ITextMarker> TextMarkers { get; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes the specified text marker.
|
||||||
|
/// </summary>
|
||||||
|
void Remove(ITextMarker marker); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all text markers that match the condition.
|
||||||
|
/// </summary>
|
||||||
|
void RemoveAll(Predicate<ITextMarker> predicate); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.AvalonEdit |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Content of text editor tooltip (used as <see cref="ToolTipRequestEventArgs.ContentToShow"/>),
|
||||||
|
/// specifying whether it should be displayed in a WPF Popup.
|
||||||
|
/// </summary>
|
||||||
|
public interface ITooltip |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// If true, this ITooltip will be displayed in a WPF Popup.
|
||||||
|
/// Otherwise it will be displayed in a WPF Tooltip.
|
||||||
|
/// WPF Popups are (unlike WPF Tooltips) focusable.
|
||||||
|
/// </summary>
|
||||||
|
bool ShowAsPopup { get; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Closes this tooltip.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mouseClick">True if close request is raised
|
||||||
|
/// because of mouse click on some SharpDevelop GUI element.</param>
|
||||||
|
/// <returns>True if Close succeeded (that is, can close). False otherwise.</returns>
|
||||||
|
bool Close(bool mouseClick); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when this tooltip decides to close.
|
||||||
|
/// </summary>
|
||||||
|
event RoutedEventHandler Closed; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,83 @@ |
|||||||
|
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
// software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||||
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
// substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Collections.ObjectModel; |
||||||
|
using System.Collections.Specialized; |
||||||
|
using System.Linq; |
||||||
|
|
||||||
|
using ICSharpCode.ILSpy.Bookmarks; |
||||||
|
using ICSharpCode.NRefactory.CSharp; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.AvalonEdit |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Stores the entries in the icon bar margin. Multiple icon bar margins
|
||||||
|
/// can use the same manager if split view is used.
|
||||||
|
/// </summary>
|
||||||
|
public class IconBarManager : IBookmarkMargin |
||||||
|
{ |
||||||
|
ObservableCollection<IBookmark> bookmarks = new ObservableCollection<IBookmark>(); |
||||||
|
|
||||||
|
public IconBarManager() |
||||||
|
{ |
||||||
|
bookmarks.CollectionChanged += bookmarks_CollectionChanged; |
||||||
|
} |
||||||
|
|
||||||
|
public IList<IBookmark> Bookmarks { |
||||||
|
get { return bookmarks; } |
||||||
|
} |
||||||
|
|
||||||
|
void bookmarks_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
||||||
|
{ |
||||||
|
Redraw(); |
||||||
|
} |
||||||
|
|
||||||
|
public void Redraw() |
||||||
|
{ |
||||||
|
if (RedrawRequested != null) |
||||||
|
RedrawRequested(this, EventArgs.Empty); |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler RedrawRequested; |
||||||
|
|
||||||
|
internal void UpdateClassMemberBookmarks(IEnumerable<AstNode> nodes) |
||||||
|
{ |
||||||
|
this.bookmarks.Clear(); |
||||||
|
|
||||||
|
if (nodes == null || nodes.Count() == 0) |
||||||
|
return; |
||||||
|
|
||||||
|
foreach (var n in nodes) { |
||||||
|
switch (n.NodeType) { |
||||||
|
case NodeType.TypeDeclaration: |
||||||
|
case NodeType.TypeReference: |
||||||
|
this.bookmarks.Add(new TypeBookmark(n)); |
||||||
|
break; |
||||||
|
case NodeType.Member: |
||||||
|
this.bookmarks.Add(new MemberBookmark(n)); |
||||||
|
break; |
||||||
|
default: |
||||||
|
// do nothing
|
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,318 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Media; |
||||||
|
|
||||||
|
using ICSharpCode.AvalonEdit.Editing; |
||||||
|
using ICSharpCode.AvalonEdit.Rendering; |
||||||
|
using ICSharpCode.AvalonEdit.Utils; |
||||||
|
using ICSharpCode.Decompiler; |
||||||
|
using ICSharpCode.ILSpy.Bookmarks; |
||||||
|
using ICSharpCode.ILSpy.Debugger; |
||||||
|
using ICSharpCode.ILSpy.Debugger.Bookmarks; |
||||||
|
using ICSharpCode.NRefactory.CSharp; |
||||||
|
using Mono.Cecil; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.AvalonEdit |
||||||
|
{ |
||||||
|
public class IconBarMargin : AbstractMargin, IDisposable |
||||||
|
{ |
||||||
|
readonly IconBarManager manager; |
||||||
|
|
||||||
|
public IconBarMargin(IconBarManager manager) |
||||||
|
{ |
||||||
|
BookmarkManager.Added += delegate { InvalidateVisual(); }; |
||||||
|
BookmarkManager.Removed += delegate { InvalidateVisual(); }; |
||||||
|
|
||||||
|
this.manager = manager; |
||||||
|
} |
||||||
|
|
||||||
|
public IconBarManager Manager { |
||||||
|
get { return manager; } |
||||||
|
} |
||||||
|
|
||||||
|
public IList<MemberReference> DecompiledMembers { get; set; } |
||||||
|
|
||||||
|
public virtual void Dispose() |
||||||
|
{ |
||||||
|
this.TextView = null; // detach from TextView (will also detach from manager)
|
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) |
||||||
|
{ |
||||||
|
// accept clicks even when clicking on the background
|
||||||
|
return new PointHitTestResult(this, hitTestParameters.HitPoint); |
||||||
|
} |
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
protected override Size MeasureOverride(Size availableSize) |
||||||
|
{ |
||||||
|
return new Size(18, 0); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnRender(DrawingContext drawingContext) |
||||||
|
{ |
||||||
|
Size renderSize = this.RenderSize; |
||||||
|
drawingContext.DrawRectangle(SystemColors.ControlBrush, null, |
||||||
|
new Rect(0, 0, renderSize.Width, renderSize.Height)); |
||||||
|
drawingContext.DrawLine(new Pen(SystemColors.ControlDarkBrush, 1), |
||||||
|
new Point(renderSize.Width - 0.5, 0), |
||||||
|
new Point(renderSize.Width - 0.5, renderSize.Height)); |
||||||
|
|
||||||
|
ICSharpCode.AvalonEdit.Rendering.TextView textView = this.TextView; |
||||||
|
if (textView != null && textView.VisualLinesValid) { |
||||||
|
// create a dictionary line number => first bookmark
|
||||||
|
Dictionary<int, IBookmark> bookmarkDict = new Dictionary<int, IBookmark>(); |
||||||
|
foreach (var bm in BookmarkManager.Bookmarks) { |
||||||
|
if (DebugData.DecompiledMemberReferences == null || DebugData.DecompiledMemberReferences.Count == 0 || |
||||||
|
!DebugData.DecompiledMemberReferences.ContainsKey(bm.MemberReference.MetadataToken.ToInt32())) |
||||||
|
continue; |
||||||
|
|
||||||
|
int line = bm.LineNumber; |
||||||
|
IBookmark existingBookmark; |
||||||
|
if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder) |
||||||
|
bookmarkDict[line] = bm; |
||||||
|
} |
||||||
|
|
||||||
|
foreach (var bm in manager.Bookmarks) { |
||||||
|
int line = bm.LineNumber; |
||||||
|
IBookmark existingBookmark; |
||||||
|
if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder) |
||||||
|
bookmarkDict[line] = bm; |
||||||
|
} |
||||||
|
|
||||||
|
Size pixelSize = PixelSnapHelpers.GetPixelSize(this); |
||||||
|
foreach (VisualLine line in textView.VisualLines) { |
||||||
|
int lineNumber = line.FirstDocumentLine.LineNumber; |
||||||
|
IBookmark bm; |
||||||
|
if (bookmarkDict.TryGetValue(lineNumber, out bm)) { |
||||||
|
Rect rect = new Rect(0, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16); |
||||||
|
if (dragDropBookmark == bm && dragStarted) |
||||||
|
drawingContext.PushOpacity(0.5); |
||||||
|
drawingContext.DrawImage(bm.Image, rect); |
||||||
|
if (dragDropBookmark == bm && dragStarted) |
||||||
|
drawingContext.Pop(); |
||||||
|
} |
||||||
|
} |
||||||
|
if (dragDropBookmark != null && dragStarted) { |
||||||
|
Rect rect = new Rect(0, PixelSnapHelpers.Round(dragDropCurrentPoint - 8, pixelSize.Height), 16, 16); |
||||||
|
drawingContext.DrawImage(dragDropBookmark.Image, rect); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
IBookmark dragDropBookmark; // bookmark being dragged (!=null if drag'n'drop is active)
|
||||||
|
double dragDropStartPoint; |
||||||
|
double dragDropCurrentPoint; |
||||||
|
bool dragStarted; // whether drag'n'drop operation has started (mouse was moved minimum distance)
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
base.OnMouseDown(e); |
||||||
|
int line = GetLineFromMousePosition(e); |
||||||
|
if (!e.Handled && line > 0) { |
||||||
|
IBookmark bm = GetBookmarkFromLine(line); |
||||||
|
if (bm != null) { |
||||||
|
bm.MouseDown(e); |
||||||
|
if (!e.Handled) { |
||||||
|
if (e.ChangedButton == MouseButton.Left && bm.CanDragDrop && CaptureMouse()) { |
||||||
|
StartDragDrop(bm, e); |
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
// don't allow selecting text through the IconBarMargin
|
||||||
|
if (e.ChangedButton == MouseButton.Left) |
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
|
||||||
|
IBookmark GetBookmarkFromLine(int line) |
||||||
|
{ |
||||||
|
BookmarkBase result = null; |
||||||
|
foreach (BookmarkBase bm in BookmarkManager.Bookmarks) { |
||||||
|
if (bm.LineNumber == line && |
||||||
|
this.DecompiledMembers != null && this.DecompiledMembers.Contains(bm.MemberReference)) { |
||||||
|
if (result == null || bm.ZOrder > result.ZOrder) |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return manager.Bookmarks.FirstOrDefault(b => b.LineNumber == line); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnLostMouseCapture(MouseEventArgs e) |
||||||
|
{ |
||||||
|
CancelDragDrop(); |
||||||
|
base.OnLostMouseCapture(e); |
||||||
|
} |
||||||
|
|
||||||
|
void StartDragDrop(IBookmark bm, MouseEventArgs e) |
||||||
|
{ |
||||||
|
dragDropBookmark = bm; |
||||||
|
dragDropStartPoint = dragDropCurrentPoint = e.GetPosition(this).Y; |
||||||
|
if (TextView != null) { |
||||||
|
TextArea area = TextView.Services.GetService(typeof(TextArea)) as TextArea; |
||||||
|
if (area != null) |
||||||
|
area.PreviewKeyDown += TextArea_PreviewKeyDown; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void CancelDragDrop() |
||||||
|
{ |
||||||
|
if (dragDropBookmark != null) { |
||||||
|
dragDropBookmark = null; |
||||||
|
dragStarted = false; |
||||||
|
if (TextView != null) { |
||||||
|
TextArea area = TextView.Services.GetService(typeof(TextArea)) as TextArea; |
||||||
|
if (area != null) |
||||||
|
area.PreviewKeyDown -= TextArea_PreviewKeyDown; |
||||||
|
} |
||||||
|
ReleaseMouseCapture(); |
||||||
|
InvalidateVisual(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void TextArea_PreviewKeyDown(object sender, KeyEventArgs e) |
||||||
|
{ |
||||||
|
// any key press cancels drag'n'drop
|
||||||
|
CancelDragDrop(); |
||||||
|
if (e.Key == Key.Escape) |
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
|
||||||
|
internal int GetLineFromMousePosition(MouseEventArgs e) |
||||||
|
{ |
||||||
|
ICSharpCode.AvalonEdit.Rendering.TextView textView = this.TextView; |
||||||
|
if (textView == null) |
||||||
|
return 0; |
||||||
|
VisualLine vl = textView.GetVisualLineFromVisualTop(e.GetPosition(textView).Y + textView.ScrollOffset.Y); |
||||||
|
if (vl == null) |
||||||
|
return 0; |
||||||
|
return vl.FirstDocumentLine.LineNumber; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e) |
||||||
|
{ |
||||||
|
base.OnMouseMove(e); |
||||||
|
if (dragDropBookmark != null) { |
||||||
|
dragDropCurrentPoint = e.GetPosition(this).Y; |
||||||
|
if (Math.Abs(dragDropCurrentPoint - dragDropStartPoint) > SystemParameters.MinimumVerticalDragDistance) |
||||||
|
dragStarted = true; |
||||||
|
InvalidateVisual(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override void OnMouseUp(MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
base.OnMouseUp(e); |
||||||
|
int line = GetLineFromMousePosition(e); |
||||||
|
if (!e.Handled && dragDropBookmark != null) { |
||||||
|
if (dragStarted) { |
||||||
|
if (line != 0) |
||||||
|
dragDropBookmark.Drop(line); |
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
CancelDragDrop(); |
||||||
|
} |
||||||
|
if (!e.Handled && line != 0) { |
||||||
|
var bm = GetBookmarkFromLine(line); |
||||||
|
if (bm != null) { |
||||||
|
bm.MouseUp(e); |
||||||
|
|
||||||
|
if (bm is BookmarkBase) { |
||||||
|
if ((bm as BookmarkBase).CanToggle) { |
||||||
|
BookmarkManager.RemoveMark(bm as BookmarkBase); |
||||||
|
InvalidateVisual(); |
||||||
|
} |
||||||
|
} |
||||||
|
if (e.Handled) |
||||||
|
return; |
||||||
|
} |
||||||
|
if (e.ChangedButton == MouseButton.Left) { |
||||||
|
// see IBookmarkActionEntry interface
|
||||||
|
} |
||||||
|
InvalidateVisual(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void SyncBookmarks() |
||||||
|
{ |
||||||
|
var storage = DebugData.CodeMappings; |
||||||
|
if (storage == null || storage.Count == 0) |
||||||
|
return; |
||||||
|
|
||||||
|
//remove existing bookmarks and create new ones
|
||||||
|
List<BreakpointBookmark> newBookmarks = new List<BreakpointBookmark>(); |
||||||
|
for (int i = BookmarkManager.Bookmarks.Count - 1; i >= 0; --i) { |
||||||
|
var breakpoint = BookmarkManager.Bookmarks[i] as BreakpointBookmark; |
||||||
|
if (breakpoint == null) |
||||||
|
continue; |
||||||
|
|
||||||
|
var key = breakpoint.MemberReference.MetadataToken.ToInt32(); |
||||||
|
if (!storage.ContainsKey(key)) |
||||||
|
continue; |
||||||
|
|
||||||
|
var member = DebugData.DecompiledMemberReferences[key]; |
||||||
|
|
||||||
|
bool isMatch; |
||||||
|
SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset( |
||||||
|
member.MetadataToken.ToInt32(), breakpoint.ILRange.From, out isMatch); |
||||||
|
|
||||||
|
if (map != null) { |
||||||
|
newBookmarks.Add(new BreakpointBookmark( |
||||||
|
member, new AstLocation(map.SourceCodeLine, 0), |
||||||
|
map.ILInstructionOffset, BreakpointAction.Break, DebugData.Language)); |
||||||
|
|
||||||
|
BookmarkManager.RemoveMark(breakpoint); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
newBookmarks.ForEach(m => BookmarkManager.AddMark(m)); |
||||||
|
|
||||||
|
SyncCurrentLineBookmark(); |
||||||
|
} |
||||||
|
|
||||||
|
void SyncCurrentLineBookmark() |
||||||
|
{ |
||||||
|
// checks
|
||||||
|
if (CurrentLineBookmark.Instance == null) |
||||||
|
return; |
||||||
|
|
||||||
|
var oldMappings = DebugData.OldCodeMappings; |
||||||
|
var newMappings = DebugData.CodeMappings; |
||||||
|
|
||||||
|
if (oldMappings == null || newMappings == null) |
||||||
|
return; |
||||||
|
|
||||||
|
// 1. Save it's data
|
||||||
|
int line = CurrentLineBookmark.Instance.LineNumber; |
||||||
|
var markerType = CurrentLineBookmark.Instance.MemberReference; |
||||||
|
|
||||||
|
if (!oldMappings.ContainsKey(markerType.MetadataToken.ToInt32()) || !newMappings.ContainsKey(markerType.MetadataToken.ToInt32())) |
||||||
|
return; |
||||||
|
|
||||||
|
// 2. Remove it
|
||||||
|
CurrentLineBookmark.Remove(); |
||||||
|
|
||||||
|
// 3. map the marker line
|
||||||
|
int token; |
||||||
|
var instruction = oldMappings[markerType.MetadataToken.ToInt32()].GetInstructionByLineNumber(line, out token); |
||||||
|
if (instruction == null) |
||||||
|
return; |
||||||
|
|
||||||
|
MemberReference memberReference; |
||||||
|
int newline; |
||||||
|
if (newMappings[markerType.MetadataToken.ToInt32()].GetInstructionByTokenAndOffset(token, instruction.ILInstructionOffset.From, out memberReference, out newline)) { |
||||||
|
// 4. create breakpoint for new languages
|
||||||
|
CurrentLineBookmark.SetPosition(memberReference, newline, 0, newline, 0); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,190 @@ |
|||||||
|
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
// software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||||
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
// substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel.Composition; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Media; |
||||||
|
|
||||||
|
using ICSharpCode.ILSpy.Bookmarks; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.AvalonEdit |
||||||
|
{ |
||||||
|
#region Context menu extensibility
|
||||||
|
public interface IBookmarkContextMenuEntry |
||||||
|
{ |
||||||
|
bool IsVisible(IBookmark[] bookmarks); |
||||||
|
bool IsEnabled(IBookmark[] bookmarks); |
||||||
|
void Execute(IBookmark[] bookmarks); |
||||||
|
} |
||||||
|
|
||||||
|
public interface IBookmarkContextMenuEntryMetadata |
||||||
|
{ |
||||||
|
string Icon { get; } |
||||||
|
string Header { get; } |
||||||
|
string Category { get; } |
||||||
|
|
||||||
|
double Order { get; } |
||||||
|
} |
||||||
|
|
||||||
|
[MetadataAttribute] |
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] |
||||||
|
public class ExportBookmarkContextMenuEntryAttribute : ExportAttribute, IBookmarkContextMenuEntryMetadata |
||||||
|
{ |
||||||
|
public ExportBookmarkContextMenuEntryAttribute() |
||||||
|
: base(typeof(IBookmarkContextMenuEntry)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public string Icon { get; set; } |
||||||
|
public string Header { get; set; } |
||||||
|
public string Category { get; set; } |
||||||
|
public double Order { get; set; } |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Actions (simple clicks) - this will be used for creating bookmarks (e.g. Breakpoint bookmarks)
|
||||||
|
|
||||||
|
public interface IBookmarkActionEntry |
||||||
|
{ |
||||||
|
bool IsEnabled(); |
||||||
|
void Execute(int line); |
||||||
|
} |
||||||
|
|
||||||
|
public interface IBookmarkActionMetadata |
||||||
|
{ |
||||||
|
string Category { get; } |
||||||
|
|
||||||
|
double Order { get; } |
||||||
|
} |
||||||
|
|
||||||
|
[MetadataAttribute] |
||||||
|
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] |
||||||
|
public class ExportBookmarkActionEntryAttribute : ExportAttribute, IBookmarkActionMetadata |
||||||
|
{ |
||||||
|
public ExportBookmarkActionEntryAttribute() |
||||||
|
: base(typeof(IBookmarkActionEntry)) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public string Icon { get; set; } |
||||||
|
public string Header { get; set; } |
||||||
|
public string Category { get; set; } |
||||||
|
public double Order { get; set; } |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
internal class IconMarginActionsProvider |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Enables extensible context menu support for the specified icon margin.
|
||||||
|
/// </summary>
|
||||||
|
public static void Add(IconBarMargin margin) |
||||||
|
{ |
||||||
|
var provider = new IconMarginActionsProvider(margin); |
||||||
|
margin.MouseUp += provider.HandleMouseEvent; |
||||||
|
margin.ContextMenu = new ContextMenu(); |
||||||
|
} |
||||||
|
|
||||||
|
readonly IconBarMargin margin; |
||||||
|
|
||||||
|
[ImportMany(typeof(IBookmarkContextMenuEntry))] |
||||||
|
Lazy<IBookmarkContextMenuEntry, IBookmarkContextMenuEntryMetadata>[] contextEntries = null; |
||||||
|
|
||||||
|
[ImportMany(typeof(IBookmarkActionEntry))] |
||||||
|
Lazy<IBookmarkActionEntry, IBookmarkActionMetadata>[] actionEntries = null; |
||||||
|
|
||||||
|
private IconMarginActionsProvider(IconBarMargin margin) |
||||||
|
{ |
||||||
|
this.margin = margin; |
||||||
|
App.CompositionContainer.ComposeParts(this); |
||||||
|
} |
||||||
|
|
||||||
|
void HandleMouseEvent(object sender, MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
int line = margin.GetLineFromMousePosition(e); |
||||||
|
|
||||||
|
if (e.ChangedButton == MouseButton.Left) { |
||||||
|
foreach (var category in actionEntries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { |
||||||
|
foreach (var entryPair in category) { |
||||||
|
IBookmarkActionEntry entry = entryPair.Value; |
||||||
|
|
||||||
|
if (entryPair.Value.IsEnabled()) { |
||||||
|
entry.Execute(line); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// context menu entries
|
||||||
|
var bookmarks = margin.Manager.Bookmarks.ToArray(); |
||||||
|
if (bookmarks.Length == 0) { |
||||||
|
// don't show the menu
|
||||||
|
e.Handled = true; |
||||||
|
this.margin.ContextMenu = null; |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (e.ChangedButton == MouseButton.Right) { |
||||||
|
// check if we are on a Member
|
||||||
|
var bookmark = bookmarks.FirstOrDefault(b => b.LineNumber == line); |
||||||
|
if (bookmark == null) { |
||||||
|
// don't show the menu
|
||||||
|
e.Handled = true; |
||||||
|
this.margin.ContextMenu = null; |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
var marks = new[] { bookmark }; |
||||||
|
ContextMenu menu = new ContextMenu(); |
||||||
|
foreach (var category in contextEntries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { |
||||||
|
if (menu.Items.Count > 0) { |
||||||
|
menu.Items.Add(new Separator()); |
||||||
|
} |
||||||
|
foreach (var entryPair in category) { |
||||||
|
IBookmarkContextMenuEntry entry = entryPair.Value; |
||||||
|
if (entry.IsVisible(marks)) { |
||||||
|
MenuItem menuItem = new MenuItem(); |
||||||
|
menuItem.Header = entryPair.Metadata.Header; |
||||||
|
if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) { |
||||||
|
menuItem.Icon = new Image { |
||||||
|
Width = 16, |
||||||
|
Height = 16, |
||||||
|
Source = Images.LoadImage(entry, entryPair.Metadata.Icon) |
||||||
|
}; |
||||||
|
} |
||||||
|
if (entryPair.Value.IsEnabled(marks)) { |
||||||
|
menuItem.Click += delegate { entry.Execute(marks); }; |
||||||
|
} else |
||||||
|
menuItem.IsEnabled = false; |
||||||
|
menu.Items.Add(menuItem); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
if (menu.Items.Count > 0) |
||||||
|
margin.ContextMenu = menu; |
||||||
|
else |
||||||
|
// hide the context menu.
|
||||||
|
e.Handled = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,319 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.ComponentModel.Composition; |
||||||
|
using System.Linq; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Media; |
||||||
|
using System.Windows.Threading; |
||||||
|
|
||||||
|
using ICSharpCode.AvalonEdit; |
||||||
|
using ICSharpCode.AvalonEdit.Document; |
||||||
|
using ICSharpCode.AvalonEdit.Rendering; |
||||||
|
using ICSharpCode.ILSpy.Bookmarks; |
||||||
|
using ICSharpCode.ILSpy.Debugger.Bookmarks; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.AvalonEdit |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Handles the text markers for a code editor.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService |
||||||
|
{ |
||||||
|
TextEditor codeEditor; |
||||||
|
|
||||||
|
TextSegmentCollection<TextMarker> markers = new TextSegmentCollection<TextMarker>(); |
||||||
|
|
||||||
|
public TextMarkerService() |
||||||
|
{ |
||||||
|
BookmarkManager.Added += new BookmarkEventHandler(BookmarkManager_Added); |
||||||
|
BookmarkManager.Removed += new BookmarkEventHandler(BookmarkManager_Removed); |
||||||
|
} |
||||||
|
|
||||||
|
public TextEditor CodeEditor { |
||||||
|
get { return codeEditor; } |
||||||
|
set { codeEditor = value; } |
||||||
|
} |
||||||
|
|
||||||
|
void BookmarkManager_Removed(object sender, BookmarkEventArgs e) |
||||||
|
{ |
||||||
|
if (e.Bookmark is BreakpointBookmark) { |
||||||
|
var bm = (MarkerBookmark)e.Bookmark; |
||||||
|
Remove(bm.Marker); |
||||||
|
} |
||||||
|
|
||||||
|
if (e.Bookmark is CurrentLineBookmark) { |
||||||
|
RemoveAll(m => m.Bookmark is CurrentLineBookmark); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void BookmarkManager_Added(object sender, BookmarkEventArgs e) |
||||||
|
{ |
||||||
|
if (e.Bookmark is MarkerBookmark) { |
||||||
|
var bm = (MarkerBookmark)e.Bookmark; |
||||||
|
// add bookmark for the current type
|
||||||
|
if (bm.LineNumber < codeEditor.Document.LineCount) { |
||||||
|
DocumentLine line = codeEditor.Document.GetLineByNumber(bm.LineNumber); |
||||||
|
bm.CreateMarker(this, line.Offset, line.Length); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#region ITextMarkerService
|
||||||
|
public ITextMarker Create(int startOffset, int length) |
||||||
|
{ |
||||||
|
int textLength = codeEditor.TextArea.TextView.Document.TextLength; |
||||||
|
if (startOffset < 0 || startOffset > textLength) |
||||||
|
throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be between 0 and " + textLength); |
||||||
|
if (length < 0 || startOffset + length > textLength) |
||||||
|
throw new ArgumentOutOfRangeException("length", length, "length must not be negative and startOffset+length must not be after the end of the document"); |
||||||
|
|
||||||
|
TextMarker m = new TextMarker(this, startOffset, length); |
||||||
|
markers.Add(m); |
||||||
|
// no need to mark segment for redraw: the text marker is invisible until a property is set
|
||||||
|
return m; |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<ITextMarker> GetMarkersAtOffset(int offset) |
||||||
|
{ |
||||||
|
return markers.FindSegmentsContaining(offset); |
||||||
|
} |
||||||
|
|
||||||
|
public IEnumerable<ITextMarker> TextMarkers { |
||||||
|
get { return markers; } |
||||||
|
} |
||||||
|
|
||||||
|
public void RemoveAll(Predicate<ITextMarker> predicate) |
||||||
|
{ |
||||||
|
if (predicate == null) |
||||||
|
throw new ArgumentNullException("predicate"); |
||||||
|
foreach (TextMarker m in markers.ToArray()) { |
||||||
|
if (predicate(m)) |
||||||
|
Remove(m); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Remove(ITextMarker marker) |
||||||
|
{ |
||||||
|
if (marker == null) |
||||||
|
return; |
||||||
|
|
||||||
|
TextMarker m = marker as TextMarker; |
||||||
|
if (markers.Remove(m)) { |
||||||
|
Redraw(m); |
||||||
|
m.OnDeleted(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Redraws the specified text segment.
|
||||||
|
/// </summary>
|
||||||
|
public void Redraw(ISegment segment) |
||||||
|
{ |
||||||
|
codeEditor.TextArea.TextView.Redraw(segment, DispatcherPriority.Normal); |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region DocumentColorizingTransformer
|
||||||
|
protected override void ColorizeLine(DocumentLine line) |
||||||
|
{ |
||||||
|
if (markers == null) |
||||||
|
return; |
||||||
|
int lineStart = line.Offset; |
||||||
|
int lineEnd = lineStart + line.Length; |
||||||
|
foreach (TextMarker marker in markers.FindOverlappingSegments(lineStart, line.Length).Reverse()) { |
||||||
|
if (!marker.IsVisible(marker.Bookmark)) |
||||||
|
continue; |
||||||
|
|
||||||
|
Brush foregroundBrush = null; |
||||||
|
if (marker.ForegroundColor != null) { |
||||||
|
foregroundBrush = new SolidColorBrush(marker.ForegroundColor.Value); |
||||||
|
foregroundBrush.Freeze(); |
||||||
|
} |
||||||
|
ChangeLinePart( |
||||||
|
Math.Max(marker.StartOffset, lineStart), |
||||||
|
Math.Min(marker.EndOffset, lineEnd), |
||||||
|
element => { |
||||||
|
if (foregroundBrush != null) { |
||||||
|
element.TextRunProperties.SetForegroundBrush(foregroundBrush); |
||||||
|
} |
||||||
|
} |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IBackgroundRenderer
|
||||||
|
public KnownLayer Layer { |
||||||
|
get { |
||||||
|
// draw behind selection
|
||||||
|
return KnownLayer.Selection; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void Draw(ICSharpCode.AvalonEdit.Rendering.TextView textView, DrawingContext drawingContext) |
||||||
|
{ |
||||||
|
if (textView == null) |
||||||
|
throw new ArgumentNullException("textView"); |
||||||
|
if (drawingContext == null) |
||||||
|
throw new ArgumentNullException("drawingContext"); |
||||||
|
if (markers == null || !textView.VisualLinesValid) |
||||||
|
return; |
||||||
|
var visualLines = textView.VisualLines; |
||||||
|
if (visualLines.Count == 0) |
||||||
|
return; |
||||||
|
int viewStart = visualLines.First().FirstDocumentLine.Offset; |
||||||
|
int viewEnd = visualLines.Last().LastDocumentLine.Offset + visualLines.Last().LastDocumentLine.Length; |
||||||
|
foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart).Reverse()) { |
||||||
|
if (!marker.IsVisible(marker.Bookmark)) |
||||||
|
continue; |
||||||
|
|
||||||
|
if (marker.BackgroundColor != null) { |
||||||
|
BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder(); |
||||||
|
geoBuilder.AlignToWholePixels = true; |
||||||
|
geoBuilder.CornerRadius = 3; |
||||||
|
geoBuilder.AddSegment(textView, marker); |
||||||
|
Geometry geometry = geoBuilder.CreateGeometry(); |
||||||
|
if (geometry != null) { |
||||||
|
Color color = marker.BackgroundColor.Value; |
||||||
|
SolidColorBrush brush = new SolidColorBrush(color); |
||||||
|
brush.Freeze(); |
||||||
|
drawingContext.DrawGeometry(brush, null, geometry); |
||||||
|
} |
||||||
|
} |
||||||
|
if (marker.MarkerType != TextMarkerType.None) { |
||||||
|
foreach (Rect r in BackgroundGeometryBuilder.GetRectsForSegment(textView, marker)) { |
||||||
|
Point startPoint = r.BottomLeft; |
||||||
|
Point endPoint = r.BottomRight; |
||||||
|
|
||||||
|
Pen usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1); |
||||||
|
usedPen.Freeze(); |
||||||
|
switch (marker.MarkerType) { |
||||||
|
case TextMarkerType.SquigglyUnderline: |
||||||
|
double offset = 2.5; |
||||||
|
|
||||||
|
int count = Math.Max((int)((endPoint.X - startPoint.X) / offset) + 1, 4); |
||||||
|
|
||||||
|
StreamGeometry geometry = new StreamGeometry(); |
||||||
|
|
||||||
|
using (StreamGeometryContext ctx = geometry.Open()) { |
||||||
|
ctx.BeginFigure(startPoint, false, false); |
||||||
|
ctx.PolyLineTo(CreatePoints(startPoint, endPoint, offset, count).ToArray(), true, false); |
||||||
|
} |
||||||
|
|
||||||
|
geometry.Freeze(); |
||||||
|
|
||||||
|
drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
IEnumerable<Point> CreatePoints(Point start, Point end, double offset, int count) |
||||||
|
{ |
||||||
|
for (int i = 0; i < count; i++) |
||||||
|
yield return new Point(start.X + i * offset, start.Y - ((i + 1) % 2 == 0 ? offset : 0)); |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
} |
||||||
|
|
||||||
|
sealed class TextMarker : TextSegment, ITextMarker |
||||||
|
{ |
||||||
|
readonly TextMarkerService service; |
||||||
|
|
||||||
|
public TextMarker(TextMarkerService service, int startOffset, int length) |
||||||
|
{ |
||||||
|
if (service == null) |
||||||
|
throw new ArgumentNullException("service"); |
||||||
|
this.service = service; |
||||||
|
this.StartOffset = startOffset; |
||||||
|
this.Length = length; |
||||||
|
this.markerType = TextMarkerType.None; |
||||||
|
} |
||||||
|
|
||||||
|
public event EventHandler Deleted; |
||||||
|
|
||||||
|
public bool IsDeleted { |
||||||
|
get { return !this.IsConnectedToCollection; } |
||||||
|
} |
||||||
|
|
||||||
|
public void Delete() |
||||||
|
{ |
||||||
|
service.Remove(this); |
||||||
|
} |
||||||
|
|
||||||
|
internal void OnDeleted() |
||||||
|
{ |
||||||
|
if (Deleted != null) |
||||||
|
Deleted(this, EventArgs.Empty); |
||||||
|
} |
||||||
|
|
||||||
|
void Redraw() |
||||||
|
{ |
||||||
|
service.Redraw(this); |
||||||
|
} |
||||||
|
|
||||||
|
Color? backgroundColor; |
||||||
|
|
||||||
|
public Color? BackgroundColor { |
||||||
|
get { return backgroundColor; } |
||||||
|
set { |
||||||
|
if (backgroundColor != value) { |
||||||
|
backgroundColor = value; |
||||||
|
Redraw(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Color? foregroundColor; |
||||||
|
|
||||||
|
public Color? ForegroundColor { |
||||||
|
get { return foregroundColor; } |
||||||
|
set { |
||||||
|
if (foregroundColor != value) { |
||||||
|
foregroundColor = value; |
||||||
|
Redraw(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public object Tag { get; set; } |
||||||
|
|
||||||
|
TextMarkerType markerType; |
||||||
|
|
||||||
|
public TextMarkerType MarkerType { |
||||||
|
get { return markerType; } |
||||||
|
set { |
||||||
|
if (markerType != value) { |
||||||
|
markerType = value; |
||||||
|
Redraw(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Color markerColor; |
||||||
|
|
||||||
|
public Color MarkerColor { |
||||||
|
get { return markerColor; } |
||||||
|
set { |
||||||
|
if (markerColor != value) { |
||||||
|
markerColor = value; |
||||||
|
Redraw(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
/// <inheritdoc/>
|
||||||
|
public object ToolTip { get; set; } |
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public Predicate<object> IsVisible { get; set; } |
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public IBookmark Bookmark { get; set; } |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,157 @@ |
|||||||
|
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||||
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Input; |
||||||
|
using System.Windows.Media; |
||||||
|
|
||||||
|
using ICSharpCode.NRefactory.CSharp; |
||||||
|
using ICSharpCode.NRefactory.TypeSystem; |
||||||
|
using Mono.Cecil; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.Bookmarks |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Bookmark used to give additional operations for class members.
|
||||||
|
/// Does not derive from SDBookmark because it is not stored in the central BookmarkManager,
|
||||||
|
/// but only in the document's BookmarkManager.
|
||||||
|
/// </summary>
|
||||||
|
public class MemberBookmark : IBookmark |
||||||
|
{ |
||||||
|
AstNode node; |
||||||
|
|
||||||
|
public AstNode Node { |
||||||
|
get { |
||||||
|
return node; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public MemberBookmark(AstNode node) |
||||||
|
{ |
||||||
|
this.node = node; |
||||||
|
} |
||||||
|
|
||||||
|
public virtual ImageSource Image { |
||||||
|
get { |
||||||
|
var attrNode = (AttributedNode)node; |
||||||
|
if (node is EnumMemberDeclaration) |
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.EnumValue); |
||||||
|
|
||||||
|
if (node is FieldDeclaration) |
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.Field); |
||||||
|
|
||||||
|
if (node is PropertyDeclaration) |
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.Property); |
||||||
|
|
||||||
|
if (node is EventDeclaration || node is CustomEventDeclaration) |
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.Event); |
||||||
|
|
||||||
|
if (node is IndexerDeclaration) |
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.Indexer); |
||||||
|
|
||||||
|
if (node is OperatorDeclaration) |
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.Operator); |
||||||
|
|
||||||
|
if (node is ConstructorDeclaration || node is DestructorDeclaration) |
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.Constructor); |
||||||
|
|
||||||
|
return GetMemberOverlayedImage(attrNode, MemberIcon.Method); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ImageSource GetMemberOverlayedImage(AttributedNode attrNode, MemberIcon icon) |
||||||
|
{ |
||||||
|
switch (attrNode.Modifiers & Modifiers.VisibilityMask) { |
||||||
|
case Modifiers.Protected: |
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Protected, (attrNode.Modifiers & Modifiers.Static) == Modifiers.Static); |
||||||
|
case Modifiers.Private: |
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Private, (attrNode.Modifiers & Modifiers.Static) == Modifiers.Static); |
||||||
|
case Modifiers.Internal: |
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Internal, (attrNode.Modifiers & Modifiers.Static) == Modifiers.Static); |
||||||
|
} |
||||||
|
|
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Public, (attrNode.Modifiers & Modifiers.Static) == Modifiers.Static); |
||||||
|
} |
||||||
|
|
||||||
|
public int LineNumber { |
||||||
|
get { |
||||||
|
var t = node.Annotation<Tuple<int, int>>(); |
||||||
|
if (t != null) |
||||||
|
return t.Item1; |
||||||
|
return 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public virtual void MouseDown(MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public virtual void MouseUp(MouseButtonEventArgs e) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
int IBookmark.ZOrder { |
||||||
|
get { return -10; } |
||||||
|
} |
||||||
|
|
||||||
|
bool IBookmark.CanDragDrop { |
||||||
|
get { return false; } |
||||||
|
} |
||||||
|
|
||||||
|
void IBookmark.Drop(int lineNumber) |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class TypeBookmark : MemberBookmark |
||||||
|
{ |
||||||
|
public TypeBookmark(AstNode node) : base (node) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public override ImageSource Image { |
||||||
|
get { |
||||||
|
var attrNode = (AttributedNode)Node; |
||||||
|
|
||||||
|
if (Node is DelegateDeclaration) |
||||||
|
return GetTypeOverlayedImage(attrNode, TypeIcon.Delegate); |
||||||
|
|
||||||
|
if (Node is TypeDeclaration) { |
||||||
|
var n = Node as TypeDeclaration; |
||||||
|
switch (n.ClassType) |
||||||
|
{ |
||||||
|
case ClassType.Delegate: |
||||||
|
return GetTypeOverlayedImage(attrNode, TypeIcon.Delegate); |
||||||
|
case ClassType.Enum: |
||||||
|
return GetTypeOverlayedImage(attrNode, TypeIcon.Enum); |
||||||
|
case ClassType.Struct: |
||||||
|
return GetTypeOverlayedImage(attrNode, TypeIcon.Struct); |
||||||
|
case ClassType.Interface: |
||||||
|
return GetTypeOverlayedImage(attrNode, TypeIcon.Interface); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if ((attrNode.Modifiers & Modifiers.Static) == Modifiers.Static) |
||||||
|
return GetTypeOverlayedImage(attrNode, TypeIcon.StaticClass); |
||||||
|
|
||||||
|
return GetTypeOverlayedImage(attrNode, TypeIcon.Class); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ImageSource GetTypeOverlayedImage(AttributedNode attrNode, TypeIcon icon) |
||||||
|
{ |
||||||
|
switch (attrNode.Modifiers & Modifiers.VisibilityMask) { |
||||||
|
case Modifiers.Protected: |
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Protected); |
||||||
|
case Modifiers.Private: |
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Private); |
||||||
|
case Modifiers.Internal: |
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Internal); |
||||||
|
} |
||||||
|
|
||||||
|
return Images.GetIcon(icon, AccessOverlayIcon.Public); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,111 @@ |
|||||||
|
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||||
|
// software and associated documentation files (the "Software"), to deal in the Software
|
||||||
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||||
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||||
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all copies or
|
||||||
|
// substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
// DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Concurrent; |
||||||
|
using System.Collections.Generic; |
||||||
|
|
||||||
|
using ICSharpCode.Decompiler; |
||||||
|
using ICSharpCode.Decompiler.ILAst; |
||||||
|
using Mono.Cecil; |
||||||
|
|
||||||
|
namespace ICSharpCode.ILSpy.Debugger |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Contains the data important for debugger from the main application.
|
||||||
|
/// </summary>
|
||||||
|
public static class DebugData |
||||||
|
{ |
||||||
|
static DecompiledLanguages language; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the decompiled language.
|
||||||
|
/// </summary>
|
||||||
|
public static DecompiledLanguages Language { |
||||||
|
get { return language; } |
||||||
|
set { |
||||||
|
var oldLanguage = language; |
||||||
|
if (value != language) { |
||||||
|
language = value; |
||||||
|
OnLanguageChanged(new LanguageEventArgs(oldLanguage, language)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List of loaded assemblies.
|
||||||
|
/// </summary>
|
||||||
|
public static IEnumerable<AssemblyDefinition> LoadedAssemblies { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current code mappings.
|
||||||
|
/// </summary>
|
||||||
|
public static Dictionary<int, List<MemberMapping>> CodeMappings { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the local variables of the current decompiled type, method, etc.
|
||||||
|
/// </summary>
|
||||||
|
public static ConcurrentDictionary<int, IEnumerable<ILVariable>> LocalVariables { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the old code mappings.
|
||||||
|
/// </summary>
|
||||||
|
public static Dictionary<int, List<MemberMapping>> OldCodeMappings { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the MembeReference that was decompiled (a TypeDefinition, MethodDefinition, etc)
|
||||||
|
/// </summary>
|
||||||
|
public static Dictionary<int, MemberReference> DecompiledMemberReferences { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the current token, IL offset and member reference. Used for step in/out.
|
||||||
|
/// </summary>
|
||||||
|
public static Tuple<int, int, MemberReference> DebugStepInformation { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets whether the debugger is loaded.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsDebuggerLoaded { get; set; } |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occures when the language is changed.
|
||||||
|
/// </summary>
|
||||||
|
public static event EventHandler<LanguageEventArgs> LanguageChanged; |
||||||
|
|
||||||
|
private static void OnLanguageChanged(LanguageEventArgs e) |
||||||
|
{ |
||||||
|
var handler = LanguageChanged; |
||||||
|
if (handler != null) { |
||||||
|
handler(null, e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public class LanguageEventArgs : EventArgs |
||||||
|
{ |
||||||
|
public DecompiledLanguages OldLanguage { get; private set; } |
||||||
|
|
||||||
|
public DecompiledLanguages NewLanguage { get; private set; } |
||||||
|
|
||||||
|
public LanguageEventArgs(DecompiledLanguages oldLanguage, DecompiledLanguages newLanguage) |
||||||
|
{ |
||||||
|
this.OldLanguage = oldLanguage; |
||||||
|
this.NewLanguage = newLanguage; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
After Width: | Height: | Size: 735 B |
|
After Width: | Height: | Size: 524 B |
Loading…
Reference in new issue