Browse Source

Auto-loading dependent assemblies shouldn't trigger saving the assembly list

This avoids saving the file a dozen times during the initial decompilation.
pull/2113/head
Daniel Grunwald 5 years ago
parent
commit
04662d7c7d
  1. 36
      ILSpy/AssemblyList.cs

36
ILSpy/AssemblyList.cs

@ -112,32 +112,38 @@ namespace ICSharpCode.ILSpy
void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {
ClearCache(); ClearCache();
// Whenever the assembly list is modified, mark it as dirty if (CollectionChangeHasEffectOnSave(e)) {
// and enqueue a task that saves it once the UI has finished modifying the assembly list. RefreshSave();
if (!dirty) { }
dirty = true; }
App.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background, static bool CollectionChangeHasEffectOnSave(NotifyCollectionChangedEventArgs e )
new Action( {
delegate { // Auto-loading dependent assemblies shouldn't trigger saving the assembly list
dirty = false; switch (e.Action) {
AssemblyListManager.SaveList(this); case NotifyCollectionChangedAction.Add:
ClearCache(); return e.NewItems.Cast<LoadedAssembly>().Any(asm => !asm.IsAutoLoaded);
}) case NotifyCollectionChangedAction.Remove:
); return e.OldItems.Cast<LoadedAssembly>().Any(asm => !asm.IsAutoLoaded);
default:
return true;
} }
} }
internal void RefreshSave() internal void RefreshSave()
{ {
// Whenever the assembly list is modified, mark it as dirty
// and enqueue a task that saves it once the UI has finished modifying the assembly list.
if (!dirty) { if (!dirty) {
dirty = true; dirty = true;
App.Current.Dispatcher.BeginInvoke( App.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background, DispatcherPriority.Background,
new Action( new Action(
delegate { delegate {
dirty = false; if (dirty) {
AssemblyListManager.SaveList(this); dirty = false;
AssemblyListManager.SaveList(this);
}
}) })
); );
} }

Loading…
Cancel
Save