Ignore:
Timestamp:
2009-07-19T10:31:27+02:00 (15 years ago)
Author:
Gubaer
Message:

improved enabling/disabling of menu entries and action buttons depending on current state of JOSM (number of open layers, type of active layer, etc.)

File:
1 edited

Legend:

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

    r1308 r1808  
    88
    99import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.gui.layer.Layer;
     11import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    1012import org.openstreetmap.josm.tools.Shortcut;
    1113
    12 public class SelectAllAction extends JosmAction {
     14public class SelectAllAction extends JosmAction implements LayerChangeListener{
    1315
    1416    public SelectAllAction() {
    1517        super(tr("Select All"),"selectall", tr("Select all undeleted objects in the data layer. This selects incomplete objects too."),
    16         Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.GROUP_MENU), true);
     18                Shortcut.registerShortcut("system:selectall", tr("Edit: {0}", tr("Select All")), KeyEvent.VK_A, Shortcut.GROUP_MENU), true);
     19        Layer.listeners.add(this);
     20        refreshEnabled();
    1721    }
    1822
    1923    public void actionPerformed(ActionEvent e) {
     24        if (!isEnabled())
     25            return;
    2026        Main.ds.setSelected(Main.ds.allNonDeletedCompletePrimitives());
    2127    }
     28
     29    /**
     30     * Refreshes the enabled state
     31     *
     32     */
     33    protected void refreshEnabled() {
     34        setEnabled(Main.map != null
     35                && Main.map.mapView !=null
     36                && Main.map.mapView.getEditLayer() != null
     37        );
     38    }
     39
     40    /* ---------------------------------------------------------------------------------- */
     41    /* Interface LayerChangeListener                                                      */
     42    /* ---------------------------------------------------------------------------------- */
     43    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     44        refreshEnabled();
     45    }
     46
     47    public void layerAdded(Layer newLayer) {
     48        refreshEnabled();
     49    }
     50
     51    public void layerRemoved(Layer oldLayer) {
     52        refreshEnabled();
     53    }
    2254}
Note: See TracChangeset for help on using the changeset viewer.