ISubCompilerVM.Unload()

To save settings when swapping off a compiler VM
This commit is contained in:
Justin Swanson 2019-11-16 17:09:13 -06:00
parent 6d07c4be87
commit 2e9f222648
5 changed files with 21 additions and 10 deletions

View File

@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using ReactiveUI.Fody.Helpers;
using System;
using System.Collections.Generic;
@ -58,7 +58,6 @@ namespace Wabbajack
public class ModlistInstallationSettings
{
public string InstallationLocation { get; set; }
public string StagingLocation { get; set; }
public string DownloadLocation { get; set; }
}

View File

@ -59,6 +59,13 @@ namespace Wabbajack
return null;
}
})
// Unload old VM
.Pairwise()
.Do(pair =>
{
pair.Previous?.Unload();
})
.Select(p => p.Current)
.ToProperty(this, nameof(this.Compiler));
// Let sub VM determine what settings we're displaying and when

View File

@ -13,5 +13,6 @@ namespace Wabbajack
IReactiveCommand BeginCommand { get; }
bool Compiling { get; }
ModlistSettingsEditorVM ModlistSettings { get; }
void Unload();
}
}

View File

@ -16,6 +16,8 @@ namespace Wabbajack
{
public class MO2CompilerVM : ViewModel, ISubCompilerVM
{
private readonly MO2CompilationSettings settings;
private readonly ObservableAsPropertyHelper<string> _Mo2Folder;
public string Mo2Folder => _Mo2Folder.Value;
@ -132,19 +134,14 @@ namespace Wabbajack
.ToProperty(this, nameof(this.Compiling));
// Load settings
var settings = parent.MWVM.Settings.Compiler.MO2Compilation;
this.settings = parent.MWVM.Settings.Compiler.MO2Compilation;
this.ModlistLocation.TargetPath = settings.LastCompiledProfileLocation;
if (!string.IsNullOrWhiteSpace(settings.DownloadLocation))
{
this.DownloadLocation.TargetPath = settings.DownloadLocation;
}
parent.MWVM.Settings.SaveSignal
.Subscribe(_ =>
{
settings.DownloadLocation = this.DownloadLocation.TargetPath;
settings.LastCompiledProfileLocation = this.ModlistLocation.TargetPath;
this.ModlistSettings?.Save();
})
.Subscribe(_ => Unload())
.DisposeWith(this.CompositeDisposable);
// Load custom modlist settings per MO2 profile
@ -195,8 +192,13 @@ namespace Wabbajack
}
})
.DisposeWith(this.CompositeDisposable);
}
public void Unload()
{
settings.DownloadLocation = this.DownloadLocation.TargetPath;
settings.LastCompiledProfileLocation = this.ModlistLocation.TargetPath;
this.ModlistSettings?.Save();
}
}
}

View File

@ -15,5 +15,7 @@ namespace Wabbajack
public bool Compiling => throw new NotImplementedException();
public ModlistSettingsEditorVM ModlistSettings => throw new NotImplementedException();
public void Unload() => throw new NotImplementedException();
}
}