Changeset 18362 in josm for trunk/src/org


Ignore:
Timestamp:
2022-01-09T12:16:28+01:00 (3 years ago)
Author:
GerdP
Message:

fix #21730: Not all JosmActions registering in toolbar

  • separate again between all registered actions and those which appear in menus (regression from r18321)
  • replace global map actions by local one to avoid memory leak
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r18361 r18362  
    576576     * Value: The action to execute.
    577577     */
    578     private final Map<String, Action> actions = new ConcurrentHashMap<>();
    579578    private final Map<String, Action> regactions = new ConcurrentHashMap<>();
    580579
     
    10271026    }
    10281027
    1029     private void loadAction(DefaultMutableTreeNode node, MenuElement menu) {
     1028    private void loadAction(DefaultMutableTreeNode node, MenuElement menu, Map<String, Action> actionsInMenu) {
    10301029        Object userObject = null;
    10311030        MenuElement menuElement = menu;
     
    10531052                    } else {
    10541053                        String toolbar = (String) tb;
    1055                         Action r = actions.get(toolbar);
     1054                        Action r = actionsInMenu.get(toolbar);
    10561055                        if (r != null && r != action && !toolbar.startsWith(IMAGERY_PREFIX)) {
    10571056                            Logging.info(tr("Toolbar action {0} overwritten: {1} gets {2}",
    10581057                            toolbar, r.getClass().getName(), action.getClass().getName()));
    10591058                        }
    1060                         actions.put(toolbar, action);
     1059                        actionsInMenu.put(toolbar, action);
    10611060                    }
    10621061                } else {
     
    10661065            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObject);
    10671066            node.add(newNode);
    1068             loadAction(newNode, item);
    1069         }
    1070     }
    1071 
    1072     private void loadActions() {
     1067            loadAction(newNode, item, actionsInMenu);
     1068        }
     1069    }
     1070
     1071    private void loadActions(Map<String, Action> actionsInMenu) {
    10731072        rootActionsNode.removeAllChildren();
    1074         loadAction(rootActionsNode, MainApplication.getMenu());
     1073        loadAction(rootActionsNode, MainApplication.getMenu(), actionsInMenu);
    10751074        for (Map.Entry<String, Action> a : regactions.entrySet()) {
    1076             if (actions.get(a.getKey()) == null) {
     1075            if (actionsInMenu.get(a.getKey()) == null) {
    10771076                rootActionsNode.add(new DefaultMutableTreeNode(a.getValue()));
    10781077            }
     
    10991098
    11001099    private Collection<ActionDefinition> getDefinedActions() {
    1101         loadActions();
     1100        Map<String, Action> actionsInMenu = new ConcurrentHashMap<>();
     1101
     1102        loadActions(actionsInMenu);
    11021103
    11031104        Map<String, Action> allActions = new ConcurrentHashMap<>(regactions);
    1104         allActions.putAll(actions);
     1105        allActions.putAll(actionsInMenu);
    11051106        ActionParser actionParser = new ActionParser(allActions);
    11061107
     
    11411142        }
    11421143        if (toolbar != null) {
    1143             actions.put(toolbar, action);
    11441144            regactions.put(toolbar, action);
    11451145        }
     
    11561156        Object toolbar = action.getValue("toolbar");
    11571157        if (toolbar instanceof String) {
    1158             actions.remove(toolbar);
    11591158            return regactions.remove(toolbar);
    11601159        }
Note: See TracChangeset for help on using the changeset viewer.