Ticket #6730: backspace.patch
| File backspace.patch, 3.1 KB (added by , 14 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
12 12 import java.awt.Point; 13 13 import java.awt.Toolkit; 14 14 import java.awt.event.AWTEventListener; 15 import java.awt.event.ActionEvent; 15 16 import java.awt.event.InputEvent; 16 17 import java.awt.event.KeyEvent; 17 18 import java.awt.event.MouseEvent; … … 27 28 import java.util.Map; 28 29 import java.util.Set; 29 30 31 import javax.swing.AbstractAction; 30 32 import javax.swing.JOptionPane; 31 33 32 34 import org.openstreetmap.josm.Main; … … 78 80 private EastNorth currentMouseEastNorth; 79 81 80 82 private Shortcut extraShortcut; 81 83 private Shortcut backspaceShortcut; 84 82 85 public DrawAction(MapFrame mapFrame) { 83 86 super(tr("Draw"), "node/autonode", tr("Draw nodes"), 84 87 Shortcut.registerShortcut("mapmode:draw", tr("Mode: {0}", tr("Draw")), KeyEvent.VK_A, Shortcut.GROUP_EDIT), … … 175 178 drawHelperLine = Main.pref.getBoolean("draw.helper-line", true); 176 179 drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true); 177 180 wayIsFinished = false; 181 182 backspaceShortcut = Shortcut.registerShortcut("mapmode:backspace", tr("Backspace in Add mode"), KeyEvent.VK_BACK_SPACE, Shortcut.GROUP_EDIT); 183 Main.registerActionShortcut(new BackSpaceAction(), backspaceShortcut); 178 184 179 185 Main.map.mapView.addMouseListener(this); 180 186 Main.map.mapView.addMouseMotionListener(this); … … 195 201 Main.map.mapView.removeMouseMotionListener(this); 196 202 Main.map.mapView.removeTemporaryLayer(this); 197 203 DataSet.removeSelectionListener(this); 204 Main.unregisterActionShortcut(backspaceShortcut); 205 198 206 removeHighlighting(); 199 207 try { 200 208 Toolkit.getDefaultToolkit().removeAWTEventListener(this); … … 967 975 super.destroy(); 968 976 Main.unregisterActionShortcut(extraShortcut); 969 977 } 978 979 public static class BackSpaceAction extends AbstractAction { 980 981 @Override 982 public void actionPerformed(ActionEvent e) { 983 Main.main.undoRedo.undo(); 984 Node n=null; 985 Command lastCmd=Main.main.undoRedo.commands.peekLast(); 986 if (lastCmd==null) return; 987 for (OsmPrimitive p: lastCmd.getParticipatingPrimitives()) { 988 if (p instanceof Node) { 989 if (n==null) { 990 n=(Node) p; // found one node 991 } else { 992 // if more than 1 node were affected by previous command, 993 // we have no way to continue, so we forget about found node 994 n=null; 995 break; 996 } 997 } 998 } 999 // select last added node - maybe we will continue drawing from it 1000 if (n!=null) getCurrentDataSet().addSelected(n); 1001 } 1002 } 1003 970 1004 }
