mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-10-02 05:06:35 -05:00
Reference-Count ViewModels for save check
only ask to save when the last viewport for a particular model closes
This commit is contained in:
@@ -32,6 +32,8 @@ namespace HavenSoft.HexManiac.Core.Models
|
||||
}
|
||||
}
|
||||
|
||||
public int ReferenceCount { get; set; }
|
||||
|
||||
public bool SpartanMode { get; set; }
|
||||
|
||||
public delegate System.Collections.Generic.IEnumerable<T> AllDelegate_<T>() where T : Runs.IFormattedRun;
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace HavenSoft.HexManiac.Core.Models {
|
||||
|
||||
byte[] RawData { get; }
|
||||
ModelCacheScope CurrentCacheScope { get; }
|
||||
int ReferenceCount { get; set; }
|
||||
bool SpartanMode { get; set; }
|
||||
bool HasChanged(int index);
|
||||
int ChangeCount { get; }
|
||||
@@ -148,6 +149,8 @@ namespace HavenSoft.HexManiac.Core.Models {
|
||||
}
|
||||
}
|
||||
|
||||
public int ReferenceCount { get; set; } = 0; // used for tracking how many ViewModels currently use this Model
|
||||
|
||||
public BaseModel(byte[] data) {
|
||||
RawData = data;
|
||||
var code = data.GetGameCode();
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
||||
ScrollRegion.DeferHeader();
|
||||
Parent = viewPort;
|
||||
Width = Parent.Width;
|
||||
viewPort.Model.ReferenceCount -= 1; // don't reference count child viewports
|
||||
}
|
||||
|
||||
public void RefreshHeaders() => ScrollRegion.UpdateDeferedHeader();
|
||||
|
||||
@@ -676,7 +676,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
||||
}
|
||||
|
||||
private void CloseExecuted(IFileSystem fileSystem) {
|
||||
if (!history.IsSaved && ownsHistory) {
|
||||
if (!history.IsSaved && Model.ReferenceCount == 1) {
|
||||
var metadata = Model.ExportMetadata(RefTable, Singletons.MetadataInfo);
|
||||
var result = fileSystem.TrySavePrompt(new LoadedFile(FileName, Model.RawData));
|
||||
if (result == null) return;
|
||||
@@ -685,6 +685,8 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
||||
history.TagAsSaved();
|
||||
}
|
||||
}
|
||||
Model.ReferenceCount -= 1;
|
||||
|
||||
Closed.Raise(this);
|
||||
}
|
||||
|
||||
@@ -1041,6 +1043,7 @@ namespace HavenSoft.HexManiac.Core.ViewModels {
|
||||
}
|
||||
PythonTool = pythonTool;
|
||||
ownsHistory = changeHistory == null;
|
||||
model.ReferenceCount += 1;
|
||||
|
||||
history = changeHistory ?? new ChangeHistory<ModelDelta>(RevertChanges);
|
||||
history.PropertyChanged += HistoryPropertyChanged;
|
||||
|
||||
Reference in New Issue
Block a user