mirror of
https://onedev.site.tesses.net/crosslang/crosslangdevstudio
synced 2026-02-08 09:15:45 +00:00
Get way further
This commit is contained in:
@@ -1,21 +1,59 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CrossLangDevStudio.Messages;
|
||||
using CrossLangDevStudio.ViewModels;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using Tabalonia.Controls;
|
||||
|
||||
namespace CrossLangDevStudio.Views;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private async Task CloseWindowAsync(WindowClosingEventArgs e, MainWindowViewModel vm)
|
||||
{
|
||||
var box = MessageBoxManager
|
||||
.GetMessageBoxStandard("Save?", $"You have unsaved work do you want to save?",
|
||||
ButtonEnum.YesNoCancel, MsBox.Avalonia.Enums.Icon.Question);
|
||||
|
||||
switch (await box.ShowWindowDialogAsync(this))
|
||||
{
|
||||
case ButtonResult.Yes:
|
||||
vm.SaveAll();
|
||||
break;
|
||||
case ButtonResult.Cancel:
|
||||
e.Cancel = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (Design.IsDesignMode)
|
||||
return;
|
||||
this.Closing += (sender, e) =>
|
||||
{
|
||||
if (this.DataContext is MainWindowViewModel vm)
|
||||
{
|
||||
if (vm.HasUnsaved)
|
||||
{
|
||||
//thanks https://github.com/AvaloniaUI/Avalonia/issues/4810#issuecomment-704372304
|
||||
using (var source = new CancellationTokenSource())
|
||||
{
|
||||
CloseWindowAsync(e, vm).ContinueWith(e => source.Cancel(), TaskScheduler.FromCurrentSynchronizationContext());
|
||||
Dispatcher.UIThread.MainLoop(source.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Whenever 'Send(new PurchaseAlbumMessage())' is called, invoke this callback on the MainWindow instance:
|
||||
WeakReferenceMessenger.Default.Register<MainWindow, NewProjectMessage>(this, static (w, m) =>
|
||||
@@ -27,6 +65,7 @@ public partial class MainWindow : Window
|
||||
};
|
||||
// Show dialog window and reply with returned AlbumViewModel or null when the dialog is closed.
|
||||
m.Reply(dialog.ShowDialog<string?>(w));
|
||||
|
||||
});
|
||||
WeakReferenceMessenger.Default.Register<MainWindow, InstallPackageMessage>(this, static (w, m) =>
|
||||
{
|
||||
@@ -42,6 +81,13 @@ public partial class MainWindow : Window
|
||||
m.Reply(w);
|
||||
}
|
||||
);
|
||||
|
||||
WeakReferenceMessenger.Default.Register<MainWindow, PublishMessage>(this, static (w, m) =>
|
||||
{
|
||||
var dialog = new PublishDialogView
|
||||
{
|
||||
DataContext = new PublishDialogViewModel(m.Path)
|
||||
};
|
||||
m.Reply(dialog.ShowDialog(w));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user