Various event binding fixes for context menus. It's still a mess, but it's not as bad of a mess.

(cherry picked from commit 081e32da6f84abea6b9adcca9c069ba38d8b1808)