Intercept Window Closing Event


I have a client view composed of a side navigation, top navigation, and swappable main windows.
In the main window the user may make changes to various parameters and then click a save button to update the changes in a database.
If the user navigates to a different main window, and with updates pending, I would like a confirmation box to pop up asking to save changes.
Currently, my solution is to add the confirmation/save script into the ‘internalFrameClosing’ event handler. However, the navigation seems to swap to the new window before my script runs so that the popup confirmation box appears on top of the new window. I’d have expected the internalFrameClosing event to fire before the window is swapped.
So then I put the script in the internalFrameDeactivated event, but the problem there is that clicking into either of the navigation windows (in empty space, not just on navigation buttons) activates the event.
It seems like a simple problem - is there a simple solution?

Additionally, but less important, It’d be nice to add a ‘Cancel’ button to the confirmation box which prevents the event from continuing.

Hi! Sorry for the way late reply.

What version of Ignition are you using? 7.7 adds visionWindowOpened and visionWindowClosed events that look like they could do the trick.

I’m trying to do the same thing: intercept the window closing event and prevent the closing of the window under certain conditions. I have accomplished this–kind of–by defining the internalFrameClosing event handler as follows:

closeWindow = system.gui.confirm(‘Really close this window?’, ‘Close Window’)
if not closeWindow:
parentWindow = str(sys.gui.getParentWindow(event))

I say “kind of” because I’m not really preventing the closing of the window; this code opens another instance of the current window. openWindow() doesn’t work because openWindow() does not open a new instance of the current window and then the system closes this window after the handler finishes. swapWindow() doesn’t work because after successfully swapping the windows, the system closes the window after the handler finishes.

openWindowInstance() kind of works because a new instance of this window gets opened and remains after the system closes the original instance after the handler finishes.

The problem is that the new instance comes up in a different position and with a different size assuming I had previously changed position and/or size of the original window. I will experiment with setting the size and position of the new instance in the event handler.

It would be much easier if there were simply a way to prevent the closing of the current window.

Resizing and positioning the window is easy. The following internalFrameClosing event handler does what I want:

closeWindow = system.gui.confirm(‘Are you sure’, ‘Close Window’)
if not closeWindow:
parentWindow = system.gui.getParentWindow(event)
x = parentWindow.x
y = parentWindow.y
width = parentWindow.width
height = parentWindow.height
newWindow = system.nav.openWindowInstance(str(parentWindow))
newWindow.setSize(width, height)
newWindow.setLocation(x, y)