Created SelectionModeHandler class.

Also implemented it in MagicWandTool, replacing some of the MWT's code.