Ignore:
Timestamp:
2020-02-15T18:05:24+01:00 (5 years ago)
Author:
donvip
Message:

fix #18713 - make terracer plugin restartless (patch by taylor.smock)

Location:
applications/editors/josm/plugins/terracer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/terracer/build.xml

    r34584 r35324  
    88    <property name="plugin.icon" value="images/terrace.png"/>
    99    <property name="plugin.link" value="https://wiki.openstreetmap.org/wiki/JOSM/Plugins/Terracer"/>
     10        <property name="plugin.canloadatruntime" value="true"/>
    1011
    1112    <!-- ** include targets that all plugins have in common ** -->
  • applications/editors/josm/plugins/terracer/src/org/openstreetmap/josm/plugins/terracer/TerracerPlugin.java

    r34584 r35324  
    22package org.openstreetmap.josm.plugins.terracer;
    33
     4import java.awt.Component;
     5import java.util.Arrays;
     6import java.util.List;
     7import java.util.Map;
     8import java.util.Map.Entry;
     9import java.util.stream.Collectors;
     10
     11import javax.swing.Action;
     12import javax.swing.JMenu;
     13import javax.swing.JMenuItem;
     14
     15import org.openstreetmap.josm.actions.JosmAction;
    416import org.openstreetmap.josm.gui.MainApplication;
    517import org.openstreetmap.josm.gui.MainMenu;
    618import org.openstreetmap.josm.plugins.Plugin;
    719import org.openstreetmap.josm.plugins.PluginInformation;
     20import org.openstreetmap.josm.tools.Destroyable;
    821
    922/**
     
    1225 * @author zere - Copyright 2009 CloudMade Ltd
    1326 */
    14 public class TerracerPlugin extends Plugin {
     27public class TerracerPlugin extends Plugin implements Destroyable {
     28        private List<JosmAction> actions = Arrays.asList(new TerracerAction(), new ReverseTerraceAction());
     29
    1530    public TerracerPlugin(PluginInformation info) {
    1631        super(info);
     32        for (JosmAction action : actions) {
     33                MainMenu.add(MainApplication.getMenu().moreToolsMenu, action);
     34        }
     35    }
    1736
    18         MainMenu.add(MainApplication.getMenu().moreToolsMenu, new TerracerAction());
    19         MainMenu.add(MainApplication.getMenu().moreToolsMenu, new ReverseTerraceAction());
    20     }
     37        @Override
     38        public void destroy() {
     39        final JMenu moreToolsMenu = MainApplication.getMenu().moreToolsMenu;
     40        final Map<Action, Component> actionsMap = Arrays.asList(moreToolsMenu.getMenuComponents()).stream()
     41                .filter(JMenuItem.class::isInstance).map(JMenuItem.class::cast)
     42                .collect(Collectors.toMap(JMenuItem::getAction, component -> component));
     43
     44        for (final Entry<Action, Component> action : actionsMap.entrySet()) {
     45            if (actionsMap.containsKey(action.getKey())) {
     46                moreToolsMenu.remove(action.getValue());
     47            }
     48        }
     49                actions.forEach(JosmAction::destroy);
     50        }
    2151}
Note: See TracChangeset for help on using the changeset viewer.