OverviewAs of the latest release, we support PluginGui:BindToClose.
This allows your plugin to intercept & custom-handle user requests to close a PluginGui (e.g. when they click on the little ‘x’ in the corner of a dock widget hosting a plugin gui).
This allows you a sanity check before the user closes the GUI for your plugin, say to double-check that they really want to do this, or to give them a chance to save work.
ExampleA fairly frivolous example:
local counter = 0 print ("001 pluginGui.Enabled = ", pluginGui.Enabled) pluginGui:BindToClose(function() print ("002 pluginGui.Enabled = ", pluginGui.Enabled) counter = counter + 1 print ("Counter == ", counter) if (counter > 3) then print ("003 pluginGui.Enabled = ", pluginGui.Enabled) pluginGui.Enabled = false print ("004 pluginGui.Enabled = ", pluginGui.Enabled) end end)
Assuming pluginGui is already set to some PluginGui, this call would mean the user has to click on the ‘x’ 4 times to get the PluginGui to actually close.
CaveatsThis is not like the BindToClose on the DataModel (https://www.robloxdev.com/api-reference/function/DataModel/BindToClose), where the bound-to "Close" will happen once the callback completes.
Here, once you set a callback function like this, the plugin gui will not close on its own without an explicitly setting pluginGui.Enabled = false.
Flavor TextOh snap... I don't have anything prepared... THINK, Banks, THINK!!!! Um... Family Circus, sure, kids love that, right?
Whew... close one...