Browse Source

fix Bookmarks margin

pull/191/merge
Eusebiu Marcu 15 years ago
parent
commit
42c2c95511
  1. 66
      Debugger/ILSpy.Debugger/AvalonEdit/IconBarManager.cs
  2. 55
      Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs
  3. 8
      Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs
  4. 5
      Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj
  5. 28
      ILSpy.sln
  6. 1
      ILSpy/ILSpy.csproj
  7. 11
      ILSpy/TextView/DecompilerTextView.cs
  8. 2
      ILSpy/TreeNodes/TypeTreeNode.cs

66
Debugger/ILSpy.Debugger/AvalonEdit/IconBarManager.cs

@ -1,66 +0,0 @@ @@ -1,66 +0,0 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using ILSpy.Debugger.Bookmarks;
namespace ILSpy.Debugger.AvalonEdit
{
public class IconBarManager : IBookmarkMargin
{
static object syncLock = new object();
static IconBarManager instance;
public static IconBarManager Instance {
get {
if (instance == null)
lock(syncLock)
if(instance == null)
instance = new IconBarManager();
return instance;
}
}
private IconBarManager()
{
}
public IList<BookmarkBase> Bookmarks {
get { return BookmarkManager.Bookmarks; }
}
void bookmarks_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
Redraw();
}
public void Redraw()
{
if (RedrawRequested != null)
RedrawRequested(this, EventArgs.Empty);
}
public event EventHandler RedrawRequested;
}
}

55
Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs

@ -32,33 +32,18 @@ using ILSpy.Debugger.Services; @@ -32,33 +32,18 @@ using ILSpy.Debugger.Services;
namespace ILSpy.Debugger.AvalonEdit
{
public class IconBarMargin : AbstractMargin, IDisposable
{
readonly IconBarManager manager;
{
static string currentTypeName;
public IconBarMargin(IconBarManager manager)
{
if (manager == null)
throw new ArgumentNullException("manager");
this.manager = manager;
public static string CurrentTypeName {
get {
return currentTypeName; }
set { currentTypeName = value; }
}
#region OnTextViewChanged
/// <inheritdoc/>
protected override void OnTextViewChanged(TextView oldTextView, TextView newTextView)
{
if (oldTextView != null) {
oldTextView.VisualLinesChanged -= OnRedrawRequested;
manager.RedrawRequested -= OnRedrawRequested;
}
base.OnTextViewChanged(oldTextView, newTextView);
if (newTextView != null) {
newTextView.VisualLinesChanged += OnRedrawRequested;
manager.RedrawRequested += OnRedrawRequested;
}
InvalidateVisual();
}
void OnRedrawRequested(object sender, EventArgs e)
{
InvalidateVisual();
}
@ -94,17 +79,20 @@ namespace ILSpy.Debugger.AvalonEdit @@ -94,17 +79,20 @@ namespace ILSpy.Debugger.AvalonEdit
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 (IBookmark bm in manager.Bookmarks) {
Dictionary<int, BookmarkBase> bookmarkDict = new Dictionary<int, BookmarkBase>();
foreach (var bm in BookmarkManager.Bookmarks) {
if (bm.TypeName != IconBarMargin.CurrentTypeName)
continue;
int line = bm.LineNumber;
IBookmark existingBookmark;
BookmarkBase existingBookmark;
if (!bookmarkDict.TryGetValue(line, out existingBookmark) || bm.ZOrder > existingBookmark.ZOrder)
bookmarkDict[line] = bm;
}
Size pixelSize = PixelSnapHelpers.GetPixelSize(this);
foreach (VisualLine line in textView.VisualLines) {
int lineNumber = line.FirstDocumentLine.LineNumber;
IBookmark bm;
BookmarkBase bm;
if (bookmarkDict.TryGetValue(lineNumber, out bm)) {
Rect rect = new Rect(0, PixelSnapHelpers.Round(line.VisualTop - textView.VerticalOffset, pixelSize.Height), 16, 16);
if (dragDropBookmark == bm && dragStarted)
@ -148,11 +136,11 @@ namespace ILSpy.Debugger.AvalonEdit @@ -148,11 +136,11 @@ namespace ILSpy.Debugger.AvalonEdit
e.Handled = true;
}
IBookmark GetBookmarkFromLine(int line)
BookmarkBase GetBookmarkFromLine(int line)
{
IBookmark result = null;
foreach (IBookmark bm in manager.Bookmarks) {
if (bm.LineNumber == line) {
BookmarkBase result = null;
foreach (BookmarkBase bm in BookmarkManager.Bookmarks) {
if (bm.LineNumber == line && bm.TypeName == IconBarMargin.CurrentTypeName) {
if (result == null || bm.ZOrder > result.ZOrder)
result = bm;
}
@ -238,13 +226,18 @@ namespace ILSpy.Debugger.AvalonEdit @@ -238,13 +226,18 @@ namespace ILSpy.Debugger.AvalonEdit
IBookmark bm = GetBookmarkFromLine(line);
if (bm != null) {
bm.MouseUp(e);
if (!string.IsNullOrEmpty(IconBarMargin.CurrentTypeName)) {
DebuggerService.ToggleBreakpointAt(IconBarMargin.CurrentTypeName, line);
}
InvalidateVisual();
if (e.Handled)
return;
}
if (e.ChangedButton == MouseButton.Left && TextView != null) {
// no bookmark on the line: create a new breakpoint
DebuggerService.ToggleBreakpointAt("test", line);
if (!string.IsNullOrEmpty(IconBarMargin.CurrentTypeName)) {
// no bookmark on the line: create a new breakpoint
DebuggerService.ToggleBreakpointAt(IconBarMargin.CurrentTypeName, line);
}
}
InvalidateVisual();
}

8
Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs

@ -81,7 +81,7 @@ namespace ILSpy.Debugger.Bookmarks @@ -81,7 +81,7 @@ namespace ILSpy.Debugger.Bookmarks
protected virtual void RemoveMark()
{
IconBarManager.Instance.Bookmarks.Remove(this);
}
/// <summary>
@ -116,11 +116,7 @@ namespace ILSpy.Debugger.Bookmarks @@ -116,11 +116,7 @@ namespace ILSpy.Debugger.Bookmarks
protected virtual void Redraw()
{
if (document != null) {
IBookmarkMargin bookmarkMargin = IconBarManager.Instance;
if (bookmarkMargin != null)
bookmarkMargin.Redraw();
}
}
public string TypeName { get; set; }

5
Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj

@ -55,7 +55,6 @@ @@ -55,7 +55,6 @@
<Compile Include="AvalonEdit\Editor\ITextAnchor.cs" />
<Compile Include="AvalonEdit\Editor\ITextBuffer.cs" />
<Compile Include="AvalonEdit\Editor\TextChangeEventArgs.cs" />
<Compile Include="AvalonEdit\IconBarManager.cs" />
<Compile Include="AvalonEdit\IconBarMargin.cs" />
<Compile Include="Bookmarks\BookmarkBase.cs" />
<Compile Include="Bookmarks\BookmarkEventHandler.cs" />
@ -80,7 +79,9 @@ @@ -80,7 +79,9 @@
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Services\Debugger\Tooltips" />
</ItemGroup>
<ItemGroup>
<Page Include="UI\AttachToProcessWindow.xaml" />
</ItemGroup>

28
ILSpy.sln

@ -6,25 +6,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Debugger", "Debugger", "{BF @@ -6,25 +6,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Debugger", "Debugger", "{BF
ProjectSection(SolutionItems) = postProject
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.Debugger", "Debugger\ILSpy.Debugger\ILSpy.Debugger.csproj", "{6D3D0F0D-348D-456A-A6ED-E9BD5EFABB6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Debugger.Core", "Debugger\Debugger.Core\Debugger.Core.csproj", "{1D18D788-F7EE-4585-A23B-34DC8EC63CB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy.Debugger", "Debugger\ILSpy.Debugger\ILSpy.Debugger.csproj", "{6D3D0F0D-348D-456A-A6ED-E9BD5EFABB6A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{4E076A9B-159A-45C4-9E34-AE1D20D83E42}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Decompiler\lib\NRefactory\Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj", "{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "Mono.Cecil\Mono.Cecil.csproj", "{D68133BD-1E63-496E-9EDE-4FBDBF77B486}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TreeView", "SharpTreeView\ICSharpCode.TreeView.csproj", "{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.AvalonEdit", "AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj", "{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Dom", "Libraries\ICSharpCode.SharpDevelop.Dom\Project\ICSharpCode.SharpDevelop.Dom.csproj", "{924EE450-603D-49C1-A8E5-4AFAA31CE6F3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.AvalonEdit", "AvalonEdit\ICSharpCode.AvalonEdit\ICSharpCode.AvalonEdit.csproj", "{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.TreeView", "SharpTreeView\ICSharpCode.TreeView.csproj", "{DDE2A481-8271-4EAC-A330-8FA6A38D13D1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "Mono.Cecil\Mono.Cecil.csproj", "{D68133BD-1E63-496E-9EDE-4FBDBF77B486}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.NRefactory", "NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj", "{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Decompiler\lib\NRefactory\Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ILSpy", "ILSpy\ILSpy.csproj", "{1E85EFF9-E370-4683-83E4-8A3D063FF791}"
EndProject
@ -117,13 +117,13 @@ Global @@ -117,13 +117,13 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {BF79A230-0918-47DF-8A36-776779A331DE}
{6D3D0F0D-348D-456A-A6ED-E9BD5EFABB6A} = {BF79A230-0918-47DF-8A36-776779A331DE}
{D68133BD-1E63-496E-9EDE-4FBDBF77B486} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{DDE2A481-8271-4EAC-A330-8FA6A38D13D1} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{1D18D788-F7EE-4585-A23B-34DC8EC63CB8} = {BF79A230-0918-47DF-8A36-776779A331DE}
{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{3B2A5653-EC97-4001-BB9B-D90F1AF2C371} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{DDE2A481-8271-4EAC-A330-8FA6A38D13D1} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{924EE450-603D-49C1-A8E5-4AFAA31CE6F3} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{6C55B776-26D4-4DB3-A6AB-87E783B2F3D1} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
{D68133BD-1E63-496E-9EDE-4FBDBF77B486} = {4E076A9B-159A-45C4-9E34-AE1D20D83E42}
EndGlobalSection
EndGlobal

1
ILSpy/ILSpy.csproj

@ -221,6 +221,5 @@ @@ -221,6 +221,5 @@
<Name>ICSharpCode.TreeView</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
</Project>

11
ILSpy/TextView/DecompilerTextView.cs

@ -35,6 +35,7 @@ using ICSharpCode.AvalonEdit.Highlighting.Xshd; @@ -35,6 +35,7 @@ using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.Decompiler;
using ICSharpCode.ILSpy.TreeNodes;
using ILSpy.Debugger.AvalonEdit;
using ILSpy.Debugger.Bookmarks;
using Microsoft.Win32;
using Mono.Cecil;
@ -54,6 +55,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -54,6 +55,8 @@ namespace ICSharpCode.ILSpy.TextView
DefinitionLookup definitionLookup;
CancellationTokenSource currentCancellationTokenSource;
IconBarMargin iconMargin;
#region Constructor
public DecompilerTextView()
{
@ -75,7 +78,8 @@ namespace ICSharpCode.ILSpy.TextView @@ -75,7 +78,8 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.Options.RequireControlModifierForHyperlinkClick = false;
// add margin
textEditor.TextArea.LeftMargins.Add(new IconBarMargin(IconBarManager.Instance));
iconMargin = new IconBarMargin();
textEditor.TextArea.LeftMargins.Add(iconMargin);
}
#endregion
@ -192,6 +196,7 @@ namespace ICSharpCode.ILSpy.TextView @@ -192,6 +196,7 @@ namespace ICSharpCode.ILSpy.TextView
/// </summary>
public void Decompile(ILSpy.Language language, IEnumerable<ILSpyTreeNodeBase> treeNodes, DecompilationOptions options)
{
IconBarMargin.CurrentTypeName = string.Empty;
// Some actions like loading an assembly list cause several selection changes in the tree view,
// and each of those will start a decompilation action.
bool isDecompilationScheduled = this.nextDecompilationRun != null;
@ -249,6 +254,10 @@ namespace ICSharpCode.ILSpy.TextView @@ -249,6 +254,10 @@ namespace ICSharpCode.ILSpy.TextView
}
ShowOutput(output);
}
finally {
// repaint bookmarks
iconMargin.InvalidateVisual();
}
});
}

2
ILSpy/TreeNodes/TypeTreeNode.cs

@ -22,6 +22,7 @@ using System.Linq; @@ -22,6 +22,7 @@ using System.Linq;
using System.Windows.Media;
using ICSharpCode.Decompiler;
using ILSpy.Debugger.AvalonEdit;
using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes
@ -121,6 +122,7 @@ namespace ICSharpCode.ILSpy.TreeNodes @@ -121,6 +122,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override void Decompile(Language language, ITextOutput output, DecompilationOptions options)
{
IconBarMargin.CurrentTypeName = type.FullName;
language.DecompileType(type, output, options);
}

Loading…
Cancel
Save