Remember all open scripts (#100)

This commit is contained in:
azakhi 2018-11-27 00:25:10 +03:00 committed by Ben Wallis
parent 124786dd0d
commit 05a994f562
3 changed files with 17 additions and 7 deletions

View File

@ -221,12 +221,12 @@ namespace Filtration.Properties {
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string LastActiveDocument {
public string LastOpenScripts {
get {
return ((string)(this["LastActiveDocument"]));
return ((string)(this["LastOpenScripts"]));
}
set {
this["LastActiveDocument"] = value;
this["LastOpenScripts"] = value;
}
}
}

View File

@ -75,7 +75,6 @@ namespace Filtration.ViewModels
if (value.IsScript)
{
_activeScriptViewModel = (IItemFilterScriptViewModel) value;
Settings.Default.LastActiveDocument = _activeScriptViewModel.Script.FilePath;
}
else if (value.IsTheme)
{

View File

@ -206,9 +206,9 @@ namespace Filtration.ViewModels
}
});
if (!string.IsNullOrWhiteSpace(Settings.Default.LastActiveDocument) && File.Exists(Settings.Default.LastActiveDocument))
if (!string.IsNullOrWhiteSpace(Settings.Default.LastOpenScripts))
{
LoadScriptAsync(Settings.Default.LastActiveDocument);
LoadScriptsAsync(Settings.Default.LastOpenScripts.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries));
}
}
@ -435,6 +435,17 @@ namespace Filtration.ViewModels
await LoadScriptAsync(filePath); // TODO: fix crash
}
private async Task LoadScriptsAsync(string[] files)
{
foreach (var file in files)
{
if (File.Exists(file))
{
await LoadScriptAsync(file);
}
}
}
private async Task LoadScriptAsync(string scriptFilename)
{
IItemFilterScriptViewModel loadedViewModel;
@ -637,7 +648,6 @@ namespace Filtration.ViewModels
private void OnCloseDocumentCommand()
{
Settings.Default.LastActiveDocument = "";
_avalonDockWorkspaceViewModel.ActiveDocument.Close();
}
@ -784,6 +794,7 @@ namespace Filtration.ViewModels
public async Task<bool> CloseAllDocumentsAsync()
{
Settings.Default.LastOpenScripts = string.Join("|", _avalonDockWorkspaceViewModel.OpenDocuments.OfType<IItemFilterScriptViewModel>().Select(sc => sc.Script.FilePath));
var openDocuments = _avalonDockWorkspaceViewModel.OpenDocuments.OfType<IEditableDocument>().ToList();
foreach (var document in openDocuments)