Add exit handler for application

Add exit handler for close button, menu item and alt+f4.