Browse Source

remove old LGPL code copied from SharpDevelop 4

pull/455/head
Siegfried Pammer 11 years ago
parent
commit
056dfa1194
  1. 14
      ILSpy.SharpDevelop.LGPL/AvalonEdit/ITextEditorListener.cs
  2. 35
      ILSpy.SharpDevelop.LGPL/AvalonEdit/IToolTip.cs
  3. 47
      ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs
  4. 353
      ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarMargin.cs
  5. 52
      ILSpy.SharpDevelop.LGPL/AvalonEdit/TextEditorWeakEventManager.cs
  6. 97
      ILSpy.SharpDevelop.LGPL/Bookmarks/BookmarkBase.cs
  7. 28
      ILSpy.SharpDevelop.LGPL/Bookmarks/BookmarkEventHandler.cs
  8. 117
      ILSpy.SharpDevelop.LGPL/Bookmarks/BookmarkManager.cs
  9. 115
      ILSpy.SharpDevelop.LGPL/Bookmarks/BreakpointBookmark.cs
  10. 23
      ILSpy.SharpDevelop.LGPL/Bookmarks/BreakpointBookmarkEventArgs.cs
  11. 94
      ILSpy.SharpDevelop.LGPL/Bookmarks/CurrentLineBookmark.cs
  12. 69
      ILSpy.SharpDevelop.LGPL/Bookmarks/IBookmark.cs
  13. 22
      ILSpy.SharpDevelop.LGPL/Bookmarks/MarkerBookmark.cs
  14. 39
      ILSpy.SharpDevelop.LGPL/DebugInformation.cs
  15. 118
      ILSpy.SharpDevelop.LGPL/ILSpy.SharpDevelop.LGPL.csproj
  16. 36
      ILSpy.SharpDevelop.LGPL/Images.cs
  17. 57
      ILSpy.SharpDevelop.LGPL/Models/ToolTipRequestEventArgs.cs
  18. 31
      ILSpy.SharpDevelop.LGPL/Properties/AssemblyInfo.cs
  19. 409
      ILSpy.SharpDevelop.LGPL/Services/DebuggerService.cs
  20. 122
      ILSpy.SharpDevelop.LGPL/Services/IDebugger.cs
  21. 87
      ILSpy.SharpDevelop.LGPL/Services/ParserService.cs
  22. 18
      ILSpy.sln
  23. 3
      ILSpy/AboutPage.cs
  24. 6
      ILSpy/App.xaml.cs
  25. 81
      ILSpy/AvalonEdit/ITextMarker.cs
  26. 190
      ILSpy/AvalonEdit/IconMarginActionsProvider.cs
  27. 241
      ILSpy/AvalonEdit/TextMarkerService.cs
  28. 93
      ILSpy/Bookmarks/MemberBookmark.cs
  29. 12
      ILSpy/ILSpy.csproj
  30. 51
      ILSpy/MainWindow.xaml.cs
  31. 101
      ILSpy/TextView/DecompilerTextView.cs
  32. 11
      NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

14
ILSpy.SharpDevelop.LGPL/AvalonEdit/ITextEditorListener.cs

@ -1,14 +0,0 @@ @@ -1,14 +0,0 @@
// 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();
}
}

35
ILSpy.SharpDevelop.LGPL/AvalonEdit/IToolTip.cs

@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
// 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;
}
}

47
ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarManager.cs

@ -1,47 +0,0 @@ @@ -1,47 +0,0 @@
// 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.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using ICSharpCode.ILSpy.Bookmarks;
using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
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;
}
}

353
ILSpy.SharpDevelop.LGPL/AvalonEdit/IconBarMargin.cs

@ -1,353 +0,0 @@ @@ -1,353 +0,0 @@
// 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.ILSpy.Debugger.Services;
using ICSharpCode.NRefactory;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.AvalonEdit
{
public class IconBarMargin : AbstractMargin, IDisposable
{
readonly IconBarManager manager;
public IconBarMargin(IconBarManager manager)
{
BookmarkManager.Added += new BookmarkEventHandler(OnBookmarkAdded);
BookmarkManager.Removed += new BookmarkEventHandler(OnBookmarkRemoved);
this.manager = manager;
}
public IconBarManager Manager {
get { return manager; }
}
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)
{
// 16px wide icon + 1px each side padding + 1px right-side border
return new Size(19, 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 (bm is BreakpointBookmark) {
if (DebugInformation.CodeMappings == null || DebugInformation.CodeMappings.Count == 0 ||
!DebugInformation.CodeMappings.ContainsKey(((BreakpointBookmark)bm).FunctionToken))
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;
}
const double imagePadding = 1.0;
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(imagePadding, 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(imagePadding, 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)
continue;
if (bm is BreakpointBookmark) {
if (DebugInformation.CodeMappings == null || DebugInformation.CodeMappings.Count == 0 ||
!DebugInformation.CodeMappings.ContainsKey(((BreakpointBookmark)bm).FunctionToken))
continue;
}
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;
}
public 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 OnBookmarkAdded(object sender, BookmarkEventArgs args)
{
var breakpoint = args.Bookmark as BreakpointBookmark;
if (null == breakpoint)
return;
var storage = DebugInformation.CodeMappings;
if (storage == null || storage.Count == 0)
return;
var key = breakpoint.MemberReference.MetadataToken.ToInt32();
if (storage.ContainsKey(key))
{
// register to show enabled/disabled state
breakpoint.ImageChanged += delegate { InvalidateVisual(); };
InvalidateVisual();
}
}
public void OnBookmarkRemoved(object sender, BookmarkEventArgs args)
{
var breakpoint = args.Bookmark as BreakpointBookmark;
if (null == breakpoint)
return;
var storage = DebugInformation.CodeMappings;
if (storage == null || storage.Count == 0)
return;
var key = breakpoint.MemberReference.MetadataToken.ToInt32();
if (storage.ContainsKey(key))
{
breakpoint.ImageChanged -= delegate { InvalidateVisual(); };
InvalidateVisual();
}
}
public void SyncBookmarks()
{
var storage = DebugInformation.CodeMappings;
if (storage == null || storage.Count == 0)
return;
// TODO: handle other types of bookmarks
// remove existing bookmarks and create new ones
// update of existing bookmarks for new position does not update TextMarker
// this is only done in TextMarkerService handlers for BookmarkManager.Added/Removed
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.FunctionToken;
if (!storage.ContainsKey(key))
continue;
bool isMatch;
SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset(breakpoint.ILRange.From, out isMatch);
if (map != null) {
BreakpointBookmark newBookmark = new BreakpointBookmark(breakpoint.MemberReference,
new TextLocation(map.StartLocation.Line, 0),
breakpoint.FunctionToken,
map.ILInstructionOffset,
BreakpointAction.Break);
newBookmark.IsEnabled = breakpoint.IsEnabled;
newBookmarks.Add(newBookmark);
BookmarkManager.RemoveMark(breakpoint);
}
}
newBookmarks.ForEach(m => BookmarkManager.AddMark(m));
SyncCurrentLineBookmark();
}
void SyncCurrentLineBookmark()
{
// checks
if (CurrentLineBookmark.Instance == null)
return;
var codeMappings = DebugInformation.CodeMappings;
if (codeMappings == null)
return;
// 1. Save it's data
int line = CurrentLineBookmark.Instance.LineNumber;
var markerType = CurrentLineBookmark.Instance.MemberReference;
int token = markerType.MetadataToken.ToInt32();
int offset = CurrentLineBookmark.Instance.ILOffset;
if (!codeMappings.ContainsKey(token))
return;
// 2. map the marker line
MemberReference memberReference;
int newline;
if (codeMappings[token].GetInstructionByTokenAndOffset(offset, out memberReference, out newline)) {
// 3. create breakpoint for new languages
DebuggerService.JumpToCurrentLine(memberReference, newline, 0, newline, 0, offset);
}
}
}
}

52
ILSpy.SharpDevelop.LGPL/AvalonEdit/TextEditorWeakEventManager.cs

@ -1,52 +0,0 @@ @@ -1,52 +0,0 @@
// 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.AvalonEdit;
using ICSharpCode.AvalonEdit.Utils;
namespace ICSharpCode.ILSpy.AvalonEdit
{
public static class TextEditorWeakEventManager
{
public sealed class MouseHover : WeakEventManagerBase<MouseHover, TextEditor>
{
protected override void StopListening(TextEditor source)
{
source.MouseHover -= DeliverEvent;
}
protected override void StartListening(TextEditor source)
{
source.MouseHover += DeliverEvent;
}
}
public sealed class MouseHoverStopped : WeakEventManagerBase<MouseHoverStopped, TextEditor>
{
protected override void StopListening(TextEditor source)
{
source.MouseHoverStopped -= DeliverEvent;
}
protected override void StartListening(TextEditor source)
{
source.MouseHoverStopped += DeliverEvent;
}
}
public sealed class MouseDown : WeakEventManagerBase<MouseDown, TextEditor>
{
protected override void StopListening(TextEditor source)
{
source.MouseDown -= DeliverEvent;
}
protected override void StartListening(TextEditor source)
{
source.MouseDown += DeliverEvent;
}
}
}
}

97
ILSpy.SharpDevelop.LGPL/Bookmarks/BookmarkBase.cs

@ -1,97 +0,0 @@ @@ -1,97 +0,0 @@
// 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.Input;
using System.Windows.Media;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Bookmarks
{
/// <summary>
/// A bookmark that can be attached to an AvalonEdit TextDocument.
/// </summary>
public class BookmarkBase : IBookmark
{
TextLocation location;
protected virtual void RemoveMark()
{
}
public TextLocation Location {
get { return location; }
set { location = value; }
}
public event EventHandler DocumentChanged;
protected virtual void OnDocumentChanged(EventArgs e)
{
if (DocumentChanged != null) {
DocumentChanged(this, e);
}
}
protected virtual void Redraw()
{
}
public MemberReference MemberReference { get; set; }
public int LineNumber {
get { return location.Line; }
}
public int ColumnNumber {
get { return location.Column; }
}
public virtual int ZOrder {
get { return 0; }
}
/// <summary>
/// Gets if the bookmark can be toggled off using the 'set/unset bookmark' command.
/// </summary>
public virtual bool CanToggle {
get {
return true;
}
}
public BookmarkBase(MemberReference member, TextLocation location)
{
this.MemberReference = member;
this.Location = location;
}
public virtual ImageSource Image {
get { return null; }
}
public virtual void MouseDown(MouseButtonEventArgs e)
{
}
public virtual void MouseUp(MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left && CanToggle) {
RemoveMark();
e.Handled = true;
}
}
public virtual bool CanDragDrop {
get { return false; }
}
public virtual void Drop(int lineNumber)
{
}
}
}

28
ILSpy.SharpDevelop.LGPL/Bookmarks/BookmarkEventHandler.cs

@ -1,28 +0,0 @@ @@ -1,28 +0,0 @@
// 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;
namespace ICSharpCode.ILSpy.Bookmarks
{
public delegate void BookmarkEventHandler(object sender, BookmarkEventArgs e);
/// <summary>
/// Description of BookmarkEventHandler.
/// </summary>
public class BookmarkEventArgs : EventArgs
{
BookmarkBase bookmark;
public BookmarkBase Bookmark {
get {
return bookmark;
}
}
public BookmarkEventArgs(BookmarkBase bookmark)
{
this.bookmark = bookmark;
}
}
}

117
ILSpy.SharpDevelop.LGPL/Bookmarks/BookmarkManager.cs

@ -1,117 +0,0 @@ @@ -1,117 +0,0 @@
// 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 ICSharpCode.Decompiler;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
using Mono.CSharp;
namespace ICSharpCode.ILSpy.Bookmarks
{
/// <summary>
/// Static class that maintains the list of bookmarks and breakpoints.
/// </summary>
public static partial class BookmarkManager
{
static List<BookmarkBase> bookmarks = new List<BookmarkBase>();
public static List<BookmarkBase> Bookmarks {
get {
return bookmarks;
}
}
public static List<BookmarkBase> GetBookmarks(string typeName)
{
if (typeName == null)
throw new ArgumentNullException("typeName");
List<BookmarkBase> marks = new List<BookmarkBase>();
foreach (BookmarkBase mark in bookmarks) {
if (typeName == mark.MemberReference.FullName) {
marks.Add(mark);
}
}
return marks;
}
public static void AddMark(BookmarkBase bookmark)
{
if (bookmark == null) return;
if (bookmarks.Contains(bookmark)) return;
if (bookmarks.Exists(b => IsEqualBookmark(b, bookmark))) return;
bookmarks.Add(bookmark);
OnAdded(new BookmarkEventArgs(bookmark));
}
static bool IsEqualBookmark(BookmarkBase a, BookmarkBase b)
{
if (a == b)
return true;
if (a == null || b == null)
return false;
if (a.GetType() != b.GetType())
return false;
if (a.MemberReference.FullName != b.MemberReference.FullName)
return false;
return a.LineNumber == b.LineNumber;
}
public static void RemoveMark(BookmarkBase bookmark)
{
bookmarks.Remove(bookmark);
OnRemoved(new BookmarkEventArgs(bookmark));
}
public static void Clear()
{
while (bookmarks.Count > 0) {
var b = bookmarks[bookmarks.Count - 1];
bookmarks.RemoveAt(bookmarks.Count - 1);
OnRemoved(new BookmarkEventArgs(b));
}
}
internal static void Initialize()
{
}
static void OnRemoved(BookmarkEventArgs e)
{
if (Removed != null) {
Removed(null, e);
}
}
static void OnAdded(BookmarkEventArgs e)
{
if (Added != null) {
Added(null, e);
}
}
public static void ToggleBookmark(string typeName, int line,
Predicate<BookmarkBase> canToggle,
Func<TextLocation, BookmarkBase> bookmarkFactory)
{
foreach (BookmarkBase bookmark in GetBookmarks(typeName)) {
if (canToggle(bookmark) && bookmark.LineNumber == line) {
BookmarkManager.RemoveMark(bookmark);
return;
}
}
// no bookmark at that line: create a new bookmark
BookmarkManager.AddMark(bookmarkFactory(new TextLocation(line, 0)));
}
public static event BookmarkEventHandler Removed;
public static event BookmarkEventHandler Added;
}
}

115
ILSpy.SharpDevelop.LGPL/Bookmarks/BreakpointBookmark.cs

@ -1,115 +0,0 @@ @@ -1,115 +0,0 @@
// 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.Media;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.ILSpy.AvalonEdit;
using ICSharpCode.ILSpy.Bookmarks;
using ICSharpCode.ILSpy.SharpDevelop;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Debugger.Bookmarks
{
public enum BreakpointAction
{
Break,
Trace,
Condition
}
public class BreakpointBookmark : MarkerBookmark
{
bool isHealthy = true;
bool isEnabled = true;
BreakpointAction action = BreakpointAction.Break;
public BreakpointAction Action {
get {
return action;
}
set {
if (action != value) {
action = value;
Redraw();
}
}
}
/// <summary>
/// Gets the function/method where the breakpoint is set.
/// <remarks>
/// In case of methods, it is the same as the MemberReference metadata token.<br/>
/// In case of properties and events, it's the GetMethod/SetMethod|AddMethod/RemoveMethod token.
/// </remarks>
/// </summary>
public int FunctionToken { get; private set; }
public ILRange ILRange { get; private set; }
public virtual bool IsHealthy {
get {
return isHealthy;
}
set {
if (isHealthy != value) {
isHealthy = value;
Redraw();
}
}
}
public virtual bool IsEnabled {
get {
return isEnabled;
}
set {
if (isEnabled != value) {
isEnabled = value;
if (IsEnabledChanged != null)
IsEnabledChanged(this, EventArgs.Empty);
if (ImageChanged != null)
ImageChanged(this, EventArgs.Empty); // Image property reflects IsEnabled property
Redraw();
}
}
}
public event EventHandler IsEnabledChanged;
public string Tooltip { get; private set; }
public BreakpointBookmark(MemberReference member, TextLocation location, int functionToken, ILRange range, BreakpointAction action)
: base(member, location)
{
this.action = action;
this.FunctionToken = functionToken;
this.ILRange = range;
this.Tooltip = string.Format("Line:{0}, IL range:{1}-{2}", location.Line, range.From, range.To);
}
public override ImageSource Image {
get {
return IsEnabled ? Images.Breakpoint : Images.DisabledBreakpoint;
}
}
public event EventHandler ImageChanged;
public override ITextMarker CreateMarker(ITextMarkerService markerService, int offset, int length)
{
ITextMarker marker = markerService.Create(offset, length);
marker.BackgroundColor = Color.FromRgb(180, 38, 38);
marker.ForegroundColor = Colors.White;
marker.IsVisible = b => b is BreakpointBookmark && DebugInformation.CodeMappings != null &&
DebugInformation.CodeMappings.ContainsKey(((BreakpointBookmark)b).FunctionToken);
marker.Bookmark = this;
this.Marker = marker;
return marker;
}
}
}

23
ILSpy.SharpDevelop.LGPL/Bookmarks/BreakpointBookmarkEventArgs.cs

@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
// 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;
namespace ICSharpCode.ILSpy.Debugger.Bookmarks
{
public class BreakpointBookmarkEventArgs : EventArgs
{
BreakpointBookmark breakpointBookmark;
public BreakpointBookmark BreakpointBookmark {
get {
return breakpointBookmark;
}
}
public BreakpointBookmarkEventArgs(BreakpointBookmark breakpointBookmark)
{
this.breakpointBookmark = breakpointBookmark;
}
}
}

94
ILSpy.SharpDevelop.LGPL/Bookmarks/CurrentLineBookmark.cs

@ -1,94 +0,0 @@ @@ -1,94 +0,0 @@
// 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.Media;
using ICSharpCode.ILSpy.AvalonEdit;
using ICSharpCode.ILSpy.Bookmarks;
using ICSharpCode.ILSpy.SharpDevelop;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Debugger.Bookmarks
{
public class CurrentLineBookmark : MarkerBookmark
{
static CurrentLineBookmark instance;
public static CurrentLineBookmark Instance {
get { return instance; }
}
static int startLine;
static int startColumn;
static int endLine;
static int endColumn;
public static void SetPosition(MemberReference memberReference, int makerStartLine, int makerStartColumn, int makerEndLine, int makerEndColumn, int ilOffset)
{
Remove();
startLine = makerStartLine;
startColumn = makerStartColumn;
endLine = makerEndLine;
endColumn = makerEndColumn;
instance = new CurrentLineBookmark(memberReference, new TextLocation(startLine, startColumn), ilOffset);
BookmarkManager.AddMark(instance);
}
public static void Remove()
{
if (instance != null) {
BookmarkManager.RemoveMark(instance);
instance = null;
}
}
public override bool CanToggle {
get { return false; }
}
public override int ZOrder {
get { return 100; }
}
private CurrentLineBookmark(MemberReference member, TextLocation location, int ilOffset) : base(member, location)
{
this.ILOffset = ilOffset;
}
public int ILOffset { get; private set; }
public override ImageSource Image {
get { return Images.CurrentLine; }
}
public override bool CanDragDrop {
get { return false; }
}
public override void Drop(int lineNumber)
{
// call async because the Debugger seems to use Application.DoEvents(), but we don't want to process events
// because Drag'N'Drop operation has finished
// WorkbenchSingleton.SafeThreadAsyncCall(
// delegate {
// DebuggerService.CurrentDebugger.SetInstructionPointer(this.FileName, lineNumber, 1);
// });
}
public override ITextMarker CreateMarker(ITextMarkerService markerService, int offset, int length)
{
ITextMarker marker = markerService.Create(offset + startColumn - 1, length + 1);
marker.BackgroundColor = Colors.Yellow;
marker.ForegroundColor = Colors.Blue;
marker.IsVisible = b => b is MarkerBookmark && DebugInformation.CodeMappings != null &&
DebugInformation.CodeMappings.ContainsKey(((MarkerBookmark)b).MemberReference.MetadataToken.ToInt32());
marker.Bookmark = this;
this.Marker = marker;
return marker;
}
}
}

69
ILSpy.SharpDevelop.LGPL/Bookmarks/IBookmark.cs

@ -1,69 +0,0 @@ @@ -1,69 +0,0 @@
// 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.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows.Input;
using System.Windows.Media;
namespace ICSharpCode.ILSpy.Bookmarks
{
/// <summary>
/// The bookmark margin.
/// </summary>
public interface IBookmarkMargin
{
/// <summary>
/// Gets the list of bookmarks.
/// </summary>
IList<IBookmark> Bookmarks { get; }
/// <summary>
/// Redraws the bookmark margin. Bookmarks need to call this method when the Image changes.
/// </summary>
void Redraw();
}
/// <summary>
/// Represents a bookmark in the bookmark margin.
/// </summary>
public interface IBookmark
{
/// <summary>
/// Gets the line number of the bookmark.
/// </summary>
int LineNumber { get; }
/// <summary>
/// Gets the image.
/// </summary>
ImageSource Image { get; }
/// <summary>
/// Gets the Z-Order of the bookmark icon.
/// </summary>
int ZOrder { get; }
/// <summary>
/// Handles the mouse down event.
/// </summary>
void MouseDown(MouseButtonEventArgs e);
/// <summary>
/// Handles the mouse up event.
/// </summary>
void MouseUp(MouseButtonEventArgs e);
/// <summary>
/// Gets whether this bookmark can be dragged around.
/// </summary>
bool CanDragDrop { get; }
/// <summary>
/// Notifies the bookmark that it was dropped on the specified line.
/// </summary>
void Drop(int lineNumber);
}
}

22
ILSpy.SharpDevelop.LGPL/Bookmarks/MarkerBookmark.cs

@ -1,22 +0,0 @@ @@ -1,22 +0,0 @@
// 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 ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.ILSpy.AvalonEdit;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Bookmarks
{
public abstract class MarkerBookmark : BookmarkBase
{
public MarkerBookmark(MemberReference member, TextLocation location) : base(member, location)
{
}
public ITextMarker Marker { get; set; }
public abstract ITextMarker CreateMarker(ITextMarkerService markerService, int offset, int length);
}
}

39
ILSpy.SharpDevelop.LGPL/DebugInformation.cs

@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
// 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.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 DebugInformation
{
/// <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, MemberMapping> CodeMappings { 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; }
}
}

118
ILSpy.SharpDevelop.LGPL/ILSpy.SharpDevelop.LGPL.csproj

@ -1,118 +0,0 @@ @@ -1,118 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{704F66F1-5C7F-4326-A7AA-C604A3896D4E}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.ILSpy.SharpDevelop</RootNamespace>
<AssemblyName>ILSpy.SharpDevelop.LGPL</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<BaseAddress>6881280</BaseAddress>
<SignAssembly>True</SignAssembly>
<DelaySign>False</DelaySign>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<AssemblyOriginatorKeyFile>..\NRefactory\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>PdbOnly</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AvalonEdit\IconBarManager.cs" />
<Compile Include="AvalonEdit\IconBarMargin.cs" />
<Compile Include="AvalonEdit\ITextEditorListener.cs" />
<Compile Include="AvalonEdit\ITextMarker.cs" />
<Compile Include="AvalonEdit\IToolTip.cs" />
<Compile Include="AvalonEdit\TextEditorWeakEventManager.cs" />
<Compile Include="AvalonEdit\TextMarkerService.cs" />
<Compile Include="Bookmarks\BookmarkBase.cs" />
<Compile Include="Bookmarks\BookmarkEventHandler.cs" />
<Compile Include="Bookmarks\BookmarkManager.cs" />
<Compile Include="Bookmarks\BreakpointBookmark.cs" />
<Compile Include="Bookmarks\BreakpointBookmarkEventArgs.cs" />
<Compile Include="Bookmarks\CurrentLineBookmark.cs" />
<Compile Include="Bookmarks\IBookmark.cs" />
<Compile Include="Bookmarks\MarkerBookmark.cs" />
<Compile Include="DebugInformation.cs" />
<Compile Include="Images.cs" />
<Compile Include="Models\ToolTipRequestEventArgs.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\DebuggerService.cs" />
<Compile Include="Services\IDebugger.cs" />
<Compile Include="Services\ParserService.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="AvalonEdit" />
<Folder Include="Bookmarks" />
<Folder Include="Models" />
<Folder Include="Services" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj">
<Project>{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}</Project>
<Name>ICSharpCode.AvalonEdit</Name>
</ProjectReference>
<ProjectReference Include="..\ICSharpCode.Decompiler\ICSharpCode.Decompiler.csproj">
<Project>{984CC812-9470-4A13-AFF9-CC44068D666C}</Project>
<Name>ICSharpCode.Decompiler</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53DCA265-3C3C-42F9-B647-F72BA678122B}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
</ProjectReference>
<ProjectReference Include="..\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
<Name>ICSharpCode.NRefactory</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

36
ILSpy.SharpDevelop.LGPL/Images.cs

@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
// 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.Media;
using System.Windows.Media.Imaging;
namespace ICSharpCode.ILSpy.SharpDevelop
{
static class Images
{
static BitmapImage LoadBitmap(string name)
{
try {
BitmapImage image = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/Images/" + name + ".png"));
if (image == null)
return null;
image.Freeze();
return image;
}
catch {
// resource not found
return null;
}
}
public static readonly BitmapImage Breakpoint = LoadBitmap("Breakpoint");
public static readonly BitmapImage DisabledBreakpoint = LoadBitmap("DisabledBreakpoint");
public static readonly BitmapImage CurrentLine = LoadBitmap("CurrentLine");
public static ImageSource GetImage(string imageName)
{
return LoadBitmap(imageName);
}
}
}

57
ILSpy.SharpDevelop.LGPL/Models/ToolTipRequestEventArgs.cs

@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
// 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 ICSharpCode.AvalonEdit;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.ILSpy.Debugger.Tooltips
{
public class ToolTipRequestEventArgs : EventArgs
{
/// <summary>
/// Gets whether the tool tip request was handled.
/// </summary>
public bool Handled { get; set; }
/// <summary>
/// Gets the editor causing the request.
/// </summary>
public TextEditor Editor { get; private set; }
/// <summary>
/// Gets whether the mouse was inside the document bounds.
/// </summary>
public bool InDocument { get; set; }
/// <summary>
/// The mouse position, in document coordinates.
/// </summary>
public TextLocation LogicalPosition { get; set; }
/// <summary>
/// Gets/Sets the content to show as a tooltip.
/// </summary>
public object ContentToShow { get; set; }
/// <summary>
/// Sets the tooltip to be shown.
/// </summary>
public void SetToolTip(object content)
{
if (content == null)
throw new ArgumentNullException("content");
this.Handled = true;
this.ContentToShow = content;
}
public ToolTipRequestEventArgs(TextEditor editor)
{
if (editor == null)
throw new ArgumentNullException("editor");
this.Editor = editor;
this.InDocument = true;
}
}
}

31
ILSpy.SharpDevelop.LGPL/Properties/AssemblyInfo.cs

@ -1,31 +0,0 @@ @@ -1,31 +0,0 @@
#region Using directives
using System;
using System.Reflection;
using System.Runtime.InteropServices;
#endregion
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ILSpy.SharpDevelop.LGPL")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ILSpy.SharpDevelop.LGPL")]
[assembly: AssemblyCopyright("Copyright 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// This sets the default COM visibility of types in the assembly to invisible.
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
[assembly: ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all the values or you can use the default the Revision and
// Build Numbers by using the '*' as shown below:
[assembly: AssemblyVersion("2.0.0.0")]

409
ILSpy.SharpDevelop.LGPL/Services/DebuggerService.cs

@ -1,409 +0,0 @@ @@ -1,409 +0,0 @@
// 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 ICSharpCode.AvalonEdit.Document;
using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.ILAst;
using ICSharpCode.ILSpy;
using ICSharpCode.ILSpy.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Tooltips;
using ICSharpCode.NRefactory.CSharp.Resolver;
using ICSharpCode.NRefactory.Semantics;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.Debugger.Services
{
public static class DebuggerService
{
static IDebugger currentDebugger;
static DebuggerService()
{
BookmarkManager.Added += BookmarkAdded;
BookmarkManager.Removed += BookmarkRemoved;
}
static IDebugger GetCompatibleDebugger()
{
return currentDebugger;
}
/// <summary>
/// Gets the current debugger. The debugger addin is loaded on demand; so if you
/// just want to check a property like IsDebugging, check <see cref="IsDebuggerLoaded"/>
/// before using this property.
/// </summary>
public static IDebugger CurrentDebugger {
get {
if (currentDebugger == null) {
currentDebugger = GetCompatibleDebugger();
if (currentDebugger == null)
return null;
currentDebugger.DebugStarting += new EventHandler(OnDebugStarting);
currentDebugger.DebugStarted += new EventHandler(OnDebugStarted);
currentDebugger.DebugStopped += new EventHandler(OnDebugStopped);
}
return currentDebugger;
}
}
/// <summary>
/// Returns true if debugger is already loaded.
/// </summary>
public static bool IsDebuggerLoaded {
get {
return currentDebugger != null;
}
}
static bool debuggerStarted;
/// <summary>
/// Gets whether the debugger is currently active.
/// </summary>
public static bool IsDebuggerStarted {
get { return debuggerStarted; }
}
public static event EventHandler DebugStarting;
public static event EventHandler DebugStarted;
public static event EventHandler DebugStopped;
static void OnDebugStarting(object sender, EventArgs e)
{
ClearDebugMessages();
if (DebugStarting != null)
DebugStarting(null, e);
}
static void OnDebugStarted(object sender, EventArgs e)
{
debuggerStarted = true;
if (DebugStarted != null)
DebugStarted(null, e);
}
static void OnDebugStopped(object sender, EventArgs e)
{
debuggerStarted = false;
RemoveCurrentLineMarker();
if (DebugStopped != null)
DebugStopped(null, e);
}
public static void ClearDebugMessages()
{
}
public static void PrintDebugMessage(string msg)
{
}
public static event EventHandler<BreakpointBookmarkEventArgs> BreakPointChanged;
public static event EventHandler<BreakpointBookmarkEventArgs> BreakPointAdded;
public static event EventHandler<BreakpointBookmarkEventArgs> BreakPointRemoved;
static void OnBreakPointChanged(BreakpointBookmarkEventArgs e)
{
if (BreakPointChanged != null) {
BreakPointChanged(null, e);
}
}
static void OnBreakPointAdded(BreakpointBookmarkEventArgs e)
{
if (BreakPointAdded != null) {
BreakPointAdded(null, e);
}
}
static void OnBreakPointRemoved(BreakpointBookmarkEventArgs e)
{
if (BreakPointRemoved != null) {
BreakPointRemoved(null, e);
}
}
public static IList<BreakpointBookmark> Breakpoints {
get {
List<BreakpointBookmark> breakpoints = new List<BreakpointBookmark>();
foreach (var bookmark in BookmarkManager.Bookmarks) {
BreakpointBookmark breakpoint = bookmark as BreakpointBookmark;
if (breakpoint != null) {
breakpoints.Add(breakpoint);
}
}
return breakpoints.AsReadOnly();
}
}
static void BookmarkAdded(object sender, BookmarkEventArgs e)
{
BreakpointBookmark bb = e.Bookmark as BreakpointBookmark;
if (bb != null) {
OnBreakPointAdded(new BreakpointBookmarkEventArgs(bb));
}
}
static void BookmarkRemoved(object sender, BookmarkEventArgs e)
{
BreakpointBookmark bb = e.Bookmark as BreakpointBookmark;
if (bb != null) {
OnBreakPointRemoved(new BreakpointBookmarkEventArgs(bb));
}
}
static void BookmarkChanged(object sender, EventArgs e)
{
BreakpointBookmark bb = sender as BreakpointBookmark;
if (bb != null) {
OnBreakPointChanged(new BreakpointBookmarkEventArgs(bb));
}
}
public static void ToggleBreakpointAt(MemberReference member, int lineNumber, int functionToken, ILRange range)
{
BookmarkManager.ToggleBookmark(
member.FullName, lineNumber,
b => b.CanToggle && b is BreakpointBookmark,
location => new BreakpointBookmark(member, location, functionToken, range, BreakpointAction.Break));
}
/* TODO: reimplement this stuff
static void ViewContentOpened(object sender, ViewContentEventArgs e)
{
textArea.IconBarMargin.MouseDown += IconBarMouseDown;
textArea.ToolTipRequest += TextAreaToolTipRequest;
textArea.MouseLeave += TextAreaMouseLeave;
}*/
public static void RemoveCurrentLineMarker()
{
CurrentLineBookmark.Remove();
}
public static void JumpToCurrentLine(MemberReference memberReference, int startLine, int startColumn, int endLine, int endColumn, int ilOffset)
{
CurrentLineBookmark.SetPosition(memberReference, startLine, startColumn, endLine, endColumn, ilOffset);
}
#region Tool tips
/// <summary>
/// Gets debugger tooltip information for the specified position.
/// A descriptive string for the element or a DebuggerTooltipControl
/// showing its current value (when in debugging mode) can be returned
/// through the ToolTipRequestEventArgs.SetTooltip() method.
/// </summary>
public static void HandleToolTipRequest(ToolTipRequestEventArgs e)
{
if (!e.InDocument)
return;
var logicPos = e.LogicalPosition;
var doc = (TextDocument)e.Editor.Document;
var line = doc.GetLineByNumber(logicPos.Line);
if (line.Offset + logicPos.Column >= doc.TextLength)
return;
var c = doc.GetText(line.Offset + logicPos.Column, 1);
if (string.IsNullOrEmpty(c) || c == "\n" || c == "\t")
return;
string variable =
ParserService.SimpleParseAt(doc.Text, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column)));
if (currentDebugger == null || !currentDebugger.IsDebugging || !currentDebugger.CanEvaluate) {
e.ContentToShow = null;
}
else {
try {
e.ContentToShow = currentDebugger.GetTooltipControl(e.LogicalPosition, variable);
} catch {
return;
}
}
// FIXME Do proper parsing
//
// using (var sr = new StringReader(doc.Text))
// {
// var parser = new CSharpParser();
// parser.Parse(sr);
//
// IExpressionFinder expressionFinder = ParserService.GetExpressionFinder();
// if (expressionFinder == null)
// return;
// var currentLine = doc.GetLine(logicPos.Y);
// if (logicPos.X > currentLine.Length)
// return;
// string textContent = doc.Text;
// ExpressionResult expressionResult = expressionFinder.FindFullExpression(textContent, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column)));
// string expression = (expressionResult.Expression ?? "").Trim();
// if (expression.Length > 0) {
// // Look if it is variable
// ResolveResult result = ParserService.Resolve(expressionResult, logicPos.Y, logicPos.X, e.Editor.FileName, textContent);
// bool debuggerCanShowValue;
// string toolTipText = GetText(result, expression, out debuggerCanShowValue);
// if (Control.ModifierKeys == Keys.Control) {
// toolTipText = "expr: " + expressionResult.ToString() + "\n" + toolTipText;
// debuggerCanShowValue = false;
// }
// if (toolTipText != null) {
// if (debuggerCanShowValue && currentDebugger != null) {
// object toolTip = currentDebugger.GetTooltipControl(e.LogicalPosition, expressionResult.Expression);
// if (toolTip != null)
// e.SetToolTip(toolTip);
// else
// e.SetToolTip(toolTipText);
// } else {
// e.SetToolTip(toolTipText);
// }
// }
// }
// else {
// #if DEBUG
// if (Control.ModifierKeys == Keys.Control) {
// e.SetToolTip("no expr: " + expressionResult.ToString());
// }
// #endif
// }
// }
}
static string GetText(ResolveResult result, string expression, out bool debuggerCanShowValue)
{
debuggerCanShowValue = false;
return "FIXME";
// FIXME
// debuggerCanShowValue = false;
// if (result == null) {
// // when pressing control, show the expression even when it could not be resolved
// return (Control.ModifierKeys == Keys.Control) ? "" : null;
// }
// if (result is MixedResolveResult)
// return GetText(((MixedResolveResult)result).PrimaryResult, expression, out debuggerCanShowValue);
// else if (result is DelegateCallResolveResult)
// return GetText(((DelegateCallResolveResult)result).Target, expression, out debuggerCanShowValue);
//
// IAmbience ambience = AmbienceService.GetCurrentAmbience();
// ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.UseFullyQualifiedMemberNames;
// if (result is MemberResolveResult) {
// return GetMemberText(ambience, ((MemberResolveResult)result).ResolvedMember, expression, out debuggerCanShowValue);
// } else if (result is LocalResolveResult) {
// LocalResolveResult rr = (LocalResolveResult)result;
// ambience.ConversionFlags = ConversionFlags.UseFullyQualifiedTypeNames
// | ConversionFlags.ShowReturnType | ConversionFlags.ShowDefinitionKeyWord;
// StringBuilder b = new StringBuilder();
// if (rr.IsParameter)
// b.Append("parameter ");
// else
// b.Append("local variable ");
// b.Append(ambience.Convert(rr.Field));
// if (currentDebugger != null) {
// string currentValue = currentDebugger.GetValueAsString(rr.VariableName);
// if (currentValue != null) {
// debuggerCanShowValue = true;
// b.Append(" = ");
// if (currentValue.Length > 256)
// currentValue = currentValue.Substring(0, 256) + "...";
// b.Append(currentValue);
// }
// }
// return b.ToString();
// } else if (result is NamespaceResolveResult) {
// return "namespace " + ((NamespaceResolveResult)result).Name;
// } else if (result is TypeResolveResult) {
// IClass c = ((TypeResolveResult)result).ResolvedClass;
// if (c != null)
// return GetMemberText(ambience, c, expression, out debuggerCanShowValue);
// else
// return ambience.Convert(result.ResolvedType);
// } else if (result is MethodGroupResolveResult) {
// MethodGroupResolveResult mrr = result as MethodGroupResolveResult;
// IMethod m = mrr.GetMethodIfSingleOverload();
// IMethod m2 = mrr.GetMethodWithEmptyParameterList();
// if (m != null)
// return GetMemberText(ambience, m, expression, out debuggerCanShowValue);
// else if (ambience is VBNetAmbience && m2 != null)
// return GetMemberText(ambience, m2, expression, out debuggerCanShowValue);
// else
// return "Overload of " + ambience.Convert(mrr.ContainingType) + "." + mrr.Name;
// } else {
// if (Control.ModifierKeys == Keys.Control) {
// if (result.ResolvedType != null)
// return "expression of type " + ambience.Convert(result.ResolvedType);
// else
// return "ResolveResult without ResolvedType";
// } else {
// return null;
// }
// }
}
// static string GetMemberText(IAmbience ambience, IEntity member, string expression, out bool debuggerCanShowValue)
// {
// bool tryDisplayValue = false;
// debuggerCanShowValue = false;
// StringBuilder text = new StringBuilder();
// if (member is IField) {
// text.Append(ambience.Convert(member as IField));
// tryDisplayValue = true;
// } else if (member is IProperty) {
// text.Append(ambience.Convert(member as IProperty));
// tryDisplayValue = true;
// } else if (member is IEvent) {
// text.Append(ambience.Convert(member as IEvent));
// } else if (member is IMethod) {
// text.Append(ambience.Convert(member as IMethod));
// } else if (member is IClass) {
// text.Append(ambience.Convert(member as IClass));
// } else {
// text.Append("unknown member ");
// text.Append(member.ToString());
// }
// if (tryDisplayValue && currentDebugger != null) {
// LoggingService.Info("asking debugger for value of '" + expression + "'");
// string currentValue = currentDebugger.GetValueAsString(expression);
// if (currentValue != null) {
// debuggerCanShowValue = true;
// text.Append(" = ");
// text.Append(currentValue);
// }
// }
// string documentation = member.Documentation;
// if (documentation != null && documentation.Length > 0) {
// text.Append('\n');
// text.Append(ICSharpCode.SharpDevelop.Editor.CodeCompletion.CodeCompletionItem.ConvertDocumentation(documentation));
// }
// return text.ToString();
// }
#endregion
public static void SetDebugger(Lazy<IDebugger> debugger)
{
if (currentDebugger != null)
{
currentDebugger.DebugStarting -= new EventHandler(OnDebugStarting);
currentDebugger.DebugStarted -= new EventHandler(OnDebugStarted);
currentDebugger.DebugStopped -= new EventHandler(OnDebugStopped);
}
currentDebugger = debugger.Value;
if (currentDebugger != null)
{
currentDebugger.DebugStarting += new EventHandler(OnDebugStarting);
currentDebugger.DebugStarted += new EventHandler(OnDebugStarted);
currentDebugger.DebugStopped += new EventHandler(OnDebugStopped);
}
}
}
}

122
ILSpy.SharpDevelop.LGPL/Services/IDebugger.cs

@ -1,122 +0,0 @@ @@ -1,122 +0,0 @@
// 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.Diagnostics;
using ICSharpCode.Decompiler;
using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.CSharp;
namespace ICSharpCode.ILSpy.Debugger.Services
{
public interface IDebugger : IDisposable
{
/// <summary>
/// Gets whether the debugger can evaluate the expression.
/// </summary>
bool CanEvaluate { get; }
/// <summary>
/// Returns true if debuger is attached to a process
/// </summary>
bool IsDebugging {
get;
}
/// <summary>
/// Returns true if process is running
/// Returns false if breakpoint is hit, program is breaked, program is stepped, etc...
/// </summary>
bool IsProcessRunning {
get;
}
/// <summary>
/// Gets or sets whether the debugger should break at the first line of execution.
/// </summary>
bool BreakAtBeginning {
get; set;
}
/// <summary>
/// Starts process and attaches debugger
/// </summary>
void Start(ProcessStartInfo processStartInfo);
void StartWithoutDebugging(ProcessStartInfo processStartInfo);
/// <summary>
/// Stops/terminates attached process
/// </summary>
void Stop();
// ExecutionControl:
void Break();
void Continue();
// Stepping:
void StepInto();
void StepOver();
void StepOut();
/// <summary>
/// Shows a dialog so the user can attach to a process.
/// </summary>
void ShowAttachDialog();
/// <summary>
/// Used to attach to an existing process.
/// </summary>
void Attach(Process process);
void Detach();
/// <summary>
/// Gets the current value of the variable as string that can be displayed in tooltips.
/// </summary>
string GetValueAsString(string variable);
/// <summary>
/// Gets the tooltip control that shows the value of given variable.
/// Return null if no tooltip is available.
/// </summary>
object GetTooltipControl(TextLocation logicalPosition, string variable);
/// <summary>
/// Queries the debugger whether it is possible to set the instruction pointer to a given position.
/// </summary>
/// <returns>True if possible. False otherwise</returns>
bool CanSetInstructionPointer(string filename, int line, int column);
/// <summary>
/// Set the instruction pointer to a given position.
/// </summary>
/// <returns>True if successful. False otherwise</returns>
bool SetInstructionPointer(string filename, int line, int column);
/// <summary>
/// Ocurrs when the debugger is starting.
/// </summary>
event EventHandler DebugStarting;
/// <summary>
/// Ocurrs after the debugger has started.
/// </summary>
event EventHandler DebugStarted;
/// <summary>
/// Ocurrs when the value of IsProcessRunning changes.
/// </summary>
event EventHandler IsProcessRunningChanged;
/// <summary>
/// Ocurrs after the debugging of program is finished.
/// </summary>
event EventHandler DebugStopped;
}
}

87
ILSpy.SharpDevelop.LGPL/Services/ParserService.cs

@ -1,87 +0,0 @@ @@ -1,87 +0,0 @@
// 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;
namespace ICSharpCode.ILSpy.Debugger.Services
{
/// <summary>
/// Very naive parser.
/// </summary>
static class ParserService
{
static HashSet<string> mySet = new HashSet<string>();
static ParserService()
{
mySet.AddRange((new string [] {
".",
"{",
"}",
"(",
")",
"[",
"]",
" ",
"=",
"+",
"-",
"/",
"%",
"*",
"&",
Environment.NewLine,
";",
",",
"~",
"!",
"?",
@"\n",
@"\t",
@"\r",
"|"
}));
}
static void AddRange<T>(this ICollection<T> list, IEnumerable<T> items)
{
foreach (T item in items)
if (!list.Contains(item))
list.Add(item);
}
/// <summary>
/// Returns the variable name
/// </summary>
/// <param name="fullText"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static string SimpleParseAt(string fullText, int offset)
{
if (string.IsNullOrEmpty(fullText))
return string.Empty;
if (offset <= 0 || offset >= fullText.Length)
return string.Empty;
string currentValue = fullText[offset].ToString();
if (mySet.Contains(currentValue))
return string.Empty;
int left = offset, right = offset;
//search left
while((!mySet.Contains(currentValue) || currentValue == ".") && left > 0)
currentValue = fullText[--left].ToString();
currentValue = fullText[offset].ToString();
// searh right
while(!mySet.Contains(currentValue) && right < fullText.Length - 2)
currentValue = fullText[++right].ToString();
return fullText.Substring(left + 1, right - 1 - left).Trim();
}
}
}

18
ILSpy.sln

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.3
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# SharpDevelop 5.0
VisualStudioVersion = 12.0.20827.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "doc", "doc", "{F45DB999-7E72-4000-B5AD-3A7B485A0896}"
ProjectSection(SolutionItems) = preProject
doc\Command Line.txt = doc\Command Line.txt
@ -31,8 +33,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.BamlDecompiler", "ILS @@ -31,8 +33,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.BamlDecompiler", "ILS
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.BamlDecompiler.Tests", "ILSpy.BamlDecompiler\Tests\ILSpy.BamlDecompiler.Tests.csproj", "{1169E6D1-1899-43D4-A500-07CE4235B388}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.SharpDevelop.LGPL", "ILSpy.SharpDevelop.LGPL\ILSpy.SharpDevelop.LGPL.csproj", "{704F66F1-5C7F-4326-A7AA-C604A3896D4E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory.CSharp", "NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj", "{53DCA265-3C3C-42F9-B647-F72BA678122B}"
EndProject
Global
@ -139,14 +139,6 @@ Global @@ -139,14 +139,6 @@ Global
{1169E6D1-1899-43D4-A500-07CE4235B388}.Release|Any CPU.Build.0 = Release|Any CPU
{1169E6D1-1899-43D4-A500-07CE4235B388}.Release|x86.ActiveCfg = Release|x86
{1169E6D1-1899-43D4-A500-07CE4235B388}.Release|x86.Build.0 = Release|x86
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Debug|x86.ActiveCfg = Debug|x86
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Debug|x86.Build.0 = Debug|x86
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Release|Any CPU.Build.0 = Release|Any CPU
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Release|x86.ActiveCfg = Release|x86
{704F66F1-5C7F-4326-A7AA-C604A3896D4E}.Release|x86.Build.0 = Release|x86
{53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53DCA265-3C3C-42F9-B647-F72BA678122B}.Debug|x86.ActiveCfg = Debug|Any CPU

3
ILSpy/AboutPage.cs

@ -96,9 +96,6 @@ namespace ICSharpCode.ILSpy @@ -96,9 +96,6 @@ namespace ICSharpCode.ILSpy
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("MIT License", "resource:license.txt"));
output.AddVisualLineElementGenerator(new MyLinkElementGenerator("LGPL", "resource:LGPL.txt"));
textView.ShowText(output);
//reset icon bar
textView.manager.Bookmarks.Clear();
}
sealed class MyLinkElementGenerator : LinkElementGenerator

6
ILSpy/App.xaml.cs

@ -28,7 +28,6 @@ using System.Windows.Documents; @@ -28,7 +28,6 @@ using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Threading;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.TextView;
namespace ICSharpCode.ILSpy
@ -98,11 +97,6 @@ namespace ICSharpCode.ILSpy @@ -98,11 +97,6 @@ namespace ICSharpCode.ILSpy
Hyperlink.RequestNavigateEvent,
new RequestNavigateEventHandler(Window_RequestNavigate));
try {
DebuggerService.SetDebugger(compositionContainer.GetExport<IDebugger>());
} catch {
// unable to find a IDebugger
}
}
string FullyQualifyPath(string argument)

81
ILSpy.SharpDevelop.LGPL/AvalonEdit/ITextMarker.cs → ILSpy/AvalonEdit/ITextMarker.cs

@ -1,12 +1,26 @@ @@ -1,12 +1,26 @@
// 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)
// Copyright (c) 2014 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.Windows;
using System.Windows.Media;
using ICSharpCode.ILSpy.Bookmarks;
namespace ICSharpCode.ILSpy.AvalonEdit
{
/// <summary>
@ -54,10 +68,20 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -54,10 +68,20 @@ namespace ICSharpCode.ILSpy.AvalonEdit
/// </summary>
Color? ForegroundColor { get; set; }
/// <summary>
/// Gets/Sets the font weight.
/// </summary>
FontWeight? FontWeight { get; set; }
/// <summary>
/// Gets/Sets the font style.
/// </summary>
FontStyle? FontStyle { get; set; }
/// <summary>
/// Gets/Sets the type of the marker. Use TextMarkerType.None for normal markers.
/// </summary>
TextMarkerType MarkerType { get; set; }
TextMarkerTypes MarkerTypes { get; set; }
/// <summary>
/// Gets/Sets the color of the marker.
@ -73,28 +97,44 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -73,28 +97,44 @@ namespace ICSharpCode.ILSpy.AvalonEdit
/// 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
[Flags]
public enum TextMarkerTypes
{
/// <summary>
/// Use no marker
/// </summary>
None,
None = 0x0000,
/// <summary>
/// Use squiggly underline marker
/// </summary>
SquigglyUnderline
SquigglyUnderline = 0x001,
/// <summary>
/// Normal underline.
/// </summary>
NormalUnderline = 0x002,
/// <summary>
/// Dotted underline.
/// </summary>
DottedUnderline = 0x004,
/// <summary>
/// Horizontal line in the scroll bar.
/// </summary>
LineInScrollBar = 0x0100,
/// <summary>
/// Small triangle in the scroll bar, pointing to the right.
/// </summary>
ScrollBarRightTriangle = 0x0400,
/// <summary>
/// Small triangle in the scroll bar, pointing to the left.
/// </summary>
ScrollBarLeftTriangle = 0x0800,
/// <summary>
/// Small circle in the scroll bar.
/// </summary>
CircleInScrollBar = 0x1000
}
public interface ITextMarkerService
@ -119,5 +159,10 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -119,5 +159,10 @@ namespace ICSharpCode.ILSpy.AvalonEdit
/// Removes all text markers that match the condition.
/// </summary>
void RemoveAll(Predicate<ITextMarker> predicate);
/// <summary>
/// Finds all text markers at the specified offset.
/// </summary>
IEnumerable<ITextMarker> GetMarkersAtOffset(int offset);
}
}

190
ILSpy/AvalonEdit/IconMarginActionsProvider.cs

@ -1,190 +0,0 @@ @@ -1,190 +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.ComponentModel.Composition;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Input;
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;
}
ContextMenu menu = new ContextMenu();
foreach (var category in contextEntries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) {
bool needSeparatorForCategory = true;
foreach (var entryPair in category) {
IBookmarkContextMenuEntry entry = entryPair.Value;
if (entry.IsVisible(bookmark)) {
if (needSeparatorForCategory && menu.Items.Count > 0) {
menu.Items.Add(new Separator());
needSeparatorForCategory = false;
}
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(bookmark)) {
menuItem.Click += delegate { entry.Execute(bookmark); };
} else
menuItem.IsEnabled = false;
menu.Items.Add(menuItem);
}
}
}
if (menu.Items.Count > 0)
margin.ContextMenu = menu;
else
// hide the context menu.
e.Handled = true;
}
}
}
}

241
ILSpy.SharpDevelop.LGPL/AvalonEdit/TextMarkerService.cs → ILSpy/AvalonEdit/TextMarkerService.cs

@ -1,69 +1,56 @@ @@ -1,69 +1,56 @@
// 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)
// Copyright (c) 2014 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 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
public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService, ITextViewConnect
{
TextEditor codeEditor;
TextSegmentCollection<TextMarker> markers = new TextSegmentCollection<TextMarker>();
TextSegmentCollection<TextMarker> markers;
TextDocument document;
public TextMarkerService()
public TextMarkerService(TextDocument document)
{
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);
}
}
if (document == null)
throw new ArgumentNullException("document");
this.document = document;
this.markers = new TextSegmentCollection<TextMarker>(document);
}
#region ITextMarkerService
public ITextMarker Create(int startOffset, int length)
{
int textLength = codeEditor.TextArea.TextView.Document.TextLength;
if (markers == null)
throw new InvalidOperationException("Cannot create a marker when not attached to a document");
int textLength = 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)
@ -77,30 +64,34 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -77,30 +64,34 @@ namespace ICSharpCode.ILSpy.AvalonEdit
public IEnumerable<ITextMarker> GetMarkersAtOffset(int offset)
{
return markers.FindSegmentsContaining(offset);
if (markers == null)
return Enumerable.Empty<ITextMarker>();
else
return markers.FindSegmentsContaining(offset);
}
public IEnumerable<ITextMarker> TextMarkers {
get { return markers; }
get { return markers ?? Enumerable.Empty<ITextMarker>(); }
}
public void RemoveAll(Predicate<ITextMarker> predicate)
{
if (predicate == null)
throw new ArgumentNullException("predicate");
foreach (TextMarker m in markers.ToArray()) {
if (predicate(m))
Remove(m);
if (markers != null) {
foreach (TextMarker m in markers.ToArray()) {
if (predicate(m))
Remove(m);
}
}
}
public void Remove(ITextMarker marker)
{
if (marker == null)
return;
throw new ArgumentNullException("marker");
TextMarker m = marker as TextMarker;
if (markers.Remove(m)) {
if (markers != null && markers.Remove(m)) {
Redraw(m);
m.OnDeleted();
}
@ -109,10 +100,16 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -109,10 +100,16 @@ namespace ICSharpCode.ILSpy.AvalonEdit
/// <summary>
/// Redraws the specified text segment.
/// </summary>
public void Redraw(ISegment segment)
internal void Redraw(ISegment segment)
{
codeEditor.TextArea.TextView.Redraw(segment, DispatcherPriority.Normal);
foreach (var view in textViews) {
view.Redraw(segment, DispatcherPriority.Normal);
}
if (RedrawRequested != null)
RedrawRequested(this, EventArgs.Empty);
}
public event EventHandler RedrawRequested;
#endregion
#region DocumentColorizingTransformer
@ -122,10 +119,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -122,10 +119,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
return;
int lineStart = line.Offset;
int lineEnd = lineStart + line.Length;
foreach (TextMarker marker in markers.FindOverlappingSegments(lineStart, line.Length).Reverse()) {
if (marker.Bookmark != null && !marker.IsVisible(marker.Bookmark))
continue;
foreach (TextMarker marker in markers.FindOverlappingSegments(lineStart, line.Length)) {
Brush foregroundBrush = null;
if (marker.ForegroundColor != null) {
foregroundBrush = new SolidColorBrush(marker.ForegroundColor.Value);
@ -138,6 +132,13 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -138,6 +132,13 @@ namespace ICSharpCode.ILSpy.AvalonEdit
if (foregroundBrush != null) {
element.TextRunProperties.SetForegroundBrush(foregroundBrush);
}
Typeface tf = element.TextRunProperties.Typeface;
element.TextRunProperties.SetTypeface(new Typeface(
tf.FontFamily,
marker.FontStyle ?? tf.Style,
marker.FontWeight ?? tf.Weight,
tf.Stretch
));
}
);
}
@ -164,11 +165,8 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -164,11 +165,8 @@ namespace ICSharpCode.ILSpy.AvalonEdit
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.Bookmark != null && !marker.IsVisible(marker.Bookmark))
continue;
int viewEnd = visualLines.Last().LastDocumentLine.EndOffset;
foreach (TextMarker marker in markers.FindOverlappingSegments(viewStart, viewEnd - viewStart)) {
if (marker.BackgroundColor != null) {
BackgroundGeometryBuilder geoBuilder = new BackgroundGeometryBuilder();
geoBuilder.AlignToWholePixels = true;
@ -182,30 +180,42 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -182,30 +180,42 @@ namespace ICSharpCode.ILSpy.AvalonEdit
drawingContext.DrawGeometry(brush, null, geometry);
}
}
if (marker.MarkerType != TextMarkerType.None) {
var underlineMarkerTypes = TextMarkerTypes.SquigglyUnderline | TextMarkerTypes.NormalUnderline | TextMarkerTypes.DottedUnderline;
if ((marker.MarkerTypes & underlineMarkerTypes) != 0) {
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;
Brush usedBrush = new SolidColorBrush(marker.MarkerColor);
usedBrush.Freeze();
if ((marker.MarkerTypes & TextMarkerTypes.SquigglyUnderline) != 0) {
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();
Pen usedPen = new Pen(usedBrush, 1);
usedPen.Freeze();
drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry);
}
if ((marker.MarkerTypes & TextMarkerTypes.NormalUnderline) != 0) {
Pen usedPen = new Pen(usedBrush, 1);
usedPen.Freeze();
drawingContext.DrawLine(usedPen, startPoint, endPoint);
}
if ((marker.MarkerTypes & TextMarkerTypes.DottedUnderline) != 0) {
Pen usedPen = new Pen(usedBrush, 1);
usedPen.DashStyle = DashStyles.Dot;
usedPen.Freeze();
drawingContext.DrawLine(usedPen, startPoint, endPoint);
}
}
}
@ -218,9 +228,29 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -218,9 +228,29 @@ namespace ICSharpCode.ILSpy.AvalonEdit
yield return new Point(start.X + i * offset, start.Y - ((i + 1) % 2 == 0 ? offset : 0));
}
#endregion
#region ITextViewConnect
readonly List<ICSharpCode.AvalonEdit.Rendering.TextView> textViews = new List<ICSharpCode.AvalonEdit.Rendering.TextView>();
void ITextViewConnect.AddToTextView(ICSharpCode.AvalonEdit.Rendering.TextView textView)
{
if (textView != null && !textViews.Contains(textView)) {
Debug.Assert(textView.Document == document);
textViews.Add(textView);
}
}
void ITextViewConnect.RemoveFromTextView(ICSharpCode.AvalonEdit.Rendering.TextView textView)
{
if (textView != null) {
Debug.Assert(textView.Document == document);
textViews.Remove(textView);
}
}
#endregion
}
sealed class TextMarker : TextSegment, ITextMarker
public sealed class TextMarker : TextSegment, ITextMarker
{
readonly TextMarkerService service;
@ -231,7 +261,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -231,7 +261,7 @@ namespace ICSharpCode.ILSpy.AvalonEdit
this.service = service;
this.StartOffset = startOffset;
this.Length = length;
this.markerType = TextMarkerType.None;
this.markerTypes = TextMarkerTypes.None;
}
public event EventHandler Deleted;
@ -280,15 +310,39 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -280,15 +310,39 @@ namespace ICSharpCode.ILSpy.AvalonEdit
}
}
FontWeight? fontWeight;
public FontWeight? FontWeight {
get { return fontWeight; }
set {
if (fontWeight != value) {
fontWeight = value;
Redraw();
}
}
}
FontStyle? fontStyle;
public FontStyle? FontStyle {
get { return fontStyle; }
set {
if (fontStyle != value) {
fontStyle = value;
Redraw();
}
}
}
public object Tag { get; set; }
TextMarkerType markerType;
TextMarkerTypes markerTypes;
public TextMarkerType MarkerType {
get { return markerType; }
public TextMarkerTypes MarkerTypes {
get { return markerTypes; }
set {
if (markerType != value) {
markerType = value;
if (markerTypes != value) {
markerTypes = value;
Redraw();
}
}
@ -304,15 +358,8 @@ namespace ICSharpCode.ILSpy.AvalonEdit @@ -304,15 +358,8 @@ namespace ICSharpCode.ILSpy.AvalonEdit
Redraw();
}
}
}
/// <inheritdoc/>
public object ToolTip { get; set; }
/// <inheritdoc/>
public Predicate<object> IsVisible { get; set; }
/// <inheritdoc/>
public IBookmark Bookmark { get; set; }
public object ToolTip { get; set; }
}
}

93
ILSpy/Bookmarks/MemberBookmark.cs

@ -1,93 +0,0 @@ @@ -1,93 +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.Windows.Input;
using System.Windows.Media;
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
{
MemberReference member;
public MemberReference Member {
get {
return member;
}
}
public MemberBookmark(MemberReference member, int line)
{
this.member = member;
LineNumber = line;
}
public virtual ImageSource Image {
get {
if (member is FieldDefinition)
return TreeNodes.FieldTreeNode.GetIcon((FieldDefinition)member);
if (member is PropertyDefinition)
return TreeNodes.PropertyTreeNode.GetIcon((PropertyDefinition)member);
if (member is EventDefinition)
return TreeNodes.EventTreeNode.GetIcon((EventDefinition)member);
if (member is MethodDefinition)
return TreeNodes.MethodTreeNode.GetIcon((MethodDefinition)member);
if (member is TypeDefinition)
return TreeNodes.TypeTreeNode.GetIcon((TypeDefinition)member);
return null;
}
}
public int LineNumber {
get; private set;
}
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();
}
}
}

12
ILSpy/ILSpy.csproj

@ -99,8 +99,8 @@ @@ -99,8 +99,8 @@
</Compile>
<Compile Include="AssemblyList.cs" />
<Compile Include="AssemblyListManager.cs" />
<Compile Include="AvalonEdit\IconMarginActionsProvider.cs" />
<Compile Include="Bookmarks\MemberBookmark.cs" />
<Compile Include="AvalonEdit\ITextMarker.cs" />
<Compile Include="AvalonEdit\TextMarkerService.cs" />
<Compile Include="Commands\BrowseBackCommand.cs" />
<Compile Include="Commands\BrowseForwardCommand.cs" />
<Compile Include="CommandLineArguments.cs" />
@ -361,10 +361,6 @@ @@ -361,10 +361,6 @@
<Project>{984CC812-9470-4A13-AFF9-CC44068D666C}</Project>
<Name>ICSharpCode.Decompiler</Name>
</ProjectReference>
<ProjectReference Include="..\ILSpy.SharpDevelop.LGPL\ILSpy.SharpDevelop.LGPL.csproj">
<Project>{704F66F1-5C7F-4326-A7AA-C604A3896D4E}</Project>
<Name>ILSpy.SharpDevelop.LGPL</Name>
</ProjectReference>
<ProjectReference Include="..\Mono.Cecil\Mono.Cecil.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
<Name>Mono.Cecil</Name>
@ -394,7 +390,9 @@ @@ -394,7 +390,9 @@
<Name>ICSharpCode.TreeView</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="AvalonEdit" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\ResourceXml.png" />
<Resource Include="Images\ResourceXsd.png" />

51
ILSpy/MainWindow.xaml.cs

@ -32,7 +32,6 @@ using System.Windows.Interop; @@ -32,7 +32,6 @@ using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpy.XmlDoc;
@ -50,7 +49,7 @@ namespace ICSharpCode.ILSpy @@ -50,7 +49,7 @@ namespace ICSharpCode.ILSpy
readonly NavigationHistory<NavigationState> history = new NavigationHistory<NavigationState>();
ILSpySettings spySettings;
internal SessionSettings sessionSettings;
internal AssemblyListManager assemblyListManager;
AssemblyList assemblyList;
AssemblyListTreeNode assemblyListTreeNode;
@ -311,7 +310,7 @@ namespace ICSharpCode.ILSpy @@ -311,7 +310,7 @@ namespace ICSharpCode.ILSpy
HandleCommandLineArguments(App.CommandLineArguments);
if (assemblyList.GetAssemblies().Length == 0
&& assemblyList.ListName == AssemblyListManager.DefaultListName)
&& assemblyList.ListName == AssemblyListManager.DefaultListName)
{
LoadInitialAssemblies();
}
@ -403,7 +402,7 @@ namespace ICSharpCode.ILSpy @@ -403,7 +402,7 @@ namespace ICSharpCode.ILSpy
ShowAssemblyList(list);
}
}
void ShowAssemblyList(AssemblyList assemblyList)
{
history.Clear();
@ -421,7 +420,7 @@ namespace ICSharpCode.ILSpy @@ -421,7 +420,7 @@ namespace ICSharpCode.ILSpy
else
this.Title = "ILSpy - " + assemblyList.ListName;
}
void assemblyList_Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Reset) {
@ -459,7 +458,7 @@ namespace ICSharpCode.ILSpy @@ -459,7 +458,7 @@ namespace ICSharpCode.ILSpy
foreach (System.Reflection.Assembly asm in initialAssemblies)
assemblyList.OpenAssembly(asm.Location);
}
void filterSettings_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
RefreshTreeViewFilter();
@ -491,9 +490,9 @@ namespace ICSharpCode.ILSpy @@ -491,9 +490,9 @@ namespace ICSharpCode.ILSpy
treeView.SelectedItem = obj;
} else {
MessageBox.Show("Navigation failed because the target is hidden or a compiler-generated class.\n" +
"Please disable all filters that might hide the item (i.e. activate " +
"\"View > Show internal types and members\") and try again.",
"ILSpy", MessageBoxButton.OK, MessageBoxImage.Exclamation);
"Please disable all filters that might hide the item (i.e. activate " +
"\"View > Show internal types and members\") and try again.",
"ILSpy", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
}
}
@ -611,13 +610,9 @@ namespace ICSharpCode.ILSpy @@ -611,13 +610,9 @@ namespace ICSharpCode.ILSpy
void RefreshCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (!DebugInformation.IsDebuggerLoaded) {
var path = GetPathForNode(treeView.SelectedItem as SharpTreeNode);
ShowAssemblyList(assemblyListManager.LoadList(ILSpySettings.Load(), assemblyList.ListName));
SelectNode(FindNodeByPath(path, true));
} else {
e.Handled = false;
}
var path = GetPathForNode(treeView.SelectedItem as SharpTreeNode);
ShowAssemblyList(assemblyListManager.LoadList(ILSpySettings.Load(), assemblyList.ListName));
SelectNode(FindNodeByPath(path, true));
}
void SearchCommandExecuted(object sender, ExecutedRoutedEventArgs e)
@ -631,21 +626,21 @@ namespace ICSharpCode.ILSpy @@ -631,21 +626,21 @@ namespace ICSharpCode.ILSpy
{
DecompileSelectedNodes();
}
private bool ignoreDecompilationRequests;
private void DecompileSelectedNodes(DecompilerTextViewState state = null, bool recordHistory = true)
bool ignoreDecompilationRequests;
void DecompileSelectedNodes(DecompilerTextViewState state = null, bool recordHistory = true)
{
if (ignoreDecompilationRequests)
return;
if (recordHistory) {
var dtState = decompilerTextView.GetState();
if(dtState != null)
history.UpdateCurrent(new NavigationState(dtState));
history.Record(new NavigationState(treeView.SelectedItems.OfType<SharpTreeNode>()));
}
if (treeView.SelectedItems.Count == 1) {
ILSpyTreeNode node = treeView.SelectedItem as ILSpyTreeNode;
if (node != null && node.View(decompilerTextView))
@ -661,8 +656,8 @@ namespace ICSharpCode.ILSpy @@ -661,8 +656,8 @@ namespace ICSharpCode.ILSpy
return;
}
this.TextView.SaveToDisk(this.CurrentLanguage,
this.SelectedNodes,
new DecompilationOptions() { FullDecompilation = true });
this.SelectedNodes,
new DecompilationOptions() { FullDecompilation = true });
}
public void RefreshDecompiledView()
@ -715,14 +710,14 @@ namespace ICSharpCode.ILSpy @@ -715,14 +710,14 @@ namespace ICSharpCode.ILSpy
NavigateHistory(true);
}
}
void NavigateHistory(bool forward)
{
var dtState = decompilerTextView.GetState();
if(dtState != null)
history.UpdateCurrent(new NavigationState(dtState));
var newState = forward ? history.GoForward() : history.GoBack();
ignoreDecompilationRequests = true;
treeView.SelectedItems.Clear();
foreach (var node in newState.TreeNodes)
@ -734,7 +729,7 @@ namespace ICSharpCode.ILSpy @@ -734,7 +729,7 @@ namespace ICSharpCode.ILSpy
ignoreDecompilationRequests = false;
DecompileSelectedNodes(newState.ViewState, false);
}
#endregion
protected override void OnStateChanged(EventArgs e)
@ -810,7 +805,7 @@ namespace ICSharpCode.ILSpy @@ -810,7 +805,7 @@ namespace ICSharpCode.ILSpy
pane.Closed();
}
#endregion
public void UnselectAll()
{
treeView.UnselectAll();

101
ILSpy/TextView/DecompilerTextView.cs

@ -43,10 +43,6 @@ using ICSharpCode.AvalonEdit.Rendering; @@ -43,10 +43,6 @@ using ICSharpCode.AvalonEdit.Rendering;
using ICSharpCode.AvalonEdit.Search;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.AvalonEdit;
using ICSharpCode.ILSpy.Bookmarks;
using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.Debugger.Bookmarks;
using ICSharpCode.ILSpy.Debugger.Services;
using ICSharpCode.ILSpy.Options;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.ILSpy.XmlDoc;
@ -73,14 +69,9 @@ namespace ICSharpCode.ILSpy.TextView @@ -73,14 +69,9 @@ namespace ICSharpCode.ILSpy.TextView
TextSegmentCollection<ReferenceSegment> references;
CancellationTokenSource currentCancellationTokenSource;
internal readonly IconBarManager manager;
readonly IconBarMargin iconMargin;
readonly TextMarkerService textMarkerService;
readonly List<ITextMarker> localReferenceMarks = new List<ITextMarker>();
[ImportMany(typeof(ITextEditorListener))]
IEnumerable<ITextEditorListener> textEditorListeners = null;
#region Constructor
public DecompilerTextView()
{
@ -94,7 +85,6 @@ namespace ICSharpCode.ILSpy.TextView @@ -94,7 +85,6 @@ namespace ICSharpCode.ILSpy.TextView
}
});
this.Loaded+= new RoutedEventHandler(DecompilerTextView_Loaded);
InitializeComponent();
this.referenceElementGenerator = new ReferenceElementGenerator(this.JumpToReference, this.IsLink);
@ -104,44 +94,21 @@ namespace ICSharpCode.ILSpy.TextView @@ -104,44 +94,21 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.Options.RequireControlModifierForHyperlinkClick = false;
textEditor.TextArea.TextView.MouseHover += TextViewMouseHover;
textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped;
textEditor.SetBinding(TextEditor.FontFamilyProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") });
textEditor.SetBinding(TextEditor.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") });
textEditor.SetBinding(Control.FontFamilyProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFont") });
textEditor.SetBinding(Control.FontSizeProperty, new Binding { Source = DisplaySettingsPanel.CurrentDisplaySettings, Path = new PropertyPath("SelectedFontSize") });
// add marker service & margin
iconMargin = new IconBarMargin((manager = new IconBarManager()));
textMarkerService = new TextMarkerService();
textMarkerService.CodeEditor = textEditor;
textMarkerService = new TextMarkerService(textEditor.Document);
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
textEditor.ShowLineNumbers = true;
DisplaySettingsPanel.CurrentDisplaySettings.PropertyChanged += CurrentDisplaySettings_PropertyChanged;
textEditor.TextArea.LeftMargins.Insert(0, iconMargin);
textEditor.TextArea.TextView.VisualLinesChanged += delegate { iconMargin.InvalidateVisual(); };
// Bookmarks context menu
IconMarginActionsProvider.Add(iconMargin);
textEditor.TextArea.DefaultInputHandler.NestedInputHandlers.Add(new SearchInputHandler(textEditor.TextArea));
this.Loaded += new RoutedEventHandler(DecompilerTextView_Loaded);
}
void DecompilerTextView_Loaded(object sender, RoutedEventArgs e)
{
ShowLineMargin();
// wire the events
if (textEditorListeners != null) {
foreach (var listener in textEditorListeners) {
ICSharpCode.ILSpy.AvalonEdit.TextEditorWeakEventManager.MouseHover.AddListener(textEditor, listener);
ICSharpCode.ILSpy.AvalonEdit.TextEditorWeakEventManager.MouseHoverStopped.AddListener(textEditor, listener);
ICSharpCode.ILSpy.AvalonEdit.TextEditorWeakEventManager.MouseDown.AddListener(textEditor, listener);
}
}
textEditor.TextArea.TextView.VisualLinesChanged += (s, _) => iconMargin.InvalidateVisual();
// add marker service & margin
textMarkerService.CodeEditor = textEditor;
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
}
@ -364,21 +331,6 @@ namespace ICSharpCode.ILSpy.TextView @@ -364,21 +331,6 @@ namespace ICSharpCode.ILSpy.TextView
foldingManager.UpdateFoldings(textOutput.Foldings.OrderBy(f => f.StartOffset), -1);
Debug.WriteLine(" Updating folding: {0}", w.Elapsed); w.Restart();
}
// update debugger info
DebugInformation.CodeMappings = textOutput.DebuggerMemberMappings.ToDictionary(m => m.MetadataToken);
// update class bookmarks
var document = textEditor.Document;
manager.Bookmarks.Clear();
foreach (var pair in textOutput.DefinitionLookup.definitions) {
MemberReference member = pair.Key as MemberReference;
int offset = pair.Value;
if (member != null) {
int line = document.GetLocation(offset).Line;
manager.Bookmarks.Add(new MemberBookmark(member, line));
}
}
}
#endregion
@ -429,14 +381,6 @@ namespace ICSharpCode.ILSpy.TextView @@ -429,14 +381,6 @@ namespace ICSharpCode.ILSpy.TextView
void DoDecompile(DecompilationContext context, int outputLengthLimit)
{
// close popup
if (textEditorListeners != null) {
foreach (var listener in textEditorListeners) {
listener.ClosePopup();
}
}
bool isDecompilationOk = true;
RunWithCancellation(
delegate (CancellationToken ct) { // creation of the background task
context.Options.CancellationToken = ct;
@ -461,50 +405,11 @@ namespace ICSharpCode.ILSpy.TextView @@ -461,50 +405,11 @@ namespace ICSharpCode.ILSpy.TextView
output.WriteLine(ex.ToString());
}
ShowOutput(output);
isDecompilationOk = false;
} finally {
this.UpdateDebugUI(isDecompilationOk);
}
decompiledNodes = context.TreeNodes;
});
}
void UpdateDebugUI(bool isDecompilationOk)
{
// sync bookmarks
iconMargin.SyncBookmarks();
if (isDecompilationOk) {
if (DebugInformation.DebugStepInformation != null && DebuggerService.CurrentDebugger != null) {
// repaint bookmarks
iconMargin.InvalidateVisual();
// show the currentline marker
int token = DebugInformation.DebugStepInformation.Item1;
int ilOffset = DebugInformation.DebugStepInformation.Item2;
int line;
MemberReference member;
if (DebugInformation.CodeMappings == null || !DebugInformation.CodeMappings.ContainsKey(token))
return;
if (!DebugInformation.CodeMappings[token].GetInstructionByTokenAndOffset(ilOffset, out member, out line))
return;
// update marker
DebuggerService.JumpToCurrentLine(member, line, 0, line, 0, ilOffset);
var bm = CurrentLineBookmark.Instance;
DocumentLine docline = textEditor.Document.GetLineByNumber(line);
bm.Marker = bm.CreateMarker(textMarkerService, docline.Offset + 1, docline.Length);
UnfoldAndScroll(line);
}
} else {
// remove currentline marker
CurrentLineBookmark.Remove();
}
}
Task<AvalonEditTextOutput> DecompileAsync(DecompilationContext context, int outputLengthLimit)
{
Debug.WriteLine("Start decompilation of {0} tree nodes", context.TreeNodes.Length);

11
NRefactory/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -836,17 +836,6 @@ namespace ICSharpCode.NRefactory.VB @@ -836,17 +836,6 @@ namespace ICSharpCode.NRefactory.VB
}
WriteToken("]", AstNode.Roles.RBracket);
}
void WriteCommaSeparatedListInBrackets(IEnumerable<Expression> list)
{
WriteToken ("[", AstNode.Roles.LBracket);
if (list.Any ()) {
Space();
WriteCommaSeparatedList(list);
Space();
}
WriteToken ("]", AstNode.Roles.RBracket);
}
#endregion
#region Write tokens

Loading…
Cancel
Save