Browse Source

Fix #984: Add keyboard shortcut for "analyze"

pull/1420/head
Siegfried Pammer 7 years ago
parent
commit
5946b32c2e
  1. 28
      ILSpy/Analyzers/AnalyzeCommand.cs
  2. 33
      ILSpy/Commands/ILSpyCommands.cs
  3. 5
      ILSpy/ContextMenuEntry.cs
  4. 3
      ILSpy/ILSpy.csproj
  5. 3
      ILSpy/MainWindow.xaml

28
ILSpy/Analyzers/AnalyzeContextMenuEntry.cs → ILSpy/Analyzers/AnalyzeCommand.cs

@ -18,14 +18,14 @@
using System;
using System.Linq;
using System.Windows.Input;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.Analyzers.TreeNodes;
using ICSharpCode.ILSpy.TreeNodes;
namespace ICSharpCode.ILSpy.Analyzers
{
[ExportContextMenuEntry(Header = "Analyze", Icon = "images/Search.png", Category = "Analyze", Order = 100)]
internal sealed class AnalyzeContextMenuEntry : IContextMenuEntry
[ExportContextMenuEntry(Header = "Analyze", Icon = "images/Search.png", Category = "Analyze", InputGestureText = "Ctrl+R", Order = 100)]
internal sealed class AnalyzeCommand : SimpleCommand, IContextMenuEntry
{
public bool IsVisible(TextViewContext context)
{
@ -63,5 +63,27 @@ namespace ICSharpCode.ILSpy.Analyzers
AnalyzerTreeView.Instance.Analyze(entity);
}
}
public override bool CanExecute(object parameter)
{
if (AnalyzerTreeView.Instance.IsKeyboardFocusWithin) {
return AnalyzerTreeView.Instance.SelectedItems.OfType<object>().All(n => n is IMemberTreeNode);
} else {
return MainWindow.Instance.SelectedNodes.All(n => n is IMemberTreeNode);
}
}
public override void Execute(object parameter)
{
if (AnalyzerTreeView.Instance.IsKeyboardFocusWithin) {
foreach (IMemberTreeNode node in AnalyzerTreeView.Instance.SelectedItems.OfType<IMemberTreeNode>().ToArray()) {
AnalyzerTreeView.Instance.Analyze(node.Member);
}
} else {
foreach (IMemberTreeNode node in MainWindow.Instance.SelectedNodes) {
AnalyzerTreeView.Instance.Analyze(node.Member);
}
}
}
}
}

33
ILSpy/Commands/ILSpyCommands.cs

@ -0,0 +1,33 @@
// Copyright (c) 2018 Siegfried Pammer
//
// 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.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ICSharpCode.ILSpy.Analyzers;
namespace ICSharpCode.ILSpy
{
static class ILSpyCommands
{
public static readonly AnalyzeCommand Analyze = new AnalyzeCommand();
}
}

5
ILSpy/ContextMenuEntry.cs

@ -98,7 +98,8 @@ namespace ICSharpCode.ILSpy
string Icon { get; }
string Header { get; }
string Category { get; }
string InputGestureText { get; }
double Order { get; }
}
@ -116,6 +117,7 @@ namespace ICSharpCode.ILSpy
public string Icon { get; set; }
public string Header { get; set; }
public string Category { get; set; }
public string InputGestureText { get; set; }
public double Order { get; set; }
}
@ -218,6 +220,7 @@ namespace ICSharpCode.ILSpy
}
MenuItem menuItem = new MenuItem();
menuItem.Header = entryPair.Metadata.Header;
menuItem.InputGestureText = entryPair.Metadata.InputGestureText;
if (!string.IsNullOrEmpty(entryPair.Metadata.Icon)) {
menuItem.Icon = new Image {
Width = 16,

3
ILSpy/ILSpy.csproj

@ -105,6 +105,7 @@
<Compile Include="Commands\DisassembleAllCommand.cs" />
<Compile Include="Commands\ExitCommand.cs" />
<Compile Include="Commands\CommandWrapper.cs" />
<Compile Include="Commands\ILSpyCommands.cs" />
<Compile Include="Commands\OpenListCommand.cs" />
<Compile Include="Commands\RemoveAssembliesWithLoadErrors.cs" />
<Compile Include="Commands\ShowDebugSteps.cs" />
@ -212,7 +213,7 @@
<Compile Include="TextView\EditorCommands.cs" />
<Compile Include="TextView\FoldingCommands.cs" />
<Compile Include="TextView\XmlDocRenderer.cs" />
<Compile Include="Analyzers\AnalyzeContextMenuEntry.cs" />
<Compile Include="Analyzers\AnalyzeCommand.cs" />
<Compile Include="Analyzers\Builtin\FieldAccessAnalyzer.cs" />
<Compile Include="Analyzers\TreeNodes\AnalyzedFieldTreeNode.cs" />
<Compile Include="Analyzers\AnalyzerEntityTreeNode.cs" />

3
ILSpy/MainWindow.xaml

@ -39,6 +39,9 @@
Command="Search"
Executed="SearchCommandExecuted" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Key="R" Modifiers="Control" Command="{x:Static local:ILSpyCommands.Analyze}" />
</Window.InputBindings>
<Window.TaskbarItemInfo>
<TaskbarItemInfo />
</Window.TaskbarItemInfo>

Loading…
Cancel
Save