Skip to content

Commit f3fc48a

Browse files
committed
add confirmation box when overwriting a vanilla file. resolves #165
1 parent 4b0ddf2 commit f3fc48a

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

Gui/ViewModels/DatTypes/BaseLocoFileViewModel.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using MsBox.Avalonia;
1+
using MsBox.Avalonia;
22
using MsBox.Avalonia.Enums;
33
using OpenLoco.Common.Logging;
4+
using OpenLoco.Dat.Data;
45
using OpenLoco.Gui.Models;
56
using ReactiveUI;
67
using ReactiveUI.Fody.Helpers;
@@ -17,7 +18,7 @@ protected BaseLocoFileViewModel(FileSystemItem currentFile, ObjectEditorModel mo
1718
Model = model;
1819

1920
ReloadCommand = ReactiveCommand.Create(Load);
20-
SaveCommand = ReactiveCommand.Create(Save);
21+
SaveCommand = ReactiveCommand.CreateFromTask(SaveWrapper);
2122
SaveAsCommand = ReactiveCommand.Create(SaveAs);
2223
DeleteLocalFileCommand = ReactiveCommand.CreateFromTask(DeleteWrapper);
2324
}
@@ -36,11 +37,27 @@ protected BaseLocoFileViewModel(FileSystemItem currentFile, ObjectEditorModel mo
3637
public abstract void Load();
3738
public abstract void Save();
3839
public abstract void SaveAs();
40+
public virtual void Delete() { }
41+
42+
async Task SaveWrapper()
43+
{
44+
if (CurrentFile is FileSystemItemObject fsio && fsio.ObjectSource is ObjectSource.LocomotionSteam or ObjectSource.LocomotionGoG)
45+
{
46+
var box = MessageBoxManager.GetMessageBoxStandard("Confirm Save", "This is a vanilla loco file - are you sure you want to overwrite it?", ButtonEnum.YesNo);
47+
var result = await box.ShowAsync();
48+
49+
if (result != ButtonResult.Yes)
50+
{
51+
return;
52+
}
53+
}
54+
55+
Save();
56+
}
3957

4058
async Task DeleteWrapper()
4159
{
42-
var box = MessageBoxManager
43-
.GetMessageBoxStandard("Confirm Delete", "Are you sure you would like to delete?", ButtonEnum.YesNo);
60+
var box = MessageBoxManager.GetMessageBoxStandard("Confirm Delete", "Are you sure you would like to delete?", ButtonEnum.YesNo);
4461
var result = await box.ShowAsync();
4562

4663
if (result == ButtonResult.Yes)
@@ -49,7 +66,6 @@ async Task DeleteWrapper()
4966
}
5067
}
5168

52-
public virtual void Delete() { }
5369

5470
public string ReloadText => CurrentFile.FileLocation == FileLocation.Local ? "Reload" : "Redownload";
5571
public string SaveText => CurrentFile.FileLocation == FileLocation.Local ? "Save" : "Download";

0 commit comments

Comments
 (0)