diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs
index 1093b50b7..0bd87082d 100644
--- a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs
+++ b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs
@@ -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;
}
+ ///
+ public override bool OnKeyDown(KeyboardKeys key)
+ {
+ if (base.OnKeyDown(key))
+ return true;
+
+ switch (key)
+ {
+ case KeyboardKeys.Escape:
+ Hide();
+ return true;
+ }
+ return false;
+ }
+
///
public override void OnDestroy()
{
diff --git a/Source/Editor/Modules/WindowsModule.cs b/Source/Editor/Modules/WindowsModule.cs
index 0e341581f..2fa93a994 100644
--- a/Source/Editor/Modules/WindowsModule.cs
+++ b/Source/Editor/Modules/WindowsModule.cs
@@ -193,6 +193,8 @@ namespace FlaxEditor.Modules
/// Editor window or null if cannot find any window.
public EditorWindow FindEditor(ContentItem item)
{
+ if (item == null)
+ return null;
for (int i = 0; i < Windows.Count; i++)
{
var win = Windows[i];