1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.osm.OsmData;
|
---|
11 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * User action to select all primitives in the current dataset.
|
---|
15 | */
|
---|
16 | public class SelectAllAction extends JosmAction {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Constructs a new {@code SelectAllAction}.
|
---|
20 | */
|
---|
21 | public SelectAllAction() {
|
---|
22 | super(tr("Select All"), "selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."),
|
---|
23 | Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.CTRL), true);
|
---|
24 | putValue("help", ht("/Action/SelectAll"));
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public void actionPerformed(ActionEvent e) {
|
---|
29 | if (!isEnabled())
|
---|
30 | return;
|
---|
31 | OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
|
---|
32 | // Do not use method reference before the Java 11 migration
|
---|
33 | // Otherwise we face a compiler bug, see below:
|
---|
34 | // https://bugs.openjdk.java.net/browse/JDK-8141508
|
---|
35 | // https://bugs.openjdk.java.net/browse/JDK-8142476
|
---|
36 | // https://bugs.openjdk.java.net/browse/JDK-8191655
|
---|
37 | ds.setSelected(ds.getPrimitives(t -> t.isSelectable()));
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Refreshes the enabled state
|
---|
42 | */
|
---|
43 | @Override
|
---|
44 | protected void updateEnabledState() {
|
---|
45 | setEnabled(getLayerManager().getActiveData() != null);
|
---|
46 | }
|
---|
47 | }
|
---|