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 all 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
2 changes: 2 additions & 0 deletions src/general/base_stage/EditorComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ protected virtual void NextOrFinishClicked()
{
GUICommon.Instance.PlayButtonPressSound();

ModalManager.Instance.ClearModals();

if (OnFinish != null)
{
if (OnFinish!.Invoke(null))
Expand Down
38 changes: 31 additions & 7 deletions src/gui_common/ModalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,22 @@ public bool HideTopMostPopup()
if (popup.Exclusive && !popup.ExclusiveAllowCloseOnEscape)
return false;

// 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);
HideModal(popup);

return true;
}

/// <summary>
/// Attempt to clear all open modals.
/// </summary>
public void ClearModals()
Copy link
Member

Choose a reason for hiding this comment

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

Does the HideModal method cause a modal to be removed from the stack? If so doesn't the foreach cause a crash by continuing to iterate? Maybe instead the loop should check if the stack is empty and if not attempt to close the top most one.

If this doesn't remove the modals in the stack, then I'm still of the opinion that the name of this method is wrong and should really be something like ForceHideModals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah it doesn't remove from the stack, happy to rename it.

Copy link
Member

Choose a reason for hiding this comment

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

Alright, then the foreach doesn't crash. And yeah I'd really like it to be renamed if the method doesn't even "clear" the modals from the data structure.

{
foreach (var modal in modalStack)
{
HideModal(modal);
}
}

/// <summary>
/// Returns the top-most popup in the modal stack if there's any and it's exclusive, otherwise null.
/// </summary>
Expand All @@ -125,6 +130,25 @@ 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>
private static void HideModal(TopLevelContainer popup)
{
if (!popup.Visible)
return;

// 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
}

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