Browse Source

Remove ILSpyTreeNode.Save accepting a file name, as it is currently not necessary.

Remove focused element check in SaveCommandCanExecute, because saving the text view content independently from the tree view selection is currently not supported.
pull/1550/head
Siegfried Pammer 6 years ago
parent
commit
9dd22011d6
  1. 34
      ILSpy/Controls/ExtensionMethods.cs
  2. 7
      ILSpy/MainWindow.xaml.cs
  3. 18
      ILSpy/Properties/Resources.Designer.cs
  4. 6
      ILSpy/Properties/Resources.resx
  5. 52
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  6. 9
      ILSpy/TreeNodes/ILSpyTreeNode.cs

34
ILSpy/Controls/ExtensionMethods.cs

@ -19,7 +19,6 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Markup; using System.Windows.Markup;
using System.Windows.Media;
namespace ICSharpCode.ILSpy.Controls namespace ICSharpCode.ILSpy.Controls
{ {
@ -28,39 +27,6 @@ namespace ICSharpCode.ILSpy.Controls
/// </summary> /// </summary>
public static class ExtensionMethods public static class ExtensionMethods
{ {
/// <summary>
/// Checks if the current <see cref="DependencyObject"/> is contained in the visual tree of the
/// <paramref name="dependencyObject"/> object.
/// </summary>
/// <param name="thisObject">The object to check, may be null.</param>
/// <param name="dependencyObject">The object whose visual tree will be inspected.</param>
///
/// <returns><c>true</c> if this object is contained in the visual tree of the <paramref name="dependencyObject"/>;
/// otherwise, <c>false</c>.</returns>
///
/// <exception cref="ArgumentNullException">Thrown when <paramref name="dependencyObject"/> is null.</exception>
public static bool IsInVisualTreeOf(this DependencyObject thisObject, DependencyObject dependencyObject)
{
if (dependencyObject == null) {
throw new ArgumentNullException(nameof(dependencyObject));
}
if (thisObject is null) {
return false;
}
var parent = VisualTreeHelper.GetParent(thisObject);
while (parent != null) {
if (parent == dependencyObject) {
return true;
}
parent = VisualTreeHelper.GetParent(parent);
}
return false;
}
/// <summary> /// <summary>
/// Sets the value of a dependency property on <paramref name="targetObject"/> using a markup extension. /// Sets the value of a dependency property on <paramref name="targetObject"/> using a markup extension.
/// </summary> /// </summary>

7
ILSpy/MainWindow.xaml.cs

@ -902,11 +902,6 @@ namespace ICSharpCode.ILSpy
void SaveCommandCanExecute(object sender, CanExecuteRoutedEventArgs e) void SaveCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{ {
e.Handled = true; e.Handled = true;
var focusedElement = FocusManager.GetFocusedElement(this) as DependencyObject;
if (focusedElement.IsInVisualTreeOf(TextView)) {
e.CanExecute = true;
return;
}
var selectedNodes = SelectedNodes.ToList(); var selectedNodes = SelectedNodes.ToList();
e.CanExecute = selectedNodes.Count == 1 || (selectedNodes.Count > 1 && selectedNodes.All(n => n is AssemblyTreeNode)); e.CanExecute = selectedNodes.Count == 1 || (selectedNodes.Count > 1 && selectedNodes.All(n => n is AssemblyTreeNode));
} }
@ -926,7 +921,7 @@ namespace ICSharpCode.ILSpy
if (!string.IsNullOrEmpty(selectedPath)) { if (!string.IsNullOrEmpty(selectedPath)) {
var assemblies = selectedNodes.OfType<AssemblyTreeNode>() var assemblies = selectedNodes.OfType<AssemblyTreeNode>()
.Select(n => n.LoadedAssembly) .Select(n => n.LoadedAssembly)
.Where(a => a != null).ToArray(); .Where(a => !a.HasLoadError).ToArray();
SolutionWriter.CreateSolution(TextView, selectedPath, CurrentLanguage, assemblies); SolutionWriter.CreateSolution(TextView, selectedPath, CurrentLanguage, assemblies);
} }
return; return;

18
ILSpy/Properties/Resources.Designer.cs generated

@ -303,6 +303,24 @@ namespace ICSharpCode.ILSpy.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to The directory is not empty. File will be overwritten.\r\nAre you sure you want to continue?.
/// </summary>
public static string AssemblySaveCodeDirectoryNotEmpty {
get {
return ResourceManager.GetString("AssemblySaveCodeDirectoryNotEmpty", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Project Directory not empty.
/// </summary>
public static string AssemblySaveCodeDirectoryNotEmptyTitle {
get {
return ResourceManager.GetString("AssemblySaveCodeDirectoryNotEmptyTitle", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Automatically check for updates every week. /// Looks up a localized string similar to Automatically check for updates every week.
/// </summary> /// </summary>

6
ILSpy/Properties/Resources.resx

@ -729,4 +729,10 @@
<data name="CannotAnalyzeMissingRef" xml:space="preserve"> <data name="CannotAnalyzeMissingRef" xml:space="preserve">
<value>Entity could not be resolved. Cannot analyze entities from missing assembly references. Add the missing reference and try again.</value> <value>Entity could not be resolved. Cannot analyze entities from missing assembly references. Add the missing reference and try again.</value>
</data> </data>
<data name="AssemblySaveCodeDirectoryNotEmpty" xml:space="preserve">
<value>The directory is not empty. File will be overwritten.\r\nAre you sure you want to continue?</value>
</data>
<data name="AssemblySaveCodeDirectoryNotEmptyTitle" xml:space="preserve">
<value>Project Directory not empty</value>
</data>
</root> </root>

52
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -279,44 +279,30 @@ namespace ICSharpCode.ILSpy.TreeNodes
public override bool Save(DecompilerTextView textView) public override bool Save(DecompilerTextView textView)
{ {
Language language = this.Language; Language language = this.Language;
if (string.IsNullOrEmpty(language.ProjectFileExtension)) { if (string.IsNullOrEmpty(language.ProjectFileExtension))
return false; return false;
}
SaveFileDialog dlg = new SaveFileDialog(); SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = DecompilerTextView.CleanUpName(LoadedAssembly.ShortName) + language.ProjectFileExtension; dlg.FileName = DecompilerTextView.CleanUpName(LoadedAssembly.ShortName) + language.ProjectFileExtension;
dlg.Filter = language.Name + " project|*" + language.ProjectFileExtension; dlg.Filter = language.Name + " project|*" + language.ProjectFileExtension + "|" + language.Name + " single file|*" + language.FileExtension + "|All files|*.*";
if (dlg.ShowDialog() != true) { if (dlg.ShowDialog() == true) {
return true; DecompilationOptions options = new DecompilationOptions();
} options.FullDecompilation = true;
if (dlg.FilterIndex == 1) {
var targetDirectory = Path.GetDirectoryName(dlg.FileName); options.SaveAsProjectDirectory = Path.GetDirectoryName(dlg.FileName);
var existingFiles = Directory.GetFileSystemEntries(targetDirectory); foreach (string entry in Directory.GetFileSystemEntries(options.SaveAsProjectDirectory)) {
if (!string.Equals(entry, dlg.FileName, StringComparison.OrdinalIgnoreCase)) {
if (existingFiles.Any(e => !string.Equals(e, dlg.FileName, StringComparison.OrdinalIgnoreCase))) { var result = MessageBox.Show(
var result = MessageBox.Show( Resources.AssemblySaveCodeDirectoryNotEmpty,
"The directory is not empty. File will be overwritten." + Environment.NewLine + Resources.AssemblySaveCodeDirectoryNotEmptyTitle,
"Are you sure you want to continue?", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
"Project Directory not empty", if (result == MessageBoxResult.No)
MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); return true; // don't save, but mark the Save operation as handled
if (result == MessageBoxResult.No) { break;
return true; // don't save, but mark the Save operation as handled }
}
} }
textView.SaveToDisk(language, new[] { this }, options, dlg.FileName);
} }
Save(textView, dlg.FileName);
return true;
}
public override bool Save(DecompilerTextView textView, string fileName)
{
var targetDirectory = Path.GetDirectoryName(fileName);
DecompilationOptions options = new DecompilationOptions {
FullDecompilation = true,
SaveAsProjectDirectory = targetDirectory
};
textView.SaveToDisk(Language, new[] { this }, options, fileName);
return true; return true;
} }

9
ILSpy/TreeNodes/ILSpyTreeNode.cs

@ -79,15 +79,6 @@ namespace ICSharpCode.ILSpy.TreeNodes
return false; return false;
} }
/// <summary>
/// Saves the content this node represents to the specified <paramref name="fileName"/>.
/// The file will be silently overwritten.
/// </summary>
/// <param name="textView">A reference to a <see cref="TextView.DecompilerTextView"/> instance.</param>
/// <param name="fileName">The target full path to save the content to.</param>
/// <returns><c>true</c> on success; otherwise, <c>false</c>.</returns>
public virtual bool Save(TextView.DecompilerTextView textView, string fileName) => Save(textView);
protected override void OnChildrenChanged(NotifyCollectionChangedEventArgs e) protected override void OnChildrenChanged(NotifyCollectionChangedEventArgs e)
{ {
if (e.NewItems != null) { if (e.NewItems != null) {

Loading…
Cancel
Save