Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing modal on "Next" pressed in editors #4486

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/general/base_stage/EditorComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ protected virtual void NextOrFinishClicked()
{
GUICommon.Instance.PlayButtonPressSound();

// If a modal won't close, don't do anything
if (!ModalManager.Instance.ClearModals())
return;

if (OnFinish != null)
{
if (OnFinish!.Invoke(null))
Expand Down
45 changes: 37 additions & 8 deletions src/gui_common/ModalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,23 @@ public bool HideTopMostPopup()

var popup = modalStack.First();

if (popup.Exclusive && !popup.ExclusiveAllowCloseOnEscape)
return false;
return HideModal(popup);
}

// This is emitted before closing to allow window using components to differentiate between "cancel" and
// "any other reason for closing" in case some logic can be simplified by handling just those two situations.
if (popup is CustomWindow dialog)
dialog.EmitSignal(nameof(CustomWindow.Cancelled));
/// <summary>
/// Attempt to clear all open modals.
/// </summary>
/// <returns>Returns true if all modals were closed, false otherwise.</returns>
public bool ClearModals()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would CloseAllOpenModals be a better name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current one is already good. This indeed clears modalStack by closing all.

{
if (modalStack.Count <= 0)
return true;

popup.Close();
popup.Notification(Control.NotificationModalClose);
for (int i = 0; i < modalStack.Count; ++i)
athariqk marked this conversation as resolved.
Show resolved Hide resolved
{
if (!HideModal(modalStack[i]))
return false;
}

return true;
}
Expand All @@ -125,6 +132,28 @@ public bool HideTopMostPopup()
return null;
}

/// <summary>
/// Attempts to hide the given modal.
/// This won't hide the modal if it's exclusive and doesn't allow closing on escape.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit is no longer true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops! Good catch :)

/// </summary>
/// <param name="popup">Modal to hide</param>
/// <returns>True if the modal was hidden</returns>
private static bool HideModal(TopLevelContainer popup)
{
if (popup.Exclusive && !popup.ExclusiveAllowCloseOnEscape)
return false;
athariqk marked this conversation as resolved.
Show resolved Hide resolved

// This is emitted before closing to allow window using components to differentiate between "cancel" and
// "any other reason for closing" in case some logic can be simplified by handling just those two situations.
if (popup is CustomWindow dialog)
dialog.EmitSignal(nameof(CustomWindow.Cancelled));

popup.Close();
popup.Notification(Control.NotificationModalClose);
athariqk marked this conversation as resolved.
Show resolved Hide resolved

return true;
}

private void UpdateModals()
{
while (demotedModals.Count > 0)
Expand Down