Browse Source

Use MEF for debugger controls; Modify the export command attribute for menuitems.

pull/191/merge
Eusebiu Marcu 16 years ago
parent
commit
f687b0fc76
  1. 2
      Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs
  2. 18
      Debugger/ILSpy.Debugger/AvalonEdit/TextMarkerService.cs
  3. 3
      Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj
  4. 1
      ILSpy/App.xaml.cs
  5. 8
      ILSpy/Commands/DebuggerCommands.cs
  6. 9
      ILSpy/ExportCommandAttribute.cs
  7. 5
      ILSpy/MainWindow.xaml.cs
  8. 28
      ILSpy/TextView/DecompilerTextView.cs

2
Debugger/ILSpy.Debugger/AvalonEdit/IconBarMargin.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
@ -17,6 +18,7 @@ using Mono.Cecil;
namespace ILSpy.Debugger.AvalonEdit namespace ILSpy.Debugger.AvalonEdit
{ {
[Export("IconMargin"), PartCreationPolicy(CreationPolicy.Shared)]
public class IconBarMargin : AbstractMargin, IDisposable public class IconBarMargin : AbstractMargin, IDisposable
{ {
public IconBarMargin() public IconBarMargin()

18
Debugger/ILSpy.Debugger/AvalonEdit/TextMarkerService.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
@ -18,20 +19,23 @@ namespace ILSpy.Debugger.AvalonEdit
/// <summary> /// <summary>
/// Handles the text markers for a code editor. /// Handles the text markers for a code editor.
/// </summary> /// </summary>
[Export("TextMarkerService"), PartCreationPolicy(CreationPolicy.Shared)]
public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService public sealed class TextMarkerService : DocumentColorizingTransformer, IBackgroundRenderer, ITextMarkerService
{ {
readonly TextEditor codeEditor; TextEditor codeEditor;
TextSegmentCollection<TextMarker> markers = new TextSegmentCollection<TextMarker>(); TextSegmentCollection<TextMarker> markers = new TextSegmentCollection<TextMarker>();
public TextMarkerService(TextEditor codeEditor) public TextMarkerService()
{ {
if (codeEditor == null)
throw new ArgumentNullException("codeEditor");
this.codeEditor = codeEditor;
BookmarkManager.Added += new BookmarkEventHandler(BookmarkManager_Added); BookmarkManager.Added += new BookmarkEventHandler(BookmarkManager_Added);
BookmarkManager.Removed += new BookmarkEventHandler(BookmarkManager_Removed); BookmarkManager.Removed += new BookmarkEventHandler(BookmarkManager_Removed);
} }
public TextEditor CodeEditor {
get { return codeEditor; }
set { codeEditor = value; }
}
void BookmarkManager_Removed(object sender, BookmarkEventArgs e) void BookmarkManager_Removed(object sender, BookmarkEventArgs e)
{ {

3
Debugger/ILSpy.Debugger/ILSpy.Debugger.csproj

@ -38,6 +38,9 @@
<RequiredTargetFramework>3.0</RequiredTargetFramework> <RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.Composition">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>

1
ILSpy/App.xaml.cs

@ -46,6 +46,7 @@ namespace ICSharpCode.ILSpy
var catalog = new AggregateCatalog(); var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
catalog.Catalogs.Add(new DirectoryCatalog(".", "*.Plugin.dll")); catalog.Catalogs.Add(new DirectoryCatalog(".", "*.Plugin.dll"));
catalog.Catalogs.Add(new DirectoryCatalog(".", "*.Debugger.dll"));
compositionContainer = new CompositionContainer(catalog); compositionContainer = new CompositionContainer(catalog);

8
ILSpy/Commands/DebuggerCommands.cs

@ -104,6 +104,9 @@ namespace ICSharpCode.ILSpy.Commands
var items = menuItems.OfType<MenuItem>().Where(m => (m.Header as string) == "_Debugger"); var items = menuItems.OfType<MenuItem>().Where(m => (m.Header as string) == "_Debugger");
foreach (var item in items.First().Items.OfType<MenuItem>()) { foreach (var item in items.First().Items.OfType<MenuItem>()) {
string header = (string)item.Header; string header = (string)item.Header;
if (header.StartsWith("Remove")) continue;
if (header.StartsWith("Attach") || header.StartsWith("Debug")) if (header.StartsWith("Attach") || header.StartsWith("Debug"))
item.IsEnabled = enable; item.IsEnabled = enable;
else else
@ -165,6 +168,7 @@ namespace ICSharpCode.ILSpy.Commands
MenuIcon = "ILSpy.Debugger;component/Images/ContinueDebugging.png", MenuIcon = "ILSpy.Debugger;component/Images/ContinueDebugging.png",
MenuCategory = "Debugger1", MenuCategory = "Debugger1",
Header = "Continue debugging", Header = "Continue debugging",
IsEnabled = false,
MenuOrder = 1)] MenuOrder = 1)]
internal sealed class ContinueDebuggingCommand : DebuggerCommands internal sealed class ContinueDebuggingCommand : DebuggerCommands
{ {
@ -179,6 +183,7 @@ namespace ICSharpCode.ILSpy.Commands
MenuIcon = "ILSpy.Debugger;component/Images/StepInto.png", MenuIcon = "ILSpy.Debugger;component/Images/StepInto.png",
MenuCategory = "Debugger1", MenuCategory = "Debugger1",
Header = "Step into", Header = "Step into",
IsEnabled = false,
MenuOrder = 2)] MenuOrder = 2)]
internal sealed class StepIntoCommand : DebuggerCommands internal sealed class StepIntoCommand : DebuggerCommands
{ {
@ -193,6 +198,7 @@ namespace ICSharpCode.ILSpy.Commands
MenuIcon = "ILSpy.Debugger;component/Images/StepOver.png", MenuIcon = "ILSpy.Debugger;component/Images/StepOver.png",
MenuCategory = "Debugger1", MenuCategory = "Debugger1",
Header = "Step over", Header = "Step over",
IsEnabled = false,
MenuOrder = 3)] MenuOrder = 3)]
internal sealed class StepOverCommand : DebuggerCommands internal sealed class StepOverCommand : DebuggerCommands
{ {
@ -207,6 +213,7 @@ namespace ICSharpCode.ILSpy.Commands
MenuIcon = "ILSpy.Debugger;component/Images/StepOut.png", MenuIcon = "ILSpy.Debugger;component/Images/StepOut.png",
MenuCategory = "Debugger1", MenuCategory = "Debugger1",
Header = "Step out", Header = "Step out",
IsEnabled = false,
MenuOrder = 4)] MenuOrder = 4)]
internal sealed class StepOutCommand : DebuggerCommands internal sealed class StepOutCommand : DebuggerCommands
{ {
@ -220,6 +227,7 @@ namespace ICSharpCode.ILSpy.Commands
[ExportMainMenuCommand(Menu = "_Debugger", [ExportMainMenuCommand(Menu = "_Debugger",
MenuCategory = "Debugger1", MenuCategory = "Debugger1",
Header = "_Detach from running application", Header = "_Detach from running application",
IsEnabled = false,
MenuOrder = 5)] MenuOrder = 5)]
internal sealed class DetachCommand : DebuggerCommands internal sealed class DetachCommand : DebuggerCommands
{ {

9
ILSpy/ExportCommandAttribute.cs

@ -42,6 +42,8 @@ namespace ICSharpCode.ILSpy
string Menu { get; } string Menu { get; }
string MenuCategory { get; } string MenuCategory { get; }
bool IsEnabled { get; }
double MenuOrder { get; } double MenuOrder { get; }
} }
@ -49,6 +51,8 @@ namespace ICSharpCode.ILSpy
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
public class ExportMainMenuCommandAttribute : ExportAttribute public class ExportMainMenuCommandAttribute : ExportAttribute
{ {
bool isEnabled = true;
public ExportMainMenuCommandAttribute() public ExportMainMenuCommandAttribute()
: base("MainMenuCommand", typeof(ICommand)) : base("MainMenuCommand", typeof(ICommand))
{ {
@ -58,6 +62,11 @@ namespace ICSharpCode.ILSpy
public string Header { get; set; } public string Header { get; set; }
public string Menu { get; set; } public string Menu { get; set; }
public string MenuCategory { get; set; } public string MenuCategory { get; set; }
public bool IsEnabled {
get { return isEnabled; }
set { isEnabled = value; }
}
public double MenuOrder { get; set; } public double MenuOrder { get; set; }
} }
#endregion #endregion

5
ILSpy/MainWindow.xaml.cs

@ -176,6 +176,9 @@ namespace ICSharpCode.ILSpy
Source = Images.LoadImage(entry.Value, entry.Metadata.MenuIcon) Source = Images.LoadImage(entry.Value, entry.Metadata.MenuIcon)
}; };
} }
menuItem.IsEnabled = entry.Metadata.IsEnabled;
topLevelMenuItem.Items.Add(menuItem); topLevelMenuItem.Items.Add(menuItem);
} }
} }
@ -421,7 +424,7 @@ namespace ICSharpCode.ILSpy
void RefreshCommandExecuted(object sender, ExecutedRoutedEventArgs e) void RefreshCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{ {
if (!System.Diagnostics.Debugger.IsAttached) { if (!DebuggerService.CurrentDebugger.IsDebugging) {
e.Handled = true; e.Handled = true;
var path = GetPathForNode(treeView.SelectedItem as SharpTreeNode); var path = GetPathForNode(treeView.SelectedItem as SharpTreeNode);
ShowAssemblyList(assemblyListManager.LoadList(ILSpySettings.Load(), assemblyList.ListName)); ShowAssemblyList(assemblyListManager.LoadList(ILSpySettings.Load(), assemblyList.ListName));

28
ILSpy/TextView/DecompilerTextView.cs

@ -65,8 +65,11 @@ namespace ICSharpCode.ILSpy.TextView
DefinitionLookup definitionLookup; DefinitionLookup definitionLookup;
CancellationTokenSource currentCancellationTokenSource; CancellationTokenSource currentCancellationTokenSource;
IconBarMargin iconMargin; [Import("IconMargin")]
TextMarkerService textMarkerService; IconBarMargin iconMargin = null;
[Import("TextMarkerService")]
TextMarkerService textMarkerService = null;
#region Constructor #region Constructor
public DecompilerTextView() public DecompilerTextView()
@ -82,6 +85,7 @@ namespace ICSharpCode.ILSpy.TextView
}); });
InitializeComponent(); InitializeComponent();
this.referenceElementGenerator = new ReferenceElementGenerator(this.JumpToReference, this.IsLink); this.referenceElementGenerator = new ReferenceElementGenerator(this.JumpToReference, this.IsLink);
textEditor.TextArea.TextView.ElementGenerators.Add(referenceElementGenerator); textEditor.TextArea.TextView.ElementGenerators.Add(referenceElementGenerator);
this.uiElementGenerator = new UIElementGenerator(); this.uiElementGenerator = new UIElementGenerator();
@ -90,19 +94,23 @@ namespace ICSharpCode.ILSpy.TextView
textEditor.TextArea.TextView.MouseHover += TextViewMouseHover; textEditor.TextArea.TextView.MouseHover += TextViewMouseHover;
textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped; textEditor.TextArea.TextView.MouseHoverStopped += TextViewMouseHoverStopped;
// wire the events
TextEditorWeakEventManager.MouseHover.AddListener(textEditor, TextEditorListener.Instance);
TextEditorWeakEventManager.MouseHoverStopped.AddListener(textEditor, TextEditorListener.Instance);
TextEditorWeakEventManager.MouseDown.AddListener(textEditor, TextEditorListener.Instance);
textEditor.TextArea.TextView.VisualLinesChanged += (s, e) => iconMargin.InvalidateVisual();
this.Loaded += new RoutedEventHandler(DecompilerTextView_Loaded);
}
void DecompilerTextView_Loaded(object sender, RoutedEventArgs e)
{
// add marker service & margin // add marker service & margin
textMarkerService = new TextMarkerService(textEditor); textMarkerService.CodeEditor = textEditor;
textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService); textEditor.TextArea.TextView.BackgroundRenderers.Add(textMarkerService);
textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService); textEditor.TextArea.TextView.LineTransformers.Add(textMarkerService);
iconMargin = new IconBarMargin();
textEditor.TextArea.LeftMargins.Add(iconMargin); textEditor.TextArea.LeftMargins.Add(iconMargin);
// wire the mouse events
TextEditorWeakEventManager.MouseHover.AddListener(textEditor, TextEditorListener.Instance);
TextEditorWeakEventManager.MouseHoverStopped.AddListener(textEditor, TextEditorListener.Instance);
TextEditorWeakEventManager.MouseDown.AddListener(textEditor, TextEditorListener.Instance);
textEditor.TextArea.TextView.VisualLinesChanged += (s, e) => iconMargin.InvalidateVisual();
} }
#endregion #endregion

Loading…
Cancel
Save