diff --git a/ILSpy/AssemblyList.cs b/ILSpy/AssemblyList.cs index 83bc06c1c..73e8c9c10 100644 --- a/ILSpy/AssemblyList.cs +++ b/ILSpy/AssemblyList.cs @@ -19,10 +19,11 @@ using System; using System.Collections.Concurrent; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.IO; using System.Linq; +using System.Windows.Threading; using System.Xml.Linq; - using ICSharpCode.ILSpy.TreeNodes; using Mono.Cecil; @@ -36,16 +37,43 @@ namespace ICSharpCode.ILSpy public AssemblyList(string listName) { this.ListName = listName; + Assemblies.CollectionChanged += Assemblies_CollectionChanged; } public AssemblyList(XElement listElement) + : this((string)listElement.Attribute("name")) { - this.ListName = (string)listElement.Attribute("name"); foreach (var asm in listElement.Elements("Assembly")) { OpenAssembly((string)asm); } + this.Dirty = false; // OpenAssembly() sets dirty, so reset it since we just loaded... + } + + public XElement Save() + { + return new XElement( + "List", + new XAttribute("name", this.ListName), + Assemblies.Select(asm => new XElement("Assembly", asm.FileName)) + ); + } + + void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + this.Dirty = true; + App.Current.Dispatcher.BeginInvoke( + DispatcherPriority.Normal, + new Action( + delegate { + if (this.Dirty) { + this.Dirty = false; + AssemblyListManager.SaveList(this); + } + }) + ); } + public bool Dirty { get; set; } public string ListName { get; set; } public readonly ObservableCollection Assemblies = new ObservableCollection(); diff --git a/ILSpy/AssemblyListManager.cs b/ILSpy/AssemblyListManager.cs index 7787f6855..f17822216 100644 --- a/ILSpy/AssemblyListManager.cs +++ b/ILSpy/AssemblyListManager.cs @@ -62,5 +62,22 @@ namespace ICSharpCode.ILSpy else return new AssemblyList(listName ?? "(Default)"); } + + public static void SaveList(AssemblyList list) + { + ILSpySettings.Update( + delegate (XElement root) { + XElement doc = root.Element("AssemblyLists"); + if (doc == null) { + doc = new XElement("AssemblyLists"); + root.Add(doc); + } + XElement listElement = doc.Elements("List").FirstOrDefault(e => (string)e.Attribute("name") == list.ListName); + if (listElement != null) + listElement.ReplaceWith(list.Save()); + else + doc.Add(list.Save()); + }); + } } } diff --git a/ILSpy/ILSpySettings.cs b/ILSpy/ILSpySettings.cs index 45930181a..4c159ff10 100644 --- a/ILSpy/ILSpySettings.cs +++ b/ILSpy/ILSpySettings.cs @@ -63,6 +63,18 @@ namespace ICSharpCode.ILSpy } public static void SaveSettings(XElement section) + { + Update( + delegate (XElement root) { + XElement existingElement = root.Element(section.Name); + if (existingElement != null) + existingElement.ReplaceWith(section); + else + root.Add(section); + }); + } + + public static void Update(Action action) { using (new MutexProtector(ConfigFileMutex)) { string config = GetConfigFile(); @@ -77,11 +89,7 @@ namespace ICSharpCode.ILSpy doc = new XDocument(new XElement("ILSpy")); } doc.Root.SetAttributeValue("version", RevisionClass.Major + "." + RevisionClass.Minor + "." + RevisionClass.Build + "." + RevisionClass.Revision); - XElement existingElement = doc.Root.Element(section.Name); - if (existingElement != null) - existingElement.ReplaceWith(section); - else - doc.Root.Add(section); + action(doc.Root); doc.Save(config); } }