From 50c11083c430c0bdb0153c4d7fde4b70bfd938bf Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Wed, 2 Mar 2011 15:57:38 +0200 Subject: [PATCH] Remove the CurrentType from IconMargin. --- .../AvalonEdit/IconBarMargin.cs | 25 +++++--------- Debugger/ILSpy.Debugger/DebuggedType.cs | 33 +++++++++++++++++++ Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj | 1 + ILSpy/TextView/DecompilerTextView.cs | 4 +-- ILSpy/TreeNodes/TypeTreeNode.cs | 3 +- 5 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 Debugger/ILSpy.Debugger/DebuggedType.cs diff --git a/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs b/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs index 35c3a0d6d..f3784859f 100644 --- a/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs +++ b/Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs @@ -19,13 +19,6 @@ namespace ILSpy.Debugger.AvalonEdit { public class IconBarMargin : AbstractMargin, IDisposable { - static TypeDefinition currentTypeName; - - public static TypeDefinition CurrentType { - get { return currentTypeName; } - set { currentTypeName = value; } - } - public IconBarMargin() { BookmarkManager.Added += delegate { InvalidateVisual(); }; @@ -64,7 +57,7 @@ namespace ILSpy.Debugger.AvalonEdit // create a dictionary line number => first bookmark Dictionary bookmarkDict = new Dictionary(); foreach (var bm in BookmarkManager.Bookmarks) { - if (CurrentType == null || bm.TypeName != CurrentType.FullName) + if (DebuggedType.CurrentType == null || bm.TypeName != DebuggedType.CurrentType.FullName) continue; if (bm is BreakpointBookmark && ((BreakpointBookmark)bm).Language != DebuggerService.CurrentDebugger.Language) @@ -126,8 +119,8 @@ namespace ILSpy.Debugger.AvalonEdit BookmarkBase result = null; foreach (BookmarkBase bm in BookmarkManager.Bookmarks) { if (bm.LineNumber == line && - CurrentType != null && - bm.TypeName == CurrentType.FullName) { + DebuggedType.CurrentType != null && + bm.TypeName == DebuggedType.CurrentType.FullName) { if (result == null || bm.ZOrder > result.ZOrder) result = bm; } @@ -196,11 +189,11 @@ namespace ILSpy.Debugger.AvalonEdit InvalidateVisual(); } - if (CurrentType == null) + if (DebuggedType.CurrentType == null) return; BreakpointBookmark bm = BookmarkManager.Bookmarks.Find( - b => b.TypeName == CurrentType.FullName && + b => b.TypeName == DebuggedType.CurrentType.FullName && b.LineNumber == GetLineFromMousePosition(e) && b is BreakpointBookmark) as BreakpointBookmark; @@ -233,22 +226,22 @@ namespace ILSpy.Debugger.AvalonEdit return; } if (e.ChangedButton == MouseButton.Left) { - if (CurrentType != null) { + if (DebuggedType.CurrentType != null) { // check if the codemappings exists for this line var storage = CodeMappings.GetStorage(DebuggerService.CurrentDebugger.Language); uint token; - var instruction = storage.GetInstructionByTypeAndLine(CurrentType.FullName, line, out token); + var instruction = storage.GetInstructionByTypeAndLine(DebuggedType.CurrentType.FullName, line, out token); if (instruction == null || instruction.ILInstructionOffset.From == 0) { - MessageBox.Show(string.Format("Missing code mappings for {0} at line {1}", CurrentType.FullName, line), + MessageBox.Show(string.Format("Missing code mappings for {0} at line {1}", DebuggedType.CurrentType.FullName, line), "Code mappings", MessageBoxButton.OK, MessageBoxImage.Information); return; } // no bookmark on the line: create a new breakpoint DebuggerService.ToggleBreakpointAt( - CurrentType.FullName, + DebuggedType.CurrentType.FullName, line, DebuggerService.CurrentDebugger.Language); } diff --git a/Debugger/ILSpy.Debugger/DebuggedType.cs b/Debugger/ILSpy.Debugger/DebuggedType.cs new file mode 100644 index 000000000..c0c0cb949 --- /dev/null +++ b/Debugger/ILSpy.Debugger/DebuggedType.cs @@ -0,0 +1,33 @@ +// 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 Mono.Cecil; + +namespace ILSpy.Debugger +{ + public static class DebuggedType + { + static TypeDefinition currentTypeName; + + public static TypeDefinition CurrentType { + get { return currentTypeName; } + set { currentTypeName = value; } + } + } +} diff --git a/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj b/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj index 3f9b4f4e5..9888ae8d5 100644 --- a/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj +++ b/Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj @@ -65,6 +65,7 @@ + diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index 2f47b517f..8713690b5 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -40,10 +40,10 @@ using ICSharpCode.AvalonEdit.Highlighting.Xshd; using ICSharpCode.Decompiler; using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.NRefactory.Documentation; +using ILSpy.Debugger; using ILSpy.Debugger.AvalonEdit; using ILSpy.Debugger.ToolTips; using Microsoft.Win32; - using TextEditorWeakEventManager = ILSpy.Debugger.AvalonEdit.TextEditorWeakEventManager; namespace ICSharpCode.ILSpy.TextView @@ -329,7 +329,7 @@ namespace ICSharpCode.ILSpy.TextView /// public void Decompile(ILSpy.Language language, IEnumerable treeNodes, DecompilationOptions options) { - IconBarMargin.CurrentType = null; + DebuggedType.CurrentType = null; // 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; diff --git a/ILSpy/TreeNodes/TypeTreeNode.cs b/ILSpy/TreeNodes/TypeTreeNode.cs index 457fdbc04..467f022a1 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; using ILSpy.Debugger.AvalonEdit; using Mono.Cecil; @@ -128,7 +129,7 @@ namespace ICSharpCode.ILSpy.TreeNodes public override void Decompile(Language language, ITextOutput output, DecompilationOptions options) { - IconBarMargin.CurrentType = type; + DebuggedType.CurrentType = type; language.DecompileType(type, output, options); }