Changeset 18683 in josm for trunk/src


Ignore:
Timestamp:
2023-03-06T23:28:55+01:00 (14 months ago)
Author:
taylor.smock
Message:

Fix #22783: Presets menu should not sort the first action block

The specific problem was that when the preset menu was sorted, the order of
the Preset menu (prior to the first separator) was Search preset...,
Preset preferences..., Search for objects by preset... instead of
Search preset..., Search for objects by preset..., Preset Preferences...

The fix for this was changing the TaggingPresetMenu.PresetTextComparator.compare
method to have the same behavior for the ordered presets. A non-regression
test was also added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetMenu.java

    r15231 r18683  
    1111import java.io.Serializable;
    1212import java.util.ArrayList;
     13import java.util.Arrays;
    1314import java.util.Comparator;
    1415import java.util.List;
     
    2122import javax.swing.JSeparator;
    2223
     24import org.openstreetmap.josm.actions.JosmAction;
    2325import org.openstreetmap.josm.gui.MainApplication;
    2426import org.openstreetmap.josm.gui.MainFrame;
     27import org.openstreetmap.josm.gui.MainMenu;
    2528import org.openstreetmap.josm.tools.AlphanumComparator;
    2629import org.openstreetmap.josm.tools.Logging;
     
    3841        @Override
    3942        public int compare(JMenuItem o1, JMenuItem o2) {
    40             if (MainApplication.getMenu().presetSearchAction.equals(o1.getAction()))
    41                 return -1;
    42             else if (MainApplication.getMenu().presetSearchAction.equals(o2.getAction()))
    43                 return 1;
    44             else
    45                 return AlphanumComparator.getInstance().compare(o1.getText(), o2.getText());
     43            final MainMenu menu = MainApplication.getMenu();
     44            // This is needed to keep the order of the search actions -> preferences
     45            for (JosmAction action : Arrays.asList(menu.presetSearchAction, menu.presetSearchPrimitiveAction)) {
     46                if (action.equals(o1.getAction())) {
     47                    return -1;
     48                } else if (action.equals(o2.getAction())) {
     49                    return 1;
     50                }
     51            }
     52            return AlphanumComparator.getInstance().compare(o1.getText(), o2.getText());
    4653        }
    4754    }
Note: See TracChangeset for help on using the changeset viewer.