Add more hooks to ImageJ1's quitting routine

DO NOT MERGE YET.

Still needs unit tests.