Skip to content

Commit

Permalink
Merge pull request #877 from MrDaedra/master
Browse files Browse the repository at this point in the history
Solved issue #92
  • Loading branch information
grokys authored Mar 18, 2017
2 parents 6754bda + 2cad826 commit 88d9b58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
15 changes: 15 additions & 0 deletions src/Avalonia.Controls/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Avalonia.Platform;
using Avalonia.Styling;
using System.Collections.Generic;
using System.Linq;

namespace Avalonia.Controls
{
Expand Down Expand Up @@ -268,6 +269,10 @@ public Task<TResult> ShowDialog<TResult>()

using (BeginAutoSizing())
{
var affectedWindows = s_windows.Where(w => w.IsEnabled && w != this).ToList();
var activated = affectedWindows.Where(w => w.IsActive).FirstOrDefault();
SetIsEnabled(affectedWindows, false);

var modal = PlatformImpl.ShowDialog();
var result = new TaskCompletionSource<TResult>();

Expand All @@ -276,13 +281,23 @@ public Task<TResult> ShowDialog<TResult>()
.Subscribe(_ =>
{
modal.Dispose();
SetIsEnabled(affectedWindows, true);
activated?.Activate();
result.SetResult((TResult)_dialogResult);
});

return result.Task;
}
}

void SetIsEnabled(IEnumerable<Window> windows, bool isEnabled)
{
foreach (var window in windows)
{
window.IsEnabled = isEnabled;
}
}

/// <inheritdoc/>
void INameScope.Register(string name, object element)
{
Expand Down
26 changes: 1 addition & 25 deletions src/Windows/Avalonia.Win32/WindowImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class WindowImpl : IWindowImpl
private IntPtr _hwnd;
private IInputRoot _owner;
private bool _trackingMouse;
private bool _isActive;
private bool _decorated = true;
private double _scaling = 1;
private WindowState _showWindowState;
Expand Down Expand Up @@ -344,30 +343,9 @@ public Point Position

public virtual IDisposable ShowDialog()
{
var disabled = s_instances.Where(x => x != this && x.IsEnabled).ToList();
WindowImpl activated = null;

foreach (var window in disabled)
{
if (window._isActive)
{
activated = window;
}

window.IsEnabled = false;
}

Show();

return Disposable.Create(() =>
{
foreach (var window in disabled)
{
window.IsEnabled = true;
}

activated?.Activate();
});
return Disposable.Empty;
}

public void SetCursor(IPlatformHandle cursor)
Expand Down Expand Up @@ -414,12 +392,10 @@ protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lP
{
case UnmanagedMethods.WindowActivate.WA_ACTIVE:
case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE:
_isActive = true;
Activated?.Invoke();
break;

case UnmanagedMethods.WindowActivate.WA_INACTIVE:
_isActive = false;
Deactivated?.Invoke();
break;
}
Expand Down

0 comments on commit 88d9b58

Please sign in to comment.