Fix sub-context menu child popup still being open when parent context menu gets focused again by the user

This commit is contained in:
Wojtek Figat
2022-12-20 21:11:29 +01:00
parent 84f2e652e4
commit 0dd79fe10a
2 changed files with 27 additions and 0 deletions

View File

@@ -196,6 +196,7 @@ namespace FlaxEditor.GUI.ContextMenu
desc.HasSizingFrame = false;
OnWindowCreating(ref desc);
_window = Platform.CreateWindow(ref desc);
_window.GotFocus += OnWindowGotFocus;
_window.LostFocus += OnWindowLostFocus;
// Attach to the window
@@ -353,6 +354,15 @@ namespace FlaxEditor.GUI.ContextMenu
}
}
private void OnWindowGotFocus()
{
if (_childCM != null && _window && _window.IsForegroundWindow)
{
// Hide child if user clicked over parent (do it next frame to process other events before - eg. child windows focus loss)
FlaxEngine.Scripting.InvokeOnUpdate(HideChild);
}
}
private void OnWindowLostFocus()
{
// Skip for parent menus (child should handle lost of focus)
@@ -428,6 +438,21 @@ namespace FlaxEditor.GUI.ContextMenu
return true;
}
/// <inheritdoc />
public override bool OnKeyDown(KeyboardKeys key)
{
if (base.OnKeyDown(key))
return true;
switch (key)
{
case KeyboardKeys.Escape:
Hide();
return true;
}
return false;
}
/// <inheritdoc />
public override void OnDestroy()
{

View File

@@ -193,6 +193,8 @@ namespace FlaxEditor.Modules
/// <returns>Editor window or null if cannot find any window.</returns>
public EditorWindow FindEditor(ContentItem item)
{
if (item == null)
return null;
for (int i = 0; i < Windows.Count; i++)
{
var win = Windows[i];