Create mode package, convert modes to use command objects

Since we got rid of onVcommand handler, we're missing the logic which finalized the action group if the command class changed. This makes undo/redo behave a bit funny in places, but I'm not entirely sure the logic was correct before either.