Ticket #21446: 21360-v3.patch

File 21360-v3.patch, 4.0 KB (added by GerdP, 4 years ago)
  • src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

     
    7676import org.openstreetmap.josm.gui.MapFrame;
    7777import org.openstreetmap.josm.gui.help.HelpUtil;
    7878import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
     79import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetListener;
     80import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    7981import org.openstreetmap.josm.gui.util.GuiHelper;
    8082import org.openstreetmap.josm.gui.util.ReorderableTableModel;
    8183import org.openstreetmap.josm.spi.preferences.Config;
     
    9092 * Toolbar preferences.
    9193 * @since 172
    9294 */
    93 public class ToolbarPreferences implements PreferenceSettingFactory {
     95public class ToolbarPreferences implements PreferenceSettingFactory, TaggingPresetListener {
    9496
    9597    private static final String EMPTY_TOOLBAR_MARKER = "<!-empty-!>";
    9698
     
    10221024            control.setComponentPopupMenu(popupMenu);
    10231025        });
    10241026        MapFrame.TOOLBAR_VISIBLE.addListener(e -> refreshToolbarControl());
     1027        TaggingPresets.addListener(this);
    10251028    }
    10261029
    10271030    private void loadAction(DefaultMutableTreeNode node, MenuElement menu) {
     
    11381141            }
    11391142        }
    11401143        if (toolbar != null) {
     1144            actions.put(toolbar, action);
    11411145            regactions.put(toolbar, action);
    11421146        }
    11431147        return action;
     
    11521156    public Action unregister(Action action) {
    11531157        Object toolbar = action.getValue("toolbar");
    11541158        if (toolbar instanceof String) {
     1159            actions.remove(toolbar);
    11551160            return regactions.remove(toolbar);
    11561161        }
    11571162        return null;
     
    12841289    }
    12851290
    12861291    private static final DataFlavor ACTION_FLAVOR = new DataFlavor(ActionDefinition.class, "ActionItem");
     1292
     1293    @Override
     1294    public void taggingPresetsModified() {
     1295        refreshToolbarControl();
     1296    }
    12871297}
  • src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

     
    177177     * Use this as default item for "do not select anything".
    178178     */
    179179    public TaggingPreset() {
    180         MainApplication.getLayerManager().addActiveLayerChangeListener(this);
    181180        updateEnabledState();
    182181    }
    183182
  • src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java

     
    9090        for (TaggingPreset tp: taggingPresets) {
    9191            if (!(tp instanceof TaggingPresetSeparator)) {
    9292                MainApplication.getToolbar().register(tp);
     93                MainApplication.getLayerManager().addActiveLayerChangeListener(tp);
    9394            }
    9495        }
    9596        if (taggingPresets.isEmpty()) {
     
    137138     */
    138139    public static void destroy() {
    139140        ToolbarPreferences toolBar = MainApplication.getToolbar();
    140         taggingPresets.forEach(toolBar::unregister);
     141        for (TaggingPreset tp: taggingPresets) {
     142            toolBar.unregister(tp);
     143            if (!(tp instanceof TaggingPresetSeparator)) {
     144                MainApplication.getLayerManager().removeActiveLayerChangeListener(tp);
     145            }
     146        }
    141147        taggingPresets.clear();
    142148        PRESET_TAG_CACHE.clear();
    143149        PRESET_ROLE_CACHE.clear();
    144150        MainApplication.getMenu().presetsMenu.removeAll();
    145         listeners.forEach(TaggingPresetListener::taggingPresetsModified);
    146151    }
    147152
    148153    /**