Skip to content

Commit

Permalink
(chocolatey#545) Mark dialog as being open when child window is opene…
Browse files Browse the repository at this point in the history
…d/closed

This commit updates the Dialog Service and the ShellView to make
sure that a dialog being open is marked correctly.

This is done to ensure that buttons for Settings and About views
are not clickable when the Advanced Installation window is open.
  • Loading branch information
AdmiringWorm committed Jan 28, 2022
1 parent e8ac317 commit d903e54
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Source/ChocolateyGui.Common.Windows/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public DialogService()
_lock = new AsyncSemaphore(1);
}

public event EventHandler<object> ChildWindowOpened;

public event EventHandler<object> ChildWindowClosed;

public ShellView ShellView { get; set; }

/// <inheritdoc />
Expand Down Expand Up @@ -161,7 +165,10 @@ public async Task<TResult> ShowChildWindowAsync<TDialogContext, TResult>(

_childWindowLoadedHandler = (sender, e) =>
{
ChildWindowOpened?.Invoke(sender, e);
var cw = (ChildWindow)sender;
cw.ClosingFinished += (senderObj, r) => ChildWindowClosed?.Invoke(senderObj, r);
if (cw.DataContext is IClosableChildWindow<TResult> vm)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using ChocolateyGui.Common.Windows.Controls.Dialogs;
using ChocolateyGui.Common.Windows.Views;
Expand All @@ -14,6 +15,10 @@ namespace ChocolateyGui.Common.Windows.Services
{
public interface IDialogService
{
event EventHandler<object> ChildWindowOpened;

event EventHandler<object> ChildWindowClosed;

ShellView ShellView { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public bool IncludePreRelease
}
}

public Utilities.NotifyTaskCompletion<ObservableCollection<SemanticVersion>> AvailableVersions
public Utilities.NotifyTaskCompletion<ObservableCollection<string>> AvailableVersions
{
get { return _availableVersions; }
set { SetPropertyValue(ref _availableVersions, value); }
Expand Down
3 changes: 3 additions & 0 deletions Source/ChocolateyGui.Common.Windows/Views/ShellView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public ShellView(
{
Environment.CurrentDirectory = Bootstrapper.ApplicationFilesPath;
}

dialogService.ChildWindowOpened += (sender, o) => IsAnyDialogOpen = true;
dialogService.ChildWindowClosed += (sender, o) => IsAnyDialogOpen = false;
}

public void CheckOperatingSystemCompatibility()
Expand Down

0 comments on commit d903e54

Please sign in to comment.