Swap out application menus on focus

Now that package menus properly destroy themselves during deactivation, the window's application menu should be tracked and restored when the window gains focus.

Without this, a bunch of menus are getting destroyed when a window is closed, even if another window is still open.

Fixes #3806