| 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others |
|---|
| 2 | package org.openstreetmap.josm.actions; |
|---|
| 3 | |
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr; |
|---|
| 5 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht; |
|---|
| 6 | |
|---|
| 7 | import java.awt.event.ActionEvent; |
|---|
| 8 | import java.awt.event.KeyEvent; |
|---|
| 9 | import java.util.Collection; |
|---|
| 10 | |
|---|
| 11 | import org.openstreetmap.josm.Main; |
|---|
| 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
|---|
| 13 | import org.openstreetmap.josm.tools.Shortcut; |
|---|
| 14 | |
|---|
| 15 | public final class DeleteAction extends JosmAction { |
|---|
| 16 | |
|---|
| 17 | public DeleteAction() { |
|---|
| 18 | super(tr("Delete"), "dialogs/delete", tr("Delete selected objects."), |
|---|
| 19 | Shortcut.registerShortcut("system:delete", tr("Edit: {0}", tr("Delete")), KeyEvent.VK_DELETE, Shortcut.DIRECT), true); |
|---|
| 20 | putValue("help", ht("/Action/Delete")); |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | public void actionPerformed(ActionEvent e) { |
|---|
| 24 | if (!isEnabled()) |
|---|
| 25 | return; |
|---|
| 26 | if(!Main.map.mapView.isActiveLayerVisible()) |
|---|
| 27 | return; |
|---|
| 28 | org.openstreetmap.josm.actions.mapmode.DeleteAction.doActionPerformed(e); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | @Override |
|---|
| 32 | protected void updateEnabledState() { |
|---|
| 33 | if (getCurrentDataSet() == null) { |
|---|
| 34 | setEnabled(false); |
|---|
| 35 | } else { |
|---|
| 36 | updateEnabledState(getCurrentDataSet().getSelected()); |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | @Override |
|---|
| 41 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { |
|---|
| 42 | setEnabled(selection != null && !selection.isEmpty()); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|