|
@@ -261,6 +261,17 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public LazyDocumentViewModel OpenFromPathLazy(string path, bool associatePath = true)
|
|
|
|
+ {
|
|
|
|
+ if (MakeExistingDocumentActiveIfOpened(path))
|
|
|
|
+ return null;
|
|
|
|
+
|
|
|
|
+ LazyDocumentViewModel lazyDoc = new LazyDocumentViewModel(path, associatePath);
|
|
|
|
+ AddLazyDocumentToTheSystem(lazyDoc);
|
|
|
|
+
|
|
|
|
+ return lazyDoc;
|
|
|
|
+ }
|
|
|
|
+
|
|
private bool IsCustomFormat(string path)
|
|
private bool IsCustomFormat(string path)
|
|
{
|
|
{
|
|
string extension = Path.GetExtension(path);
|
|
string extension = Path.GetExtension(path);
|
|
@@ -489,6 +500,13 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
return doc;
|
|
return doc;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void AddLazyDocumentToTheSystem(LazyDocumentViewModel doc)
|
|
|
|
+ {
|
|
|
|
+ Owner.DocumentManagerSubViewModel.LazyDocuments.Add(doc);
|
|
|
|
+ Owner.WindowSubViewModel.CreateNewViewport(doc);
|
|
|
|
+ Owner.WindowSubViewModel.MakeDocumentViewportActive(doc);
|
|
|
|
+ }
|
|
|
|
+
|
|
private void AddDocumentViewModelToTheSystem(DocumentViewModel doc)
|
|
private void AddDocumentViewModelToTheSystem(DocumentViewModel doc)
|
|
{
|
|
{
|
|
Owner.DocumentManagerSubViewModel.Documents.Add(doc);
|
|
Owner.DocumentManagerSubViewModel.Documents.Add(doc);
|
|
@@ -646,12 +664,6 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
{
|
|
{
|
|
var preferences = Owner.Preferences;
|
|
var preferences = Owner.Preferences;
|
|
|
|
|
|
- // Todo sure, no session saving, but shouldn't we still load backups in case of unexpected shutdown?
|
|
|
|
- // it probably should be handled elsewhere
|
|
|
|
- if (!preferences.GetPreference<bool>(PreferencesConstants.SaveSessionStateEnabled,
|
|
|
|
- PreferencesConstants.SaveSessionStateDefault))
|
|
|
|
- return;
|
|
|
|
-
|
|
|
|
var history =
|
|
var history =
|
|
preferences.GetLocalPreference<List<AutosaveHistorySession>>(PreferencesConstants.AutosaveHistory);
|
|
preferences.GetLocalPreference<List<AutosaveHistorySession>>(PreferencesConstants.AutosaveHistory);
|
|
|
|
|
|
@@ -671,11 +683,16 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (!preferences.GetPreference<bool>(PreferencesConstants.SaveSessionStateEnabled,
|
|
|
|
+ PreferencesConstants.SaveSessionStateDefault))
|
|
|
|
+ return;
|
|
|
|
+
|
|
var nextSessionFiles = preferences.GetLocalPreference<SessionFile[]>(PreferencesConstants.NextSessionFiles, []);
|
|
var nextSessionFiles = preferences.GetLocalPreference<SessionFile[]>(PreferencesConstants.NextSessionFiles, []);
|
|
List<List<AutosaveHistoryEntry>> perDocumentHistories = (
|
|
List<List<AutosaveHistoryEntry>> perDocumentHistories = (
|
|
from entry in lastSession.AutosaveEntries
|
|
from entry in lastSession.AutosaveEntries
|
|
where nextSessionFiles.Any(a =>
|
|
where nextSessionFiles.Any(a =>
|
|
- a.AutosaveFilePath == AutosaveHelper.GetAutosavePath(entry.TempFileGuid) || entry.Type != AutosaveHistoryType.OnClose)
|
|
|
|
|
|
+ a.AutosaveFilePath == AutosaveHelper.GetAutosavePath(entry.TempFileGuid) ||
|
|
|
|
+ entry.Type != AutosaveHistoryType.OnClose)
|
|
group entry by entry.TempFileGuid
|
|
group entry by entry.TempFileGuid
|
|
into entryGroup
|
|
into entryGroup
|
|
select entryGroup.OrderBy(a => a.DateTime).ToList()
|
|
select entryGroup.OrderBy(a => a.DateTime).ToList()
|
|
@@ -691,14 +708,14 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
if (lastEntry.Type != AutosaveHistoryType.OnClose)
|
|
if (lastEntry.Type != AutosaveHistoryType.OnClose)
|
|
{
|
|
{
|
|
// unexpected shutdown happened, this file wasn't saved on close, but we supposedly have a backup
|
|
// unexpected shutdown happened, this file wasn't saved on close, but we supposedly have a backup
|
|
- LoadNewest(lastEntry);
|
|
|
|
|
|
+ LoadNewest(lastEntry, true);
|
|
toLoad.RemoveAll(a =>
|
|
toLoad.RemoveAll(a =>
|
|
a.AutosaveFilePath == AutosaveHelper.GetAutosavePath(lastEntry.TempFileGuid)
|
|
a.AutosaveFilePath == AutosaveHelper.GetAutosavePath(lastEntry.TempFileGuid)
|
|
|| a.OriginalFilePath == lastEntry.OriginalPath);
|
|
|| a.OriginalFilePath == lastEntry.OriginalPath);
|
|
}
|
|
}
|
|
- else if (lastEntry.Result == AutosaveHistoryResult.SavedBackup)
|
|
|
|
|
|
+ else if (lastEntry.Result == AutosaveHistoryResult.SavedBackup || lastEntry.OriginalPath == null)
|
|
{
|
|
{
|
|
- LoadFromAutosave(lastEntry);
|
|
|
|
|
|
+ LoadFromAutosave(lastEntry, true);
|
|
toLoad.RemoveAll(a =>
|
|
toLoad.RemoveAll(a =>
|
|
a.AutosaveFilePath == AutosaveHelper.GetAutosavePath(lastEntry.TempFileGuid)
|
|
a.AutosaveFilePath == AutosaveHelper.GetAutosavePath(lastEntry.TempFileGuid)
|
|
|| a.OriginalFilePath == lastEntry.OriginalPath);
|
|
|| a.OriginalFilePath == lastEntry.OriginalPath);
|
|
@@ -736,7 +753,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
foreach (var backup in lastBackups)
|
|
foreach (var backup in lastBackups)
|
|
{
|
|
{
|
|
AutosaveHistoryEntry lastEntry = backup[^1];
|
|
AutosaveHistoryEntry lastEntry = backup[^1];
|
|
- LoadNewest(lastEntry);
|
|
|
|
|
|
+ LoadNewest(lastEntry, false);
|
|
}
|
|
}
|
|
|
|
|
|
OptionsDialog<LocalizedString> dialog = new OptionsDialog<LocalizedString>("UNEXPECTED_SHUTDOWN",
|
|
OptionsDialog<LocalizedString> dialog = new OptionsDialog<LocalizedString>("UNEXPECTED_SHUTDOWN",
|
|
@@ -754,7 +771,7 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void LoadNewest(AutosaveHistoryEntry lastEntry)
|
|
|
|
|
|
+ private void LoadNewest(AutosaveHistoryEntry lastEntry, bool lazy)
|
|
{
|
|
{
|
|
bool loadFromUserFile = false;
|
|
bool loadFromUserFile = false;
|
|
|
|
|
|
@@ -768,15 +785,22 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
|
|
|
|
if (loadFromUserFile)
|
|
if (loadFromUserFile)
|
|
{
|
|
{
|
|
- OpenFromPath(lastEntry.OriginalPath);
|
|
|
|
|
|
+ if (lazy)
|
|
|
|
+ {
|
|
|
|
+ OpenFromPathLazy(lastEntry.OriginalPath);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ OpenFromPath(lastEntry.OriginalPath);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- LoadFromAutosave(lastEntry);
|
|
|
|
|
|
+ LoadFromAutosave(lastEntry, lazy);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void LoadFromAutosave(AutosaveHistoryEntry entry)
|
|
|
|
|
|
+ private void LoadFromAutosave(AutosaveHistoryEntry entry, bool lazy)
|
|
{
|
|
{
|
|
string path = AutosaveHelper.GetAutosavePath(entry.TempFileGuid);
|
|
string path = AutosaveHelper.GetAutosavePath(entry.TempFileGuid);
|
|
if (path == null || !File.Exists(path))
|
|
if (path == null || !File.Exists(path))
|
|
@@ -785,8 +809,16 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- var document = OpenFromPath(path, false);
|
|
|
|
- document.AutosaveViewModel.SetTempFileGuidAndLastSavedPath(entry.TempFileGuid, path);
|
|
|
|
|
|
+ if (lazy)
|
|
|
|
+ {
|
|
|
|
+ var lazyDoc = OpenFromPathLazy(path, false);
|
|
|
|
+ lazyDoc.SetTempFileGuidAndLastSavedPath(entry.TempFileGuid, entry.OriginalPath);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ var document = OpenFromPath(path, false);
|
|
|
|
+ document.AutosaveViewModel.SetTempFileGuidAndLastSavedPath(entry.TempFileGuid, path);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private List<RecentlyOpenedDocument> GetRecentlyOpenedDocuments()
|
|
private List<RecentlyOpenedDocument> GetRecentlyOpenedDocuments()
|
|
@@ -803,4 +835,17 @@ internal class FileViewModel : SubViewModel<ViewModelMain>
|
|
|
|
|
|
return documents;
|
|
return documents;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void LoadLazyDocument(LazyDocumentViewModel lazyDocument)
|
|
|
|
+ {
|
|
|
|
+ var document = OpenFromPath(lazyDocument.Path, lazyDocument.AssociatePath);
|
|
|
|
+
|
|
|
|
+ if (document is null)
|
|
|
|
+ {
|
|
|
|
+ NoticeDialog.Show("FAILED_TO_OPEN_FILE", "ERROR");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ document.AutosaveViewModel.SetTempFileGuidAndLastSavedPath(lazyDocument.TempFileGuid, lazyDocument.Path);
|
|
|
|
+ }
|
|
}
|
|
}
|