# encoding: utf-8
# api: clicky
# type: init
# version: 0.0
# title: Cancel=Exit
# description: hooks [Cancel] button event up to plain exit; call
# category: ui
# state: buggy
# hidden: 1
# nomenu: 1
#
# The [X] cancel UI button has no default handler. Triggering an
# exception across runspaces has proven difficult. Hence this plugin
# turns it into an elaborate exit call (effectively crashing main and
# WPF thread).
#
if ($GUI) {
$plugins.before += {
Unregister-Event "Gui.Cancel"
Register-EngineEvent "Gui.Cancel" -Action {
$GUI.w.close()
$GUI.shell.Runspace.CloseAsync();
$PSHost.CloseAsync();
$GUI.shell.EndInvoke();
$PSHost.Dispose();
exit
}
}
}