mid: Refactor common code in diagram context menu