Ticket #22655: new_feature.diff

File new_feature.diff, 4.9 KB (added by tondahaas@…, 3 years ago)

diff file

  • src/org/openstreetmap/josm/plugins/todo/TodoDialog.java

     
    6666    private final PassAction actPass = new PassAction(model);
    6767    private final MarkAction actMark = new MarkAction(model);
    6868    private final MarkSelectedAction actMarkSelected = new MarkSelectedAction(model);
     69    private final ClearAndAddAction actClearAndAdd = new ClearAndAddAction(model);
    6970    /* The popup must be created AFTER actions */
    7071    private final TodoPopup popupMenu = new TodoPopup(lstPrimitives);
    7172
     
    7273    // CHECKSTYLE.OFF: LineLength
    7374    private final Shortcut sctPass = Shortcut.registerShortcut("subwindow:todo:pass", tr("Pass over element without marking it"), KeyEvent.VK_OPEN_BRACKET, Shortcut.DIRECT);
    7475    private final Shortcut sctMark = Shortcut.registerShortcut("subwindow:todo:mark", tr("Mark element done"), KeyEvent.VK_CLOSE_BRACKET, Shortcut.DIRECT);
     76    private final Shortcut sctAdd = Shortcut.registerShortcut("subwindow:todo:add", tr("Add elements"), KeyEvent.VK_OPEN_BRACKET, Shortcut.CTRL);
     77    private final Shortcut sctClearAndAdd = Shortcut.registerShortcut("subwindow:todo:clearandadd", tr("Clear and add elements"), KeyEvent.VK_CLOSE_BRACKET, Shortcut.CTRL);
    7578    // CHECKSTYLE.ON: LineLength
    7679
    7780    /**
     
    111114        // the add button
    112115        SideButton addButton = new SideButton(actAdd);
    113116        actAdd.updateEnabledState();
     117        MainApplication.registerActionShortcut(actAdd, sctAdd);
    114118
     119        // the clear and add button
     120        SideButton clearAndAddButton = new SideButton(actClearAndAdd);
     121        actClearAndAdd.updateEnabledState();
     122        MainApplication.registerActionShortcut(actClearAndAdd, sctClearAndAdd);
     123
    115124        // the pass button
    116125        SideButton passButton = new SideButton(actPass);
    117126        lstPrimitives.getSelectionModel().addListSelectionListener(actPass);
     
    125134        // the mark from map button
    126135        SideButton markSelectedButton = new SideButton(actMarkSelected);
    127136
    128         createLayout(lstPrimitives, true, Arrays.asList(selectButton, addButton, passButton, markButton, markSelectedButton));
     137        createLayout(lstPrimitives, true, Arrays.asList(selectButton, addButton, clearAndAddButton, passButton, markButton, markSelectedButton));
    129138    }
    130139
    131140    private static void zoom(OsmDataLayer layer) {
     
    178187    @Override
    179188    public void showNotify() {
    180189        SelectionEventManager.getInstance().addSelectionListenerForEdt(actAdd);
     190        SelectionEventManager.getInstance().addSelectionListenerForEdt(actClearAndAdd);
    181191        SelectionEventManager.getInstance().addSelectionListenerForEdt(actMarkSelected);
    182192        actAdd.updateEnabledState();
    183193    }
     
    290300        AddAction(TodoListModel model) {
    291301            this.model = model;
    292302            putValue(NAME, tr("Add"));
    293             putValue(SHORT_DESCRIPTION, tr("Add the selected items to the todo list."));
     303            putValue(SHORT_DESCRIPTION, tr("Add the selected items to the todo list. (ctrl + [)."));
    294304            new ImageProvider("dialogs", "add").getResource().attachImageIcon(this, true);
    295305            updateEnabledState();
    296306        }
     
    317327        }
    318328    }
    319329
     330    private class ClearAndAddAction extends AbstractAction implements DataSelectionListener {
     331        private final TodoListModel model;
     332
     333        ClearAndAddAction(TodoListModel model) {
     334            this.model = model;
     335            putValue(NAME, "Clear and add");
     336            putValue(SHORT_DESCRIPTION, tr("Clear list, add the selected items to the todo list and zoom first item. (ctrl + ])."));
     337            new ImageProvider("dialogs", "selectionlist").getResource().attachImageIcon(this, true);
     338            updateEnabledState();
     339        }
     340
     341        @Override
     342        public void actionPerformed(ActionEvent e) {
     343            model.clear();
     344            model.addItems(getItems());
     345            selectAndZoom(model.getSelected());
     346        }
     347
     348        /**
     349         * Update the enabled state of the action
     350         */
     351        public void updateEnabledState() {
     352            if (MainApplication.getLayerManager().getEditLayer() == null) {
     353                setEnabled(false);
     354            } else {
     355                setEnabled(!MainApplication.getLayerManager().getEditLayer().data.selectionEmpty());
     356            }
     357        }
     358
     359        @Override
     360        public void selectionChanged(SelectionChangeEvent event) {
     361            updateEnabledState();
     362        }
     363    }
     364
    320365    private class MarkSelectedAction extends AbstractAction implements DataSelectionListener {
    321366        private final TodoListModel model;
    322367
     
    514559    @Override
    515560    public void propertyChange(PropertyChangeEvent arg0) {
    516561        actAdd.updateEnabledState();
     562        actClearAndAdd.updateEnabledState();
    517563    }
    518564
    519565    @Override