|
|
@@ -11,6 +11,8 @@ using Avalonia.Media;
|
|
|
using Avalonia.Platform;
|
|
|
using Avalonia.Styling;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Reactive.Disposables;
|
|
|
|
|
|
namespace Avalonia.Controls
|
|
|
{
|
|
|
@@ -45,7 +47,7 @@ namespace Avalonia.Controls
|
|
|
/// </summary>
|
|
|
public class Window : TopLevel, IStyleable, IFocusScope, ILayoutRoot, INameScope
|
|
|
{
|
|
|
- private static IList<Window> s_windows = new List<Window>();
|
|
|
+ private static IList<Window> s_windows = new List<Window>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Retrieves an enumeration of all Windows in the currently running application.
|
|
|
@@ -89,7 +91,7 @@ namespace Avalonia.Controls
|
|
|
TitleProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl.SetTitle((string)e.NewValue));
|
|
|
HasSystemDecorationsProperty.Changed.AddClassHandler<Window>(
|
|
|
(s, e) => s.PlatformImpl.SetSystemDecorations((bool) e.NewValue));
|
|
|
-
|
|
|
+
|
|
|
IconProperty.Changed.AddClassHandler<Window>((s, e) => s.PlatformImpl.SetIcon(((WindowIcon)e.NewValue).PlatformImpl));
|
|
|
}
|
|
|
|
|
|
@@ -180,7 +182,7 @@ namespace Avalonia.Controls
|
|
|
Size ILayoutRoot.MaxClientSize => _maxPlatformClientSize;
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
- Type IStyleable.StyleKey => typeof(Window);
|
|
|
+ Type IStyleable.StyleKey => typeof(Window);
|
|
|
|
|
|
/// <summary>
|
|
|
/// Closes the window.
|
|
|
@@ -238,7 +240,7 @@ namespace Avalonia.Controls
|
|
|
PlatformImpl.Show();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Shows the window as a dialog.
|
|
|
/// </summary>
|
|
|
@@ -263,14 +265,14 @@ namespace Avalonia.Controls
|
|
|
{
|
|
|
s_windows.Add(this);
|
|
|
|
|
|
- EnsureInitialized();
|
|
|
- LayoutManager.Instance.ExecuteInitialLayoutPass(this);
|
|
|
+ EnsureInitialized();
|
|
|
+ LayoutManager.Instance.ExecuteInitialLayoutPass(this);
|
|
|
|
|
|
using (BeginAutoSizing())
|
|
|
{
|
|
|
- var modal = PlatformImpl.ShowDialog();
|
|
|
+ var modal = GetModal();
|
|
|
var result = new TaskCompletionSource<TResult>();
|
|
|
-
|
|
|
+
|
|
|
Observable.FromEventPattern(this, nameof(Closed))
|
|
|
.Take(1)
|
|
|
.Subscribe(_ =>
|
|
|
@@ -282,6 +284,32 @@ namespace Avalonia.Controls
|
|
|
return result.Task;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private IDisposable GetModal()
|
|
|
+ {
|
|
|
+ var disabled = s_windows.Where(w => w.IsEnabled && w != this);
|
|
|
+ Window activated = null;
|
|
|
+ foreach (var window in disabled)
|
|
|
+ {
|
|
|
+ if (window.IsActive)
|
|
|
+ {
|
|
|
+ activated = window;
|
|
|
+ }
|
|
|
+
|
|
|
+ window.IsEnabled = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ PlatformImpl.Show();
|
|
|
+
|
|
|
+ return Disposable.Create(() =>
|
|
|
+ {
|
|
|
+ foreach (var window in disabled)
|
|
|
+ {
|
|
|
+ window.IsEnabled = true;
|
|
|
+ }
|
|
|
+ activated?.Activate();
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
void INameScope.Register(string name, object element)
|
|
|
@@ -307,7 +335,7 @@ namespace Avalonia.Controls
|
|
|
var sizeToContent = SizeToContent;
|
|
|
var size = ClientSize;
|
|
|
var desired = base.MeasureOverride(availableSize.Constrain(_maxPlatformClientSize));
|
|
|
-
|
|
|
+
|
|
|
switch (sizeToContent)
|
|
|
{
|
|
|
case SizeToContent.Width:
|
|
|
@@ -348,7 +376,7 @@ namespace Avalonia.Controls
|
|
|
init.BeginInit();
|
|
|
init.EndInit();
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|