Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions OpenUtau/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private ObservableCollectionExtended<MenuItemViewModel> openRecentMenuItems
private ObservableCollectionExtended<MenuItemViewModel> openTemplatesMenuItems
= new ObservableCollectionExtended<MenuItemViewModel>();

// view will set this to the real AskIfSaveAndContinue implementation
public Func<Task<bool>>? AskIfSaveAndContinue { get; set; }

public MainWindowViewModel() {
PlaybackViewModel = new PlaybackViewModel();
TracksViewModel = new TracksViewModel();
Expand All @@ -92,8 +95,22 @@ public MainWindowViewModel() {
Directory.CreateDirectory(PathManager.Inst.TemplatesPath);
TemplateFiles.AddRange(Directory.GetFiles(PathManager.Inst.TemplatesPath, "*.ustx")
.Select(file => new RecentFileInfo(file)));
OpenRecentCommand = ReactiveCommand.Create<string>(OpenRecent);
OpenTemplateCommand = ReactiveCommand.Create<string>(OpenTemplate);

// create async commands that consult the view's save prompt
OpenRecentCommand = ReactiveCommand.CreateFromTask<string>(async file => {
if (!DocManager.Inst.ChangesSaved && AskIfSaveAndContinue != null) {
if (!await AskIfSaveAndContinue()) return;
}
OpenRecent(file);
});

OpenTemplateCommand = ReactiveCommand.CreateFromTask<string>(async file => {
if (!DocManager.Inst.ChangesSaved && AskIfSaveAndContinue != null) {
if (!await AskIfSaveAndContinue()) return;
}
OpenTemplate(file);
});

PartDeleteCommand = ReactiveCommand.Create<UPart>(part => {
TracksViewModel.DeleteSelectedParts();
});
Expand Down
5 changes: 4 additions & 1 deletion OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ public MainWindow() {
Log.Information("Creating main window.");
InitializeComponent();
Log.Information("Initialized main window component.");
DataContext = viewModel = new MainWindowViewModel();
DataContext = viewModel = new MainWindowViewModel {
// give the viewmodel a way to prompt/save using the view's existing method
AskIfSaveAndContinue = AskIfSaveAndContinue
};

viewModel.NewProject();
viewModel.AddTempoChangeCmd = ReactiveCommand.Create<int>(tick => AddTempoChange(tick));
Expand Down
Loading