From a83369a8815278e4a56fd3127fd8621a0202dd7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Karlas=CC=8C?= Date: Tue, 5 Nov 2019 19:28:17 +0100 Subject: [PATCH] Fix 988924: Some commands (save, undo) do not work if editor is detatched from IDE into its own window Problem is that when command comes in, it first goes to CocoaTextViewControl and then up NSView treeview, problem starts when migrating to GTK treeview because GtkNSViewHost is not set as it should be, after debugging why this happens it appears that `GetFocusedChild` method wasn't returning `GtkNSViewHost` as expected, upon further debugging it turns out thats because logic of drilling down GTK treeview doesn't work because `GetFocusedChild` parameter is `NSWindow` instead of `GtkWindow`. So fix is to convert `NSWindow` to `GtkWindow` and now everything works as expected. Reason we are getting `NSWindow` instead of `GtkWindow` is somewhere in `GetActiveWindow` method, but I'm not sure if its bug or not.... --- .../MonoDevelop.Components.Commands/CommandManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs index c211df9aa32..ae5ed6ac5f1 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs @@ -2364,7 +2364,8 @@ Windows.GtkWPFWidget GetFocusedWpfWidget () Gtk.Widget GetFocusedChild (Control widget) { Gtk.Container container; - + if (widget?.nativeWidget is AppKit.NSWindow window) + widget = Mac.GtkMacInterop.GetGtkWindow (window)?.Child; do { container = widget?.nativeWidget is Gtk.Container ? widget.GetNativeWidget () : null; if (container != null) { @@ -2376,7 +2377,7 @@ Gtk.Widget GetFocusedChild (Control widget) } } while (container != null); - return widget.nativeWidget is Gtk.Widget ? widget : null; + return widget?.nativeWidget is Gtk.Widget ? widget : null; } #if MAC