Browse Source

Implemented saving the assembly list.

pull/1/head
Daniel Grunwald 15 years ago
parent
commit
d884ec9038
  1. 32
      ILSpy/AssemblyList.cs
  2. 17
      ILSpy/AssemblyListManager.cs
  3. 18
      ILSpy/ILSpySettings.cs

32
ILSpy/AssemblyList.cs

@ -19,10 +19,11 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Threading;
using System.Xml.Linq; using System.Xml.Linq;
using ICSharpCode.ILSpy.TreeNodes; using ICSharpCode.ILSpy.TreeNodes;
using Mono.Cecil; using Mono.Cecil;
@ -36,16 +37,43 @@ namespace ICSharpCode.ILSpy
public AssemblyList(string listName) public AssemblyList(string listName)
{ {
this.ListName = listName; this.ListName = listName;
Assemblies.CollectionChanged += Assemblies_CollectionChanged;
} }
public AssemblyList(XElement listElement) public AssemblyList(XElement listElement)
: this((string)listElement.Attribute("name"))
{ {
this.ListName = (string)listElement.Attribute("name");
foreach (var asm in listElement.Elements("Assembly")) { foreach (var asm in listElement.Elements("Assembly")) {
OpenAssembly((string)asm); 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 string ListName { get; set; }
public readonly ObservableCollection<AssemblyTreeNode> Assemblies = new ObservableCollection<AssemblyTreeNode>(); public readonly ObservableCollection<AssemblyTreeNode> Assemblies = new ObservableCollection<AssemblyTreeNode>();

17
ILSpy/AssemblyListManager.cs

@ -62,5 +62,22 @@ namespace ICSharpCode.ILSpy
else else
return new AssemblyList(listName ?? "(Default)"); 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());
});
}
} }
} }

18
ILSpy/ILSpySettings.cs

@ -63,6 +63,18 @@ namespace ICSharpCode.ILSpy
} }
public static void SaveSettings(XElement section) 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<XElement> action)
{ {
using (new MutexProtector(ConfigFileMutex)) { using (new MutexProtector(ConfigFileMutex)) {
string config = GetConfigFile(); string config = GetConfigFile();
@ -77,11 +89,7 @@ namespace ICSharpCode.ILSpy
doc = new XDocument(new XElement("ILSpy")); doc = new XDocument(new XElement("ILSpy"));
} }
doc.Root.SetAttributeValue("version", RevisionClass.Major + "." + RevisionClass.Minor + "." + RevisionClass.Build + "." + RevisionClass.Revision); doc.Root.SetAttributeValue("version", RevisionClass.Major + "." + RevisionClass.Minor + "." + RevisionClass.Build + "." + RevisionClass.Revision);
XElement existingElement = doc.Root.Element(section.Name); action(doc.Root);
if (existingElement != null)
existingElement.ReplaceWith(section);
else
doc.Root.Add(section);
doc.Save(config); doc.Save(config);
} }
} }

Loading…
Cancel
Save