Is there a way to perform a specific action on open or close of a popup from within the popup? I have kind of tacked on the open part of the question out of curiosity, but I need to perform an action when someone clicks the close window x and I have no idea how to trigger that. I know somewhere there has got to be some code that is doing cleanup to make that window go away, but I can’t find that source so is there a different way to handle my own cleanup action on close without removing your close button and adding my own?
Can you use
onShutdown of the root container in the popup?
Depending on where you need the action to take place, you can use
onShutdown events (Ctrl+J on a component) if you only need to do things within the popup, or you could use an
onShutdown event along with a sendMessage() (within that shutdown script) and a message handler (Ctrl+K on a component) if you needed to perform actions outside of the popup as well.
Utilizing Perspective’s messaging functions unlock a ton of functionality–the documentation pages linked are worth the read if you want to learn a bit more.
For the View being used for the Popup, locate this View node in the Project Browser (not the
root node, but the named View node). Select this node so that it is open in the design panel. Now right-click the node and select “Configure Events”. Select the onShutdown Event, and perform the necessary logic here.
Clicking the ‘X’ does not directly call this, but when the View is removed as the Popup is closed, this logic will execute. You should be aware that this logic will execute EVERY TIME this View is closed ANYWHERE in your project - even if you do not use it as a Popup.
For example, if you use this View in an Embedded View on some other page and eventually close that page, the Embedded View will be discarded which will trigger the configured onShutdown Event.
I see. I was looking for instantiate/destruction type wording.
Is there not a session start/end type trigger then? That’s how I was using the onStartup and onShutdown. Which completely explains some of the behavior of my project now.
In the designer toolbar at the top (next to File | Edit | View) there’s Project --> Session Events
–> Startup/Shutdown, if you need to run a script whenever a session starts/ends, rather than when a component/view is opened or closed. Notably, these scripts are gateway-scoped
rather than session-scoped like most other scripts. There are some other caveats which the docs cover well.
I always forget about that. Thank you.
ALL Perspective scripts are executed on the Gateway, and so should be considered to be Gateway-scoped when examining the docs.