Index: trunk/src/org/openstreetmap/josm/command/SelectCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/SelectCommand.java	(revision 12348)
+++ trunk/src/org/openstreetmap/josm/command/SelectCommand.java	(revision 12349)
@@ -9,5 +9,5 @@
 import java.util.Objects;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 
@@ -37,4 +37,19 @@
     }
 
+    /**
+     * Constructs a new select command.
+     * @param dataset The dataset the selection belongs to
+     * @param newSelection the primitives to select when executing the command.
+     * @since 12349
+     */
+    public SelectCommand(DataSet dataset, Collection<OsmPrimitive> newSelection) {
+        super(dataset);
+        if (newSelection == null || newSelection.isEmpty()) {
+            this.newSelection = Collections.emptySet();
+        } else {
+            this.newSelection = new HashSet<>(newSelection);
+        }
+    }
+
     @Override
     public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
@@ -44,11 +59,11 @@
     @Override
     public void undoCommand() {
-        Main.getLayerManager().getEditLayer().data.setSelected(oldSelection);
+        getAffectedDataSet().setSelected(oldSelection);
     }
 
     @Override
     public boolean executeCommand() {
-        oldSelection = Main.getLayerManager().getEditLayer().data.getSelected();
-        Main.getLayerManager().getEditLayer().data.setSelected(newSelection);
+        oldSelection = getAffectedDataSet().getSelected();
+        getAffectedDataSet().setSelected(newSelection);
         return true;
     }
