diff --git a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs index 9f6988303..46bd8f09f 100644 --- a/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs +++ b/ICSharpCode.Decompiler/Metadata/DotNetCorePathFinder.cs @@ -206,7 +206,7 @@ namespace ICSharpCode.Decompiler.Metadata } } - static string FindDotNetExeDirectory() + public static string FindDotNetExeDirectory() { string dotnetExeName = (Environment.OSVersion.Platform == PlatformID.Unix) ? "dotnet" : "dotnet.exe"; foreach (var item in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator)) { diff --git a/ILSpy/AssemblyListManager.cs b/ILSpy/AssemblyListManager.cs index 0c3404fc6..eabc5ad95 100644 --- a/ILSpy/AssemblyListManager.cs +++ b/ILSpy/AssemblyListManager.cs @@ -76,6 +76,13 @@ namespace ICSharpCode.ILSpy return CreateList(newList); } + public bool RenameList(string selectedAssemblyList, string newListName) + { + var list = DoLoadList(spySettings, selectedAssemblyList); + var newList = new AssemblyList(list, newListName); + return DeleteList(selectedAssemblyList) && CreateList(newList); + } + public const string DefaultListName = "(Default)"; /// diff --git a/ILSpy/Commands/DelegateCommand.cs b/ILSpy/Commands/DelegateCommand.cs index 4c0c033d2..7e2516b1b 100644 --- a/ILSpy/Commands/DelegateCommand.cs +++ b/ILSpy/Commands/DelegateCommand.cs @@ -7,6 +7,38 @@ using System.Windows.Input; namespace ICSharpCode.ILSpy.Commands { + public class DelegateCommand : ICommand + { + private readonly Action action; + private readonly Func canExecute; + + public event EventHandler CanExecuteChanged { + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } + } + + public DelegateCommand(Action action) + : this(action, () => true) + { + } + + public DelegateCommand(Action action, Func canExecute) + { + this.action = action; + this.canExecute = canExecute; + } + + public bool CanExecute(object parameter) + { + return canExecute(); + } + + public void Execute(object parameter) + { + action(); + } + } + public class DelegateCommand : ICommand { private readonly Action action; diff --git a/ILSpy/Properties/Resources.Designer.cs b/ILSpy/Properties/Resources.Designer.cs index 267bf70dd..d025bdfe0 100644 --- a/ILSpy/Properties/Resources.Designer.cs +++ b/ILSpy/Properties/Resources.Designer.cs @@ -285,6 +285,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Add preconfigured list.... + /// + public static string AddPreconfiguredList { + get { + return ResourceManager.GetString("AddPreconfiguredList", resourceCulture); + } + } + /// /// Looks up a localized string similar to Add shell integration. /// @@ -1388,15 +1397,6 @@ namespace ICSharpCode.ILSpy.Properties { } } - /// - /// Looks up a localized string similar to New list. - /// - public static string List { - get { - return ResourceManager.GetString("List", resourceCulture); - } - } - /// /// Looks up a localized string similar to Are you sure that you want to delete the selected assembly list?. /// @@ -1506,6 +1506,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to New list. + /// + public static string NewList { + get { + return ResourceManager.GetString("NewList", resourceCulture); + } + } + /// /// Looks up a localized string similar to Nuget Package Browser. /// @@ -1632,6 +1641,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to R_ename. + /// + public static string R_ename { + get { + return ResourceManager.GetString("R_ename", resourceCulture); + } + } + /// /// Looks up a localized string similar to Reference Name. /// @@ -1706,6 +1724,15 @@ namespace ICSharpCode.ILSpy.Properties { } } + /// + /// Looks up a localized string similar to Rename list. + /// + public static string RenameList { + get { + return ResourceManager.GetString("RenameList", resourceCulture); + } + } + /// /// Looks up a localized string similar to Reset to defaults. /// diff --git a/ILSpy/Properties/Resources.resx b/ILSpy/Properties/Resources.resx index de2f7a957..492e4619a 100644 --- a/ILSpy/Properties/Resources.resx +++ b/ILSpy/Properties/Resources.resx @@ -426,7 +426,7 @@ Create - + New list @@ -852,4 +852,13 @@ Do you want to continue? Do you want to continue? + + Add preconfigured list... + + + R_ename + + + Rename list + \ No newline at end of file diff --git a/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs b/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs index baf1e6be0..7f68a9868 100644 --- a/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs +++ b/ILSpy/ViewModels/ManageAssemblyListsViewModel.cs @@ -16,11 +16,16 @@ // 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.Collections.ObjectModel; +using System.IO; +using System.Text.RegularExpressions; using System.Windows; using System.Windows.Input; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.ILSpy.Commands; +using ICSharpCode.ILSpy.Properties; namespace ICSharpCode.ILSpy.ViewModels { @@ -31,20 +36,68 @@ namespace ICSharpCode.ILSpy.ViewModels public const string ASPDotNetMVC3List = "ASP.NET (MVC3)"; private readonly AssemblyListManager manager; + private readonly Window parent; - public ManageAssemblyListsViewModel() + public ManageAssemblyListsViewModel(Window parent) { this.manager = MainWindow.Instance.AssemblyListManager; + this.parent = parent; CreateDefaultAssemblyLists(); - NewCommand = new DelegateCommand(ExecuteNew); - CloneCommand = new DelegateCommand(ExecuteClone, CanExecuteClone); - ResetCommand = new DelegateCommand(ExecuteReset); - DeleteCommand = new DelegateCommand(ExecuteDelete, CanExecuteDelete); + NewCommand = new DelegateCommand(ExecuteNew); + CloneCommand = new DelegateCommand(ExecuteClone, CanExecuteClone); + RenameCommand = new DelegateCommand(ExecuteRename, CanExecuteRename); + ResetCommand = new DelegateCommand(ExecuteReset); + DeleteCommand = new DelegateCommand(ExecuteDelete, CanExecuteDelete); + CreatePreconfiguredAssemblyListCommand = new DelegateCommand(ExecuteCreatePreconfiguredAssemblyList); + + PreconfiguredAssemblyLists = new List(ResolvePreconfiguredAssemblyLists()); + } + + IEnumerable ResolvePreconfiguredAssemblyLists() + { + yield return new PreconfiguredAssemblyList(DotNet4List); + yield return new PreconfiguredAssemblyList(DotNet35List); + yield return new PreconfiguredAssemblyList(ASPDotNetMVC3List); + + var basePath = DotNetCorePathFinder.FindDotNetExeDirectory(); + if (basePath == null) + yield break; + + Dictionary foundVersions = new Dictionary(); + Dictionary latestRevision = new Dictionary(); + + foreach (var sdkDir in Directory.GetDirectories(Path.Combine(basePath, "shared"))) { + if (sdkDir.EndsWith(".Ref", StringComparison.OrdinalIgnoreCase)) + continue; + foreach (var versionDir in Directory.GetDirectories(sdkDir)) { + var match = Regex.Match(versionDir, @"[/\\](?[A-z0-9.]+)[/\\](?\d+\.\d)+(.(?\d+))?$"); + if (!match.Success) + continue; + string name = match.Groups["name"].Value; + int index = name.LastIndexOfAny(new[] { '/', '\\' }); + if (index >= 0) + name = name.Substring(index + 1); + string text = name + " " + match.Groups["version"].Value; + if (!latestRevision.TryGetValue(text, out int revision)) + revision = -1; + int newRevision = int.Parse(match.Groups["revision"].Value); + if (newRevision > revision) { + latestRevision[text] = newRevision; + foundVersions[text] = versionDir; + } + } + } + + foreach (var pair in foundVersions) { + yield return new PreconfiguredAssemblyList(pair.Key + "(." + latestRevision[pair.Key] + ")", pair.Value); + } } public ObservableCollection AssemblyLists => manager.AssemblyLists; + public List PreconfiguredAssemblyLists { get; } + private string selectedAssemblyList; public string SelectedAssemblyList { @@ -60,50 +113,52 @@ namespace ICSharpCode.ILSpy.ViewModels public ICommand NewCommand { get; } public ICommand CloneCommand { get; } public ICommand ResetCommand { get; } + public ICommand RenameCommand { get; } public ICommand DeleteCommand { get; } + public ICommand CreatePreconfiguredAssemblyListCommand { get; } - private void ExecuteNew(ManageAssemblyListsDialog dialog) + private void ExecuteNew() { - CreateListDialog dlg = new CreateListDialog(); - dlg.Owner = dialog; + CreateListDialog dlg = new CreateListDialog(Resources.NewList); + dlg.Owner = parent; dlg.Closing += (s, args) => { if (dlg.DialogResult == true) { - if (manager.AssemblyLists.Contains(dlg.NewListName)) { + if (manager.AssemblyLists.Contains(dlg.ListName)) { args.Cancel = true; MessageBox.Show(Properties.Resources.ListExistsAlready, null, MessageBoxButton.OK); } } }; if (dlg.ShowDialog() == true) { - manager.CreateList(new AssemblyList(dlg.NewListName)); + manager.CreateList(new AssemblyList(dlg.ListName)); } } - private bool CanExecuteClone(ManageAssemblyListsDialog _) + private bool CanExecuteClone() { return selectedAssemblyList != null; } - private void ExecuteClone(ManageAssemblyListsDialog dialog) + private void ExecuteClone() { - CreateListDialog dlg = new CreateListDialog(); - dlg.Owner = dialog; + CreateListDialog dlg = new CreateListDialog(Resources.NewList); + dlg.Owner = parent; dlg.Closing += (s, args) => { if (dlg.DialogResult == true) { - if (manager.AssemblyLists.Contains(dlg.NewListName)) { + if (manager.AssemblyLists.Contains(dlg.ListName)) { args.Cancel = true; MessageBox.Show(Properties.Resources.ListExistsAlready, null, MessageBoxButton.OK); } } }; if (dlg.ShowDialog() == true) { - manager.CloneList(SelectedAssemblyList, dlg.NewListName); + manager.CloneList(SelectedAssemblyList, dlg.ListName); } } - private void ExecuteReset(ManageAssemblyListsDialog dialog) + private void ExecuteReset() { - if (MessageBox.Show(dialog, Properties.Resources.ListsResetConfirmation, + if (MessageBox.Show(parent, Properties.Resources.ListsResetConfirmation, "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No, MessageBoxOptions.None) != MessageBoxResult.Yes) return; manager.ClearAll(); @@ -111,98 +166,191 @@ namespace ICSharpCode.ILSpy.ViewModels MainWindow.Instance.SessionSettings.ActiveAssemblyList = manager.AssemblyLists[0]; } - private void ExecuteDelete(ManageAssemblyListsDialog dialog) + private void ExecuteDelete() { - if (MessageBox.Show(dialog, Properties.Resources.ListDeleteConfirmation, + if (MessageBox.Show(parent, Properties.Resources.ListDeleteConfirmation, "ILSpy", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No, MessageBoxOptions.None) != MessageBoxResult.Yes) return; manager.DeleteList(SelectedAssemblyList); } - private bool CanExecuteDelete(ManageAssemblyListsDialog _) + private bool CanExecuteDelete() + { + return selectedAssemblyList != null; + } + + private bool CanExecuteRename() { return selectedAssemblyList != null; } + private void ExecuteRename() + { + CreateListDialog dlg = new CreateListDialog(Resources.RenameList); + dlg.Owner = parent; + dlg.Closing += (s, args) => { + if (dlg.DialogResult == true) { + if (manager.AssemblyLists.Contains(dlg.ListName)) { + args.Cancel = true; + MessageBox.Show(Properties.Resources.ListExistsAlready, null, MessageBoxButton.OK); + } + } + }; + if (dlg.ShowDialog() == true) { + manager.RenameList(selectedAssemblyList, dlg.ListName); + } + } + + private AssemblyList CreateDefaultList(string name, string path = null, string newName = null) + { + var list = new AssemblyList(newName ?? name); + switch (name) { + case DotNet4List: + AddToListFromGAC("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + AddToListFromGAC("PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + break; + case DotNet35List: + AddToListFromGAC("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + break; + case ASPDotNetMVC3List: + AddToListFromGAC("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + AddToListFromGAC("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + AddToListFromGAC("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + AddToListFromGAC("System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + AddToListFromGAC("System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + AddToListFromGAC("System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + AddToListFromGAC("System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + AddToListFromGAC("Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); + break; + case object _ when path != null: + foreach (var file in Directory.GetFiles(path, "*.dll")) { + var dllname = Path.GetFileName(file); + if (DoIncludeFile(dllname)) + AddToListFromDirectory(file); + } + break; + } + return list; + + void AddToListFromGAC(string fullName) + { + AssemblyNameReference reference = AssemblyNameReference.Parse(fullName); + string file = GacInterop.FindAssemblyInNetGac(reference); + if (file != null) + list.OpenAssembly(file); + } + + void AddToListFromDirectory(string file) + { + if (File.Exists(file)) + list.OpenAssembly(file); + } + + bool DoIncludeFile(string fileName) + { + if (fileName == "Microsoft.DiaSymReader.Native.amd64.dll") + return false; + if (fileName.EndsWith("_cor3.dll", StringComparison.OrdinalIgnoreCase)) + return false; + if (char.IsUpper(fileName[0])) + return true; + if (fileName == "netstandard.dll") + return true; + if (fileName == "mscorlib.dll") + return true; + return false; + } + } + private void CreateDefaultAssemblyLists() { if (!manager.AssemblyLists.Contains(DotNet4List)) { - AssemblyList dotnet4 = new AssemblyList(DotNet4List); - AddToList(dotnet4, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet4, "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - AddToList(dotnet4, "PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(dotnet4, "PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(dotnet4, "WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - + AssemblyList dotnet4 = CreateDefaultList(DotNet4List); if (dotnet4.assemblies.Count > 0) { manager.CreateList(dotnet4); } } if (!manager.AssemblyLists.Contains(DotNet35List)) { - AssemblyList dotnet35 = new AssemblyList(DotNet35List); - AddToList(dotnet35, "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet35, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet35, "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet35, "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet35, "System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet35, "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet35, "System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(dotnet35, "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(dotnet35, "PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(dotnet35, "WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - + AssemblyList dotnet35 = CreateDefaultList(DotNet35List); if (dotnet35.assemblies.Count > 0) { manager.CreateList(dotnet35); } } if (!manager.AssemblyLists.Contains(ASPDotNetMVC3List)) { - AssemblyList mvc = new AssemblyList(ASPDotNetMVC3List); - AddToList(mvc, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - AddToList(mvc, "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - AddToList(mvc, "System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - AddToList(mvc, "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - AddToList(mvc, "System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - AddToList(mvc, "System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); - AddToList(mvc, "System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); - AddToList(mvc, "Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); - + AssemblyList mvc = CreateDefaultList(ASPDotNetMVC3List); if (mvc.assemblies.Count > 0) { manager.CreateList(mvc); } } } - private void AddToList(AssemblyList list, string FullName) + private void ExecuteCreatePreconfiguredAssemblyList(PreconfiguredAssemblyList config) + { + CreateListDialog dlg = new CreateListDialog(Resources.AddPreconfiguredList); + dlg.Owner = parent; + dlg.Closing += (s, args) => { + if (dlg.DialogResult == true) { + if (manager.AssemblyLists.Contains(dlg.ListName)) { + args.Cancel = true; + MessageBox.Show(Properties.Resources.ListExistsAlready, null, MessageBoxButton.OK); + } + } + }; + if (dlg.ShowDialog() == true) { + var list = CreateDefaultList(config.Name, config.Path, dlg.ListName); + if (list.assemblies.Count > 0) { + manager.CreateList(list); + } + } + } + } + + public class PreconfiguredAssemblyList + { + public string Name { get; } + public string Path { get; } + + public PreconfiguredAssemblyList(string name, string path = null) { - AssemblyNameReference reference = AssemblyNameReference.Parse(FullName); - string file = GacInterop.FindAssemblyInNetGac(reference); - if (file != null) - list.OpenAssembly(file); + this.Name = name; + this.Path = path; } } } diff --git a/ILSpy/Views/CreateListDialog.xaml b/ILSpy/Views/CreateListDialog.xaml index 7c63cd9a1..208e40276 100644 --- a/ILSpy/Views/CreateListDialog.xaml +++ b/ILSpy/Views/CreateListDialog.xaml @@ -2,26 +2,24 @@ x:Class="ICSharpCode.ILSpy.CreateListDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:properties="clr-namespace:ICSharpCode.ILSpy.Properties" - xmlns:controls="clr-namespace:ICSharpCode.ILSpy.Controls" - Title="{x:Static properties:Resources.List}" Style="{DynamicResource DialogWindow}" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" Width="300" Height="150" - FocusManager.FocusedElement="{Binding ElementName=ListName}"> - - - - - - + FocusManager.FocusedElement="{Binding ElementName=ListNameBox}"> + + + + + + - + + + public partial class CreateListDialog : Window { - public CreateListDialog() + public CreateListDialog(string title) { InitializeComponent(); + this.Title = title; } private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { - okButton.IsEnabled = !string.IsNullOrWhiteSpace(ListName.Text); + okButton.IsEnabled = !string.IsNullOrWhiteSpace(ListNameBox.Text); } private void OKButton_Click(object sender, RoutedEventArgs e) { - if (!string.IsNullOrWhiteSpace(ListName.Text)) + if (!string.IsNullOrWhiteSpace(ListNameBox.Text)) { this.DialogResult = true; } } - public string NewListName + public string ListName { - get - { - return ListName.Text; - } + get => ListNameBox.Text; + set => ListNameBox.Text = value; } - } } \ No newline at end of file diff --git a/ILSpy/Views/ManageAssemblyLIstsDialog.xaml.cs b/ILSpy/Views/ManageAssemblyLIstsDialog.xaml.cs index d57384d5b..25d231700 100644 --- a/ILSpy/Views/ManageAssemblyLIstsDialog.xaml.cs +++ b/ILSpy/Views/ManageAssemblyLIstsDialog.xaml.cs @@ -17,6 +17,8 @@ // DEALINGS IN THE SOFTWARE. using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; using ICSharpCode.ILSpy.ViewModels; namespace ICSharpCode.ILSpy @@ -29,7 +31,15 @@ namespace ICSharpCode.ILSpy public ManageAssemblyListsDialog() { InitializeComponent(); - DataContext = new ManageAssemblyListsViewModel(); + DataContext = new ManageAssemblyListsViewModel(this); + } + + private void PreconfiguredAssemblyListsMenuClick(object sender, RoutedEventArgs e) + { + var menu = (ContextMenu)Resources["PreconfiguredAssemblyListsMenu"]; + menu.PlacementTarget = (Button)sender; + menu.Placement = PlacementMode.Bottom; + menu.IsOpen = true; } } } diff --git a/ILSpy/Views/ManageAssemblyListsDialog.xaml b/ILSpy/Views/ManageAssemblyListsDialog.xaml index d4b34b34b..4e796bb9d 100644 --- a/ILSpy/Views/ManageAssemblyListsDialog.xaml +++ b/ILSpy/Views/ManageAssemblyListsDialog.xaml @@ -12,6 +12,16 @@ Height="350" Width="480" FocusManager.FocusedElement="{Binding ElementName=listView}"> + + + + + + + @@ -30,10 +40,12 @@