Changeset 16509 in josm


Ignore:
Timestamp:
2020-05-27T11:16:39+02:00 (6 weeks ago)
Author:
GerdP
Message:

see #19296: Actions should avoid to install listeners which are not needed

  • either don't call installAdapters() or overwrite listenToSelectionChange()
  • partly reverts previous changes so that installAdapters() is not overwritten

One has to be careful because installAdapters() also calls initEnabledState()

Location:
trunk/src/org/openstreetmap/josm
Files:
36 edited

Legend:

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

    r15744 r16509  
    298298
    299299    @Override
     300    protected boolean listenToSelectionChange() {
     301        return false;
     302    }
     303
     304    @Override
    300305    protected void updateEnabledState() {
    301306        setEnabled(!info.isBlacklisted());
  • trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java

    r15053 r16509  
    8282
    8383    @Override
     84    protected boolean listenToSelectionChange() {
     85        return false;
     86    }
     87
     88    @Override
    8489    protected void updateEnabledState() {
    8590        setEnabled(getLayerManager().getEditLayer() != null);
  • trunk/src/org/openstreetmap/josm/actions/ChangesetManagerToggleAction.java

    r16505 r16509  
    1212
    1313import org.openstreetmap.josm.gui.dialogs.changeset.ChangesetCacheManager;
     14import org.openstreetmap.josm.tools.ImageProvider;
    1415import org.openstreetmap.josm.tools.Shortcut;
    1516
     
    2627    public ChangesetManagerToggleAction() {
    2728        super(tr("Changeset Manager"),
    28               "dialogs/changeset/changesetmanager",
     29                new ImageProvider("dialogs/changeset/changesetmanager").setOptional(true),
    2930              tr("Toggle visibility of Changeset Manager window"),
    3031              Shortcut.registerShortcut("menu:windows:changesetdialog",
    3132                      tr("Toggle visibility of Changeset Manager window"),
    3233                      KeyEvent.VK_C, Shortcut.ALT_CTRL),
    33               true /* register shortcut */
     34              true /* register shortcut */, null, false
    3435        );
    3536        notifySelectedState();
    3637        changesetCacheManagerClosedHandler = new ChangesetCacheManagerClosedHandler();
    3738        setHelpId(ht("/Dialog/ChangesetManager"));
    38     }
    39 
    40     @Override
    41     protected void installAdapters() {
    42         // do nothing
    4339    }
    4440
  • trunk/src/org/openstreetmap/josm/actions/DeleteLayerAction.java

    r14397 r16509  
    4141
    4242    @Override
     43    protected boolean listenToSelectionChange() {
     44        return false;
     45    }
     46
     47    @Override
    4348    protected void updateEnabledState() {
    4449        setEnabled(getLayerManager().getActiveLayer() != null);
  • trunk/src/org/openstreetmap/josm/actions/DownloadAction.java

    r14397 r16509  
    2727        super(tr("Download data..."), "download", tr("Download map data from a server of your choice"),
    2828              Shortcut.registerShortcut("file:download", tr("File: {0}", tr("Download data")), KeyEvent.VK_DOWN, Shortcut.CTRL_SHIFT),
    29               true);
     29              true, false);
    3030        setHelpId(ht("/Action/Download"));
    3131    }
  • trunk/src/org/openstreetmap/josm/actions/DownloadNotesInViewAction.java

    r14121 r16509  
    5353
    5454    @Override
     55    protected boolean listenToSelectionChange() {
     56        return false;
     57    }
     58
     59    @Override
    5560    protected void updateEnabledState() {
    5661        setEnabled(getLayerManager().getActiveLayer() != null
  • trunk/src/org/openstreetmap/josm/actions/DownloadOsmInViewAction.java

    r14121 r16509  
    4141
    4242    @Override
     43    protected boolean listenToSelectionChange() {
     44        return false;
     45    }
     46
     47    @Override
    4348    protected void updateEnabledState() {
    4449        setEnabled(getLayerManager().getActiveLayer() != null
  • trunk/src/org/openstreetmap/josm/actions/DrawBoundariesOfDownloadedDataAction.java

    r14648 r16509  
    2828
    2929    @Override
     30    protected boolean listenToSelectionChange() {
     31        return false;
     32    }
     33
     34    @Override
    3035    protected void updateEnabledState() {
    3136        setEnabled(MainApplication.getLayerManager().getEditLayer() != null);
  • trunk/src/org/openstreetmap/josm/actions/ExpertToggleAction.java

    r16138 r16509  
    99import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1010import org.openstreetmap.josm.gui.MainApplication;
     11import org.openstreetmap.josm.tools.ImageProvider;
    1112import org.openstreetmap.josm.tools.ListenerList;
    1213
     
    110111    public ExpertToggleAction() {
    111112        super(tr("Expert Mode"),
    112               "expert",
     113                new ImageProvider("expert").setOptional(true),
    113114              tr("Enable/disable expert mode"),
    114115              null,
    115               false /* register toolbar */
     116              false /* register toolbar */, null, false
    116117        );
    117118        setToolbarId("expertmode");
  • trunk/src/org/openstreetmap/josm/actions/FullscreenToggleAction.java

    r16505 r16509  
    4141              tr("Toggle fullscreen view"),
    4242              Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle fullscreen view"), KeyEvent.VK_F11, Shortcut.DIRECT),
    43               false /* register */
     43              false /* register */, null, false
    4444        );
    4545        setHelpId(ht("/Action/FullscreenView"));
     
    4949        setSelected(Config.getPref().getBoolean("draw.fullscreen", false));
    5050        notifySelectedState();
    51     }
    52 
    53     @Override
    54     protected void installAdapters() {
    55         // not needed
    5651    }
    5752
  • trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java

    r14950 r16509  
    115115    }
    116116
     117    @Override
     118    protected boolean listenToSelectionChange() {
     119        return false;
     120    }
     121
    117122    /**
    118123     * Refreshes the enabled state
  • trunk/src/org/openstreetmap/josm/actions/HelpAction.java

    r14153 r16509  
    3535        super(tr("Help"), "help", null,
    3636                shortcut ? Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.DIRECT) : null,
    37                 true);
     37                true, false);
    3838        setEnabled(!NetworkManager.isOffline(OnlineResource.JOSM_WEBSITE));
    3939    }
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r16365 r16509  
    154154
    155155    /**
    156      * Constructs a new {@code JosmAction}.
     156     * Constructs a new {@code JosmAction} and installs layer changed and selection changed adapters.
    157157     *
    158158     * Use this super constructor to setup your action.
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r16411 r16509  
    5656        super(tr("Jump to Position"), (ImageProvider) null, tr("Opens a dialog that allows to jump to a specific location"),
    5757                Shortcut.registerShortcut("tools:jumpto", tr("Tool: {0}", tr("Jump to Position")),
    58                         KeyEvent.VK_J, Shortcut.CTRL), true, "action/jumpto", true);
     58                        KeyEvent.VK_J, Shortcut.CTRL), true, "action/jumpto", false);
     59        // make this action listen to mapframe change events
     60        MainApplication.addMapFrameListener((o, n) -> updateEnabledState());
     61
    5962        setHelpId(ht("/Action/JumpToPosition"));
    6063    }
     
    242245        setEnabled(MainApplication.isDisplayingMapView());
    243246    }
    244 
    245     @Override
    246     protected void installAdapters() {
    247         super.installAdapters();
    248         // make this action listen to mapframe change events
    249         MainApplication.addMapFrameListener((o, n) -> updateEnabledState());
    250     }
    251247}
  • trunk/src/org/openstreetmap/josm/actions/MapRectifierWMSmenuAction.java

    r15293 r16509  
    261261
    262262    @Override
     263    protected boolean listenToSelectionChange() {
     264        return false;
     265    }
     266
     267    @Override
    263268    protected void updateEnabledState() {
    264269        setEnabled(!getLayerManager().getLayers().isEmpty());
  • trunk/src/org/openstreetmap/josm/actions/MergeLayerAction.java

    r16069 r16509  
    149149    public void actionPerformed(ActionEvent e) {
    150150        merge(getSourceLayer());
     151    }
     152
     153    @Override
     154    protected boolean listenToSelectionChange() {
     155        return false;
    151156    }
    152157
  • trunk/src/org/openstreetmap/josm/actions/ReorderImageryLayersAction.java

    r15207 r16509  
    4040
    4141    @Override
     42    protected boolean listenToSelectionChange() {
     43        return false;
     44    }
     45
     46    @Override
    4247    protected void updateEnabledState() {
    4348        setEnabled(getNonOverlayImageryLayers().count() > 1);
  • trunk/src/org/openstreetmap/josm/actions/ReportBugAction.java

    r10062 r16509  
    3232        super(tr("Report bug"), "bug", tr("Report a ticket to JOSM bugtracker"),
    3333                Shortcut.registerShortcut("reportbug", tr("Report a ticket to JOSM bugtracker"),
    34                         KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), true);
     34                        KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), true, false);
    3535        this.text = text;
    3636    }
  • trunk/src/org/openstreetmap/josm/actions/SaveAction.java

    r15496 r16509  
    9393
    9494    @Override
     95    protected boolean listenToSelectionChange() {
     96        return false;
     97    }
     98
     99    @Override
    95100    protected void updateEnabledState() {
    96101        Layer activeLayer = getLayerManager().getActiveLayer();
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r15496 r16509  
    175175
    176176    @Override
     177    protected boolean listenToSelectionChange() {
     178        return false;
     179    }
     180
     181    @Override
    177182    protected void updateEnabledState() {
    178183        Layer activeLayer = getLayerManager().getActiveLayer();
  • trunk/src/org/openstreetmap/josm/actions/SearchNotesDownloadAction.java

    r15011 r16509  
    3535    /** Constructs a new note search action */
    3636    public SearchNotesDownloadAction() {
    37         super(tr("Search Notes..."), "note_search", tr("Download notes from the note search API"), null, false);
     37        super(tr("Search Notes..."), "note_search", tr("Download notes from the note search API"), null, false, false);
    3838    }
    3939
  • trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java

    r14397 r16509  
    3838    }
    3939
     40    @Override
     41    protected boolean listenToSelectionChange() {
     42        return false;
     43    }
     44
    4045    /**
    4146     * Refreshes the enabled state
  • trunk/src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequencesAction.java

    r13434 r16509  
    3535    }
    3636
     37    @Override
     38    protected boolean listenToSelectionChange() {
     39        return false;
     40    }
     41
    3742    /**
    3843     * Update the enabled state of the action when something in
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r16438 r16509  
    6363     */
    6464    public SessionSaveAsAction() {
    65         this(true, true);
     65        this(true, false);
     66        updateEnabledState();
    6667    }
    6768
  • trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java

    r16438 r16509  
    6464                tr("Show status report with useful information that can be attached to bugs"),
    6565                Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
    66                         tr("Show Status Report")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false);
     66                        tr("Show Status Report")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), true, "help/showstatusreport", false);
    6767
    6868        setHelpId(ht("/Action/ShowStatusReport"));
    69         setToolbarId("help/showstatusreport");
    70         MainApplication.getToolbar().register(this);
    7169    }
    7270
  • trunk/src/org/openstreetmap/josm/actions/TaggingPresetSearchAction.java

    r16285 r16509  
    3636
    3737    @Override
     38    protected boolean listenToSelectionChange() {
     39        return false;
     40    }
     41
     42    @Override
    3843    protected void updateEnabledState() {
    3944        setEnabled(hasActiveDataLayer());
  • trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java

    r14397 r16509  
    3333    }
    3434
     35    @Override
     36    protected boolean listenToSelectionChange() {
     37        return false;
     38    }
     39
    3540    /**
    3641     * Refreshes the enabled state
  • trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java

    r16438 r16509  
    4040                true);
    4141        setHelpId(ht("/Action/UpdateData"));
     42    }
     43
     44    @Override
     45    protected boolean listenToSelectionChange() {
     46        return false;
    4247    }
    4348
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r16438 r16509  
    147147
    148148    @Override
     149    protected boolean listenToSelectionChange() {
     150        return false;
     151    }
     152
     153    @Override
    149154    protected void updateEnabledState() {
    150155        OsmDataLayer editLayer = getLayerManager().getEditLayer();
  • trunk/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java

    r15708 r16509  
    5555
    5656    @Override
     57    protected boolean listenToSelectionChange() {
     58        return false;
     59    }
     60
     61    @Override
    5762    protected void updateEnabledState() {
    5863        setEnabled(getLayerManager().getEditDataSet() != null);
  • trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    r16138 r16509  
    3737
    3838    @Override
     39    protected boolean listenToSelectionChange() {
     40        return false;
     41    }
     42
     43    @Override
    3944    protected void updateEnabledState() {
    4045        setEnabled(getLayerManager().getActiveData() != null);
  • trunk/src/org/openstreetmap/josm/actions/ZoomInAction.java

    r14397 r16509  
    5151
    5252    @Override
     53    protected boolean listenToSelectionChange() {
     54        return false;
     55    }
     56
     57    @Override
    5358    protected void updateEnabledState() {
    5459        setEnabled(!getLayerManager().getLayers().isEmpty());
  • trunk/src/org/openstreetmap/josm/actions/ZoomOutAction.java

    r14397 r16509  
    3737
    3838    @Override
     39    protected boolean listenToSelectionChange() {
     40        return false;
     41    }
     42
     43   @Override
    3944    protected void updateEnabledState() {
    4045        setEnabled(!getLayerManager().getLayers().isEmpty());
  • trunk/src/org/openstreetmap/josm/actions/audio/AbstractAudioAction.java

    r12636 r16509  
    3939
    4040    @Override
     41    protected boolean listenToSelectionChange() {
     42        return false;
     43    }
     44
     45    @Override
    4146    protected void updateEnabledState() {
    4247        setEnabled(isAudioMarkerPresent());
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r16438 r16509  
    483483    }
    484484
     485    @Override
     486    protected boolean listenToSelectionChange() {
     487        return false;
     488    }
     489
    485490    /**
    486491     * Refreshes the enabled state
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    r16438 r16509  
    6464
    6565        @Override
     66        protected boolean listenToSelectionChange() {
     67            return false;
     68        }
     69
     70        @Override
    6671        public void updateEnabledState() {
    6772            setEnabled(MainApplication.isDisplayingMapView()
Note: See TracChangeset for help on using the changeset viewer.