Factor menu-item creation code.