From 42c2c955112a94bf510f056b0b9fa5ee766acd1c Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Sat, 12 Feb 2011 23:41:08 +0200 Subject: [PATCH] fix Bookmarks margin --- .../AvalonEdit/IconBarManager.cs | 66 ------------------- .../AvalonEdit/IconBarMargin.cs | 55 +++++++--------- .../ILSpy.Debugger/Bookmarks/BookmarkBase.cs | 8 +-- Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj | 5 +- ILSpy.sln | 28 ++++---- ILSpy/ILSpy.csproj | 1 - ILSpy/TextView/DecompilerTextView.cs | 11 +++- ILSpy/TreeNodes/TypeTreeNode.cs | 2 + 8 files changed, 55 insertions(+), 121 deletions(-) delete mode 100644 Debugger/ILSpy.Debugger/AvalonEdit/IconBarManager.cs diff --git a/Debugger/ILSpy.Debugger/AvalonEdit/IconBarManager.cs b/Debugger/ILSpy.Debugger/AvalonEdit/IconBarManager.cs deleted file mode 100644 index d0e11b678..000000000 --- a/Debugger/ILSpy.Debugger/AvalonEdit/IconBarManager.cs +++ /dev/null @@ -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 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; - } -} diff --git a/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs b/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs index dca94d67a..4df9182b9 100644 --- a/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs +++ b/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs @@ -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 /// 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 TextView textView = this.TextView; if (textView != null && textView.VisualLinesValid) { // create a dictionary line number => first bookmark - Dictionary bookmarkDict = new Dictionary(); - foreach (IBookmark bm in manager.Bookmarks) { + Dictionary bookmarkDict = new Dictionary(); + 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 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 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(); } diff --git a/Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs b/Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs index 6f62a356d..1b28e5fec 100644 --- a/Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs +++ b/Debugger/ILSpy.Debugger/Bookmarks/BookmarkBase.cs @@ -81,7 +81,7 @@ namespace ILSpy.Debugger.Bookmarks protected virtual void RemoveMark() { - IconBarManager.Instance.Bookmarks.Remove(this); + } /// @@ -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; } diff --git a/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj b/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj index 073bc8e0b..d714bc1b7 100644 --- a/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj +++ b/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj @@ -55,7 +55,6 @@ - @@ -80,7 +79,9 @@ Code - + + + diff --git a/ILSpy.sln b/ILSpy.sln index 279b1b8c8..40407ff69 100644 --- a/ILSpy.sln +++ b/ILSpy.sln @@ -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 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 diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index ef75736e5..d36b56a97 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -221,6 +221,5 @@ ICSharpCode.TreeView - \ No newline at end of file diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index c4af363d4..752aadd17 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -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 DefinitionLookup definitionLookup; CancellationTokenSource currentCancellationTokenSource; + IconBarMargin iconMargin; + #region Constructor public DecompilerTextView() { @@ -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 /// public void Decompile(ILSpy.Language language, IEnumerable 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 } ShowOutput(output); } + finally { + // repaint bookmarks + iconMargin.InvalidateVisual(); + } }); } diff --git a/ILSpy/TreeNodes/TypeTreeNode.cs b/ILSpy/TreeNodes/TypeTreeNode.cs index 791e5e318..98dc59de5 100644 --- a/ILSpy/TreeNodes/TypeTreeNode.cs +++ b/ILSpy/TreeNodes/TypeTreeNode.cs @@ -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 public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { + IconBarMargin.CurrentTypeName = type.FullName; language.DecompileType(type, output, options); }