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

Close organelle menu when leaving cell editor #5775

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 4 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
39 changes: 38 additions & 1 deletion src/gui_common/ModalManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ public void MakeModal(TopLevelContainer popup)
if (modalStack.Contains(popup))
return;

originalParents[popup] = popup.GetParent();
var parent = popup.GetParent();
originalParents[popup] = parent;

// Listen for when the parent is removed from the tree so the modal can be removed as well.
parent.Connect(Node.SignalName.TreeExiting, Callable.From(() => OnParentLost(popup)),
0HyperCube marked this conversation as resolved.
Show resolved Hide resolved
(uint)ConnectFlags.OneShot);

modalStack.AddToFront(popup);
modalsDirty = true;

Expand Down Expand Up @@ -272,4 +278,35 @@ private void OnModalLost(TopLevelContainer popup)

modalsDirty = true;
}

/// <summary>
/// Called when the parent of a <paramref name="popup"/> is deleted from the scene tree.
/// </summary>
/// <remarks>
/// <para>
/// If a popup is demoted but its parent is invalid, an exception will occur.
/// Deleting the modal here and removing references to it will avoid the exception.
/// </para>
/// </remarks>
private void OnParentLost(TopLevelContainer popup)
{
// Remove the original parent since the reference will now be invalid
originalParents.Remove(popup);
0HyperCube marked this conversation as resolved.
Show resolved Hide resolved

// Delete the popup
popup.Close();
modalStack.Remove(popup);
popup.QueueFree();

// Remove the popup from the demoted modals since it is now destroyed
var demotedModalsCount = demotedModals.Count;
for (int i = 0; i < demotedModalsCount; i++)
{
var item = demotedModals.Dequeue();
if (item != popup)
demotedModals.Enqueue(item);
}

modalsDirty = true;
}
}