Ticket #17401: 17401-v5.patch

File 17401-v5.patch, 2.5 KB (added by GerdP, 7 years ago)

cleaner code: switch passive mode by removing/adding listener

  • src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

     
    8989    private final SelectAction selectAction = new SelectAction();
    9090    private final SelectAndZoomAction selectAndZoomAction = new SelectAndZoomAction();
    9191
     92    private boolean passive;
     93
    9294    /**
    9395     * Constructs a new {@code CommandStackDialog}.
    9496     */
     
    550552            add(selectAndZoomAction);
    551553        }
    552554    }
     555
     556    /**
     557     * Allows to set the dialog into passive mode so that updates to the undo/redo tree are ignored
     558     * @param b true: enable passive mode, false: disable passive mode and rebuild dialog
     559     */
     560    public void setPassive(boolean b) {
     561        if (passive) {
     562            if (!b) {
     563                passive = false;
     564                UndoRedoHandler.getInstance().addCommandQueuePreciseListener(this);
     565                buildTrees();
     566            }
     567        } else {
     568            passive = b;
     569            if (passive) {
     570                UndoRedoHandler.getInstance().removeCommandQueuePreciseListener(this);
     571            }
     572        }
     573    }
    553574}
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

     
    618618        @Override
    619619        protected void realRun() throws SAXException, IOException, OsmTransferException {
    620620            ProgressMonitor monitor = getProgressMonitor();
     621            CommandStackDialog cmdStackPanel = dialogsPanel.getToggleDialog(CommandStackDialog.class);
    621622            try {
     623                if (cmdStackPanel != null && testErrors.size() > 100) {
     624                    cmdStackPanel.setPassive(true);
     625                }
    622626                monitor.setTicksCount(testErrors.size());
    623627                final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    624628                int i = 0;
     
    646650                throw new JosmRuntimeException(e);
    647651            } finally {
    648652                monitor.finishTask();
     653                if (cmdStackPanel != null) {
     654                    cmdStackPanel.setPassive(false);
     655                }
    649656            }
    650657        }
    651658    }