Ignore:
Timestamp:
2011-11-26T16:58:22+01:00 (12 years ago)
Author:
stoecker
Message:

fix #6730 - patch by akks - add backspace in draw mode to undo last draw action

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r4539 r4611  
    1313import java.awt.Toolkit;
    1414import java.awt.event.AWTEventListener;
     15import java.awt.event.ActionEvent;
    1516import java.awt.event.InputEvent;
    1617import java.awt.event.KeyEvent;
     
    2829import java.util.Set;
    2930
     31import javax.swing.AbstractAction;
    3032import javax.swing.JOptionPane;
    3133
     
    7981
    8082    private Shortcut extraShortcut;
    81 
     83    private Shortcut backspaceShortcut;
     84           
    8285    public DrawAction(MapFrame mapFrame) {
    8386        super(tr("Draw"), "node/autonode", tr("Draw nodes"),
     
    176179        drawTargetHighlight = Main.pref.getBoolean("draw.target-highlight", true);
    177180        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);
    178184
    179185        Main.map.mapView.addMouseListener(this);
     
    196202        Main.map.mapView.removeTemporaryLayer(this);
    197203        DataSet.removeSelectionListener(this);
     204        Main.unregisterActionShortcut(backspaceShortcut);
     205
    198206        removeHighlighting();
    199207        try {
     
    968976        Main.unregisterActionShortcut(extraShortcut);
    969977    }
     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
    9701004}
Note: See TracChangeset for help on using the changeset viewer.