Browse Source

Fix #2686: Introduce ToolPaneModel.AssociatedCommand to allow overriding Window-menu action.

pull/2693/head
Siegfried Pammer 3 years ago
parent
commit
44aa41d933
  1. 17
      ILSpy/Analyzers/AnalyzeCommand.cs
  2. 4
      ILSpy/MainWindow.xaml.cs
  3. 1
      ILSpy/ViewModels/AnalyzerPaneModel.cs
  4. 2
      ILSpy/ViewModels/ToolPaneModel.cs

17
ILSpy/Analyzers/AnalyzeCommand.cs

@ -58,24 +58,30 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -58,24 +58,30 @@ namespace ICSharpCode.ILSpy.Analyzers
public void Execute(TextViewContext context)
{
AnalyzerTreeView analyzerTreeView = MainWindow.Instance.AnalyzerTreeView;
if (analyzerTreeView == null)
{
return;
}
if (context.SelectedTreeNodes != null)
{
foreach (IMemberTreeNode node in context.SelectedTreeNodes)
{
MainWindow.Instance.AnalyzerTreeView.Analyze(node.Member);
analyzerTreeView.Analyze(node.Member);
}
}
else if (context.Reference != null && context.Reference.Reference is IEntity entity)
{
MainWindow.Instance.AnalyzerTreeView.Analyze(entity);
analyzerTreeView.Analyze(entity);
}
}
public override bool CanExecute(object parameter)
{
if (MainWindow.Instance.AnalyzerTreeView.IsKeyboardFocusWithin)
AnalyzerTreeView analyzerTreeView = MainWindow.Instance.AnalyzerTreeView;
if (analyzerTreeView != null && analyzerTreeView.IsKeyboardFocusWithin)
{
return MainWindow.Instance.AnalyzerTreeView.SelectedItems.OfType<object>().All(n => n is IMemberTreeNode);
return analyzerTreeView.SelectedItems.OfType<object>().All(n => n is IMemberTreeNode);
}
else
{
@ -85,7 +91,8 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -85,7 +91,8 @@ namespace ICSharpCode.ILSpy.Analyzers
public override void Execute(object parameter)
{
if (MainWindow.Instance.AnalyzerTreeView.IsKeyboardFocusWithin)
AnalyzerTreeView analyzerTreeView = MainWindow.Instance.AnalyzerTreeView;
if (analyzerTreeView != null && analyzerTreeView.IsKeyboardFocusWithin)
{
foreach (IMemberTreeNode node in MainWindow.Instance.AnalyzerTreeView.SelectedItems.OfType<IMemberTreeNode>().ToArray())
{

4
ILSpy/MainWindow.xaml.cs

@ -89,7 +89,7 @@ namespace ICSharpCode.ILSpy @@ -89,7 +89,7 @@ namespace ICSharpCode.ILSpy
public AnalyzerTreeView AnalyzerTreeView {
get {
return FindResource("AnalyzerTreeView") as AnalyzerTreeView;
return !IsLoaded ? null : FindResource("AnalyzerTreeView") as AnalyzerTreeView;
}
}
@ -428,7 +428,7 @@ namespace ICSharpCode.ILSpy @@ -428,7 +428,7 @@ namespace ICSharpCode.ILSpy
MenuItem CreateMenuItem(ToolPaneModel pane)
{
MenuItem menuItem = new MenuItem();
menuItem.Command = new ToolPaneCommand(pane.ContentId);
menuItem.Command = pane.AssociatedCommand ?? new ToolPaneCommand(pane.ContentId);
menuItem.Header = pane.Title;
menuItem.Tag = pane;
var shortcutKey = pane.ShortcutKey;

1
ILSpy/ViewModels/AnalyzerPaneModel.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.ILSpy.ViewModels @@ -31,6 +31,7 @@ namespace ICSharpCode.ILSpy.ViewModels
ContentId = PaneContentId;
Title = Properties.Resources.Analyze;
ShortcutKey = new KeyGesture(Key.R, ModifierKeys.Control);
AssociatedCommand = ILSpyCommands.Analyze;
}
public override DataTemplate Template => (DataTemplate)MainWindow.Instance.FindResource("AnalyzerPaneTemplate");

2
ILSpy/ViewModels/ToolPaneModel.cs

@ -34,5 +34,7 @@ namespace ICSharpCode.ILSpy.ViewModels @@ -34,5 +34,7 @@ namespace ICSharpCode.ILSpy.ViewModels
public KeyGesture ShortcutKey { get; protected set; }
public string Icon { get; protected set; }
public ICommand AssociatedCommand { get; set; }
}
}

Loading…
Cancel
Save