onShutdown Script for Docked View

I have a script that sets a property on the window and then writes to the logger so I can make sure it runs.
The script is on a view’s onShutdown event.
Every time the docked view closes (or toggles) the script does not run.
I have an “X” label on the screen that calls the toggle dock script and then when you click out of the dock, it closes as well.

When I close the screen from the designer the script runs but from a perspective session it does not.

Does anyone else see this kind of behavior?

When you close the View in the Designer, you’re closing the resource and it’s no longer “live”. When you collapse a Docked View, it only slides out of view on the web page - it is not removed from the DOM, and you’ll find that everything in the Docked View is still working and executing just out of sight. As such, the onShutdown Event will not execute.

I need to set a root custom property value back to a default value when the docked view closes. If the onShutdown event won’t execute, do you have a suggestion on how I can achieve this?

send a message when you open the dock.

I use this typically:
Edit: note this is typically in a button action that is calling the dock.

	dockId = 'dockNewProject'
	payload = {'dockId':dockId}
	system.perspective.sendMessage('msgCleanDock',payload=payload)
	system.perspective.openDock(id=dockId)

Then the dock has a message handler on it called msgCleanDock, and a parameter called dockId.
The message handler looks something like this:

	dockId = payload.get('dockId')
	if dockId == self.view.params.dockId:
		#Clean this dock
		pass
1 Like

If you’re using the default handles to expand/collapse the docked view, then you won’t be able to do this because the Docked View has no insight into whether it is expanded or collapsed, or even when that change occurs. You could implement your own buttons to manage the expanding and collapsing, but this would require a new UI piece (probably a button) in your primary view, and you’d need to guarantee the UI isn’t covered by the Docked View.

The new button would require a session property (to manage state of your property).

onClick of the expand/collapse button:

system.perspective.toggleDock("DockID")
self.session.custom.dock_root_custom_prop = "Default Value"

Your custom prop would then need to be bidirectionally bound against the session proeprty.

You could also manage this with message handlers, but it gets even more complicated.

@bschroeder , The problem with this approach is you still need a way to trigger the Handlers; the built-in dock handles will not trigger this script.

That code is run from a button action. I don’t usually use the dock action. So I script all my dock actions through a button. So open dock and send message. Seems to work well on my end.

Thanks for the suggestion. I like this approach.
I’ll call a message handler when I open the dock.
The message handler that is on the dock will do the action I need to do.