|
1 | 1 | using System; |
| 2 | +using System.ComponentModel; |
2 | 3 | using System.Windows; |
3 | 4 | using System.Windows.Controls; |
| 5 | +using Wpf.Ui.Common; |
4 | 6 | using Wpf.Ui.Controls; |
| 7 | +using Clipboard = System.Windows.Clipboard; |
5 | 8 |
|
6 | 9 | namespace Cosmos.Build.Builder.Views |
7 | 10 | { |
8 | 11 | public partial class MainWindow : UiWindow |
9 | 12 | { |
10 | 13 | public bool AppShutdown = true; |
| 14 | + |
| 15 | + public bool AllTasksCompleted; |
| 16 | + |
11 | 17 | public MainWindow() |
12 | 18 | { |
13 | 19 | InitializeComponent(); |
14 | | - Loaded += (sender, args) => |
15 | | - { |
16 | | - Wpf.Ui.Appearance.Watcher.Watch(this, Wpf.Ui.Appearance.BackgroundType.Mica, true); |
17 | | - }; |
| 20 | + |
| 21 | + Loaded += (_, _) => Wpf.Ui.Appearance.Watcher.Watch(this); |
18 | 22 | } |
19 | 23 |
|
20 | 24 | private void SectionTextCopyHandler(object sender, System.Windows.Input.MouseButtonEventArgs e) |
21 | 25 | { |
22 | 26 | Clipboard.SetText(((TextBlock)sender).Text); |
23 | 27 | } |
| 28 | + |
| 29 | + protected override void OnClosing(CancelEventArgs e) |
| 30 | + { |
| 31 | + base.OnClosing(e); |
| 32 | + |
| 33 | + if (!AllTasksCompleted) |
| 34 | + { |
| 35 | + e.Cancel = true; |
| 36 | + |
| 37 | + Wpf.Ui.Controls.MessageBox messageBox = new() |
| 38 | + { |
| 39 | + Content = "You're about to close the builder, however tasks are still running. Do you wish to continue?", |
| 40 | + SizeToContent = SizeToContent.Width, |
| 41 | + ButtonLeftAppearance = ControlAppearance.Secondary, |
| 42 | + ButtonLeftName = "Yes", |
| 43 | + ButtonRightAppearance = ControlAppearance.Primary, |
| 44 | + ButtonRightName = "No" |
| 45 | + }; |
| 46 | + messageBox.ButtonLeftClick += (_, _) => |
| 47 | + { |
| 48 | + messageBox.Close(); |
| 49 | + Application.Current.Dispatcher.Invoke(() => Application.Current?.MainWindow?.Close()); |
| 50 | + }; |
| 51 | + messageBox.ButtonRightClick += (_, _) => messageBox.Close(); |
| 52 | + messageBox.ShowDialog(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
24 | 56 | protected override void OnClosed(EventArgs e) |
25 | 57 | { |
26 | 58 | base.OnClosed(e); |
|
0 commit comments