Refactor right-click menu show code