Browse Source

Enable the save code command only when appropriate

pull/1550/head
dymanoid 6 years ago
parent
commit
864672c07c
  1. 1
      ILSpy/MainWindow.xaml
  2. 13
      ILSpy/MainWindow.xaml.cs

1
ILSpy/MainWindow.xaml

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
Executed="RefreshCommandExecuted" />
<CommandBinding
Command="Save"
CanExecute="SaveCommandExecutedCanExecute"
Executed="SaveCommandExecuted" />
<CommandBinding
Command="BrowseBack"

13
ILSpy/MainWindow.xaml.cs

@ -38,6 +38,7 @@ using ICSharpCode.Decompiler.Documentation; @@ -38,6 +38,7 @@ using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation;
using ICSharpCode.ILSpy.Controls;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
using ICSharpCode.TreeView;
@ -898,6 +899,18 @@ namespace ICSharpCode.ILSpy @@ -898,6 +899,18 @@ namespace ICSharpCode.ILSpy
decompilationTask = decompilerTextView.DecompileAsync(this.CurrentLanguage, this.SelectedNodes, new DecompilationOptions() { TextViewState = state });
}
private void SaveCommandExecutedCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.Handled = true;
var focusedElement = FocusManager.GetFocusedElement(this) as DependencyObject;
if (focusedElement.IsInVisualTreeOf(TextView)) {
e.CanExecute = true;
return;
}
var selectedNodes = SelectedNodes.ToArray();
e.CanExecute = selectedNodes.Length == 1 || Array.TrueForAll(selectedNodes, n => n is AssemblyTreeNode);
}
void SaveCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
if (this.SelectedNodes.Count() == 1) {

Loading…
Cancel
Save