I’d like to run a dialog form when Rhino is closed.
Currently I’m using the Rhino.RhinoApp.Closing event.
However, this takes a couple of seconds to fire after the Rhino window has been closed.
I notice Grasshoppers ‘You have unsaved documents’ dialog popping up instantaneously after the Rhino window disappears.
I tried using the Rhino.UI.RhinoEtoApp.MainWindow.Closing event but that does not seem to fire. Is there any other event that I could use?
So I would need to override the OnShutdown method like so
protected override void OnShutdown()
{
base.OnShutdown();
// Show my dialog here...
// Or maybe fire an event that triggers my dialog from somewhere else?
}
But where do I do this override, wouldn’t that mean I’d have to subclass the whole Grasshopper plugin? This seems a little over the top for the task at hand…
The strange thing is that I can’t seem to get it to work with the Rhino.UI.RhinoEtoApp.MainWindow.Closing event which I suspect to be the one that fires when the Rhino window closes. But it doesn’t…
Agreed, but does that mean that the Rhino window is only hidden during shutdown and then closed after a few seconds?
So I should go for some sort of hiding event that occurs during shutdown?
Just to get this clear: is the rhino window an Eto.Forms form or a System.Windows.Forms form?
I can get an eto form using
Rhino.UI.RhinoEtoApp.MainWindow
but this returns null
IntPtr handle = Rhino.RhinoApp.MainWindowHandle();
Control mainWindow = Control.FromHandle(handle);
I don’t know right now, not too long ago it was neither. Rhino is a C++ project and we were using MFC for the UI. The actual window was wrapped in specialist implementations of winforms to make it look as though there was a recognisable Form there.
Now however there is a bigger separation between the core and the UI, so maybe in recent versions of Rhino6 the main window is really an Eto form. I don’t know. @curtisw?
The Rhino main form is currently neither an Eto Form or Windows Form. On Windows I believe it is created via MFC, whereas on macOS, it is created via a NSWindowController in a xib file.
We have wrappers so you can use these as a parent window for Eto Forms or Windows Forms as you have noticed (e.g. RhinoEtoApp.MainWindow and RhinoApp.MainWindow), but trying to use things like the closing event (or any event) of those wrappers probably won’t work.
The best bet is to use the overrides in the plugin, or the static events such as RhinoApp.Closing, etc as mentioned.
@DavidRutten would it be possible for you to modify Grasshopper’s OnShutdown method to also fire an event (e.g. GrasshopperClosing) after calling SaveSettings that I could listen to?
Because at the moment I don’t see a way that I could go to make it work like I would like to have it…