Ticket #12335: updateEnabledState.patch

File updateEnabledState.patch, 6.4 KB (added by kolesar, 7 years ago)

patch for comment 5

  • src/org/openstreetmap/josm/actions/AutoScaleAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AutoScaleAction.java b/src/org/openstreetmap/josm/actions/AutoScaleAction.java
    index 6b4d5ef..f4ec85f 100644
    a b public class AutoScaleAction extends JosmAction { 
    220220     * @return the first selected layer in the layer list dialog
    221221     */
    222222    protected Layer getFirstSelectedLayer() {
     223        if (Main.main.getActiveLayer() == null)
     224            return null;
    223225        List<Layer> layers = LayerListDialog.getInstance().getModel().getSelectedLayers();
    224226        if (layers.isEmpty())
    225227            return null;
    public class AutoScaleAction extends JosmAction { 
    245247            }
    246248            break;
    247249        case "layer":
    248             if (Main.main.getActiveLayer() == null)
    249                 return null;
    250250            // try to zoom to the first selected layer
    251251            Layer l = getFirstSelectedLayer();
    252252            if (l == null)
    public class AutoScaleAction extends JosmAction { 
    289289            if (lastZoomTime > 0 && System.currentTimeMillis() - lastZoomTime > Main.pref.getLong("zoom.bounds.reset.time", 10*1000)) {
    290290                lastZoomTime = -1;
    291291            }
    292             DataSet dataset = Main.main.getCurrentDataSet();
     292            DataSet dataset = getCurrentDataSet();
    293293            if (dataset != null) {
    294294                List<DataSource> dataSources = new ArrayList<>(dataset.getDataSources());
    295295                int s = dataSources.size();
    public class AutoScaleAction extends JosmAction { 
    322322            setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty());
    323323            break;
    324324        case "layer":
    325             if (!Main.isDisplayingMapView() || Main.map.mapView.getAllLayersAsList().isEmpty()) {
    326                 setEnabled(false);
    327             } else {
    328                 // FIXME: should also check for whether a layer is selected in the layer list dialog
    329                 setEnabled(true);
    330             }
     325            setEnabled(getFirstSelectedLayer() != null);
    331326            break;
    332327        case "conflict":
    333328            setEnabled(Main.map != null && Main.map.conflictDialog.getSelectedConflict() != null);
    334329            break;
     330        case "download":
     331            setEnabled(getCurrentDataSet() != null && getCurrentDataSet().getDataSources().size()>0);
     332            break;
    335333        case "problem":
    336334            setEnabled(Main.map != null && Main.map.validatorDialog.getSelectedError() != null);
    337335            break;
    public class AutoScaleAction extends JosmAction { 
    413411                    oldFrame.validatorDialog.removeTreeSelectionListener(validatorSelectionListener);
    414412                }
    415413            }
     414            updateEnabledState();
    416415        }
    417416    }
    418417}
  • src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    diff --git a/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java b/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
    index 972ebcb..286ef70 100644
    a b public final class OrthogonalizeAction extends JosmAction { 
    598598        }
    599599    }
    600600
    601     /**
    602      * Don't check, if the current selection is suited for orthogonalization.
    603      * Instead, show a usage dialog, that explains, why it cannot be done.
    604      */
    605601    @Override
    606602    protected void updateEnabledState() {
    607         setEnabled(getCurrentDataSet() != null);
     603        setEnabled(getCurrentDataSet() != null && !getCurrentDataSet().getSelected().isEmpty());
     604    }
     605
     606    @Override
     607    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
     608        setEnabled(selection != null && !selection.isEmpty());
    608609    }
    609610}
  • src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java b/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
    index d78347b..db1768c 100644
    a b public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh 
    17911791
    17921792        @Override
    17931793        protected void updateEnabledState() {
    1794             setEnabled(Main.main != null && Main.main.hasEditLayer());
     1794            setEnabled(Main.map != null && Main.map.mapMode instanceof DrawAction);
    17951795        }
     1796
     1797
    17961798    }
    17971799}
  • src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java b/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
    index e811caf..0e017a4 100644
    a b public class ExtrudeAction extends MapMode implements MapViewPaintable, KeyPress 
    201201
    202202        @Override
    203203        protected void updateEnabledState() {
    204             setEnabled(Main.main != null && Main.main.hasEditLayer());
     204            setEnabled(Main.map != null && Main.map.mapMode instanceof ExtrudeAction);
    205205        }
    206206    }
    207207
  • src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java
    index 9ce1179..a9845eb 100644
    a b public final class TaggingPresetSearchPrimitiveDialog extends ExtendedDialog { 
    3535         * Constructs a new {@link TaggingPresetSearchPrimitiveDialog.Action}.
    3636         */
    3737        public Action() {
    38             super(tr("Search for objects by preset"), "dialogs/search", tr("Show preset search dialog"),
     38            super(tr("Search for objects by preset..."), "dialogs/search", tr("Show preset search dialog"),
    3939                    Shortcut.registerShortcut("preset:search-objects", tr("Search for objects by preset"), KeyEvent.VK_F3, Shortcut.SHIFT),
    4040                    false);
    4141            putValue("toolbar", "presets/search-objects");
    public final class TaggingPresetSearchPrimitiveDialog extends ExtendedDialog { 
    4848                TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
    4949            }
    5050        }
     51
     52        @Override
     53        protected void updateEnabledState() {
     54            setEnabled(getEditLayer() != null);
     55        }
    5156    }
    5257
    5358    /**