소스 검색

Loading window when background thread is busy

Equbuxu 3 년 전
부모
커밋
5f498f58a9

+ 13 - 1
src/PixiEditorPrototype/Models/ActionAccumulator.cs

@@ -1,6 +1,8 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Windows;
+using System.Windows.Threading;
 using ChunkyImageLib.DataHolders;
 using PixiEditor.ChangeableDocument.Actions;
 using PixiEditor.ChangeableDocument.Actions.Undo;
@@ -47,6 +49,13 @@ internal class ActionAccumulator
         if (executing || queuedActions.Count == 0)
             return;
         executing = true;
+        DispatcherTimer busyTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(2000) };
+        busyTimer.Tick += (_, _) =>
+        {
+            busyTimer.Stop();
+            document.Busy = true;
+        };
+        busyTimer.Start();
 
         while (queuedActions.Count > 0)
         {
@@ -97,6 +106,9 @@ internal class ActionAccumulator
             }
         }
 
+        busyTimer.Stop();
+        if (document.Busy)
+            document.Busy = false;
         executing = false;
     }
 

+ 12 - 0
src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs

@@ -127,6 +127,18 @@ internal class DocumentViewModel : INotifyPropertyChanged
         }
     }
 
+    private bool busy = false;
+
+    public bool Busy
+    {
+        get => busy;
+        set
+        {
+            busy = value;
+            RaisePropertyChanged(nameof(Busy));
+        }
+    }
+
     public StructureMemberViewModel? SelectedStructureMember => FindFirstSelectedMember();
 
     public Guid GuidValue { get; } = Guid.NewGuid();

+ 12 - 0
src/PixiEditorPrototype/Views/MainWindow.xaml

@@ -799,6 +799,18 @@
                                 MouseUpCommand="{Binding ElementName=window, Path=DataContext.MouseUpCommand}"
                                 Tag="Second" />
                         </Border>
+                        <Grid
+                            Grid.ColumnSpan="2"
+                            Background="#BB000000"
+                            Visibility="{Binding Busy, Converter={StaticResource BoolToVisibilityConverter}}">
+                            <TextBlock
+                                Foreground="White"
+                                HorizontalAlignment="Center"
+                                VerticalAlignment="Center"
+                                FontSize="20">
+                                Loading...
+                            </TextBlock>
+                        </Grid>
                     </Grid>
                 </DataTemplate>
             </TabControl.ContentTemplate>