Ignore:
Timestamp:
2020-01-05T16:36:31+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #18514 - make all changeset actions and dialogs only accessible in expert mode

File:
1 edited

Legend:

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

    r15445 r15633  
    448448            final JPopupMenu m = ((JMenu) a.getSource()).getPopupMenu();
    449449            for (int i = 0; i < m.getComponentCount()-1; i++) {
    450                 if (!(m.getComponent(i) instanceof JSeparator)) {
    451                     continue;
     450                // hide separator if the next menu item is one as well
     451                if (m.getComponent(i) instanceof JSeparator && m.getComponent(i+1) instanceof JSeparator) {
     452                    ((JSeparator) m.getComponent(i)).setVisible(false);
    452453                }
    453                 // hide separator if the next menu item is one as well
    454                 ((JSeparator) m.getComponent(i)).setVisible(!(m.getComponent(i+1) instanceof JSeparator));
    455454            }
    456455            // hide separator at the end of the menu
     
    566565        if (action.getShortcut().isAutomatic())
    567566            return null;
    568         int i = getInsertionIndexForGroup(menu, group.ordinal());
     567        int i = getInsertionIndexForGroup(menu, group.ordinal(), false);
    569568        JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i);
    570569        KeyStroke ks = action.getShortcut().getKeyStroke();
     
    587586     */
    588587    public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group) {
    589         int i = getInsertionIndexForGroup(menu, group.ordinal());
     588        return addWithCheckbox(menu, action, group, false, false);
     589    }
     590
     591    /**
     592     * Add a JosmAction to a menu and automatically prints accelerator if available.
     593     * Also adds a checkbox that may be toggled.
     594     * @param <E> group enum item type
     595     * @param menu to add the action to
     596     * @param action the action that should get a menu item
     597     * @param group the item should be added to. Groups are split by a separator. Use
     598     *        one of the enums that are defined for some of the menus to tell in which
     599     *        group the item should go.
     600     * @param isEntryExpert whether the entry should only be visible if the expert mode is activated
     601     * @param isGroupSeparatorExpert whether the group separator should only be visible if the expert mode is activated
     602     * @return The created menu item
     603     * @since 15633
     604     */
     605    public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group,
     606            boolean isEntryExpert, boolean isGroupSeparatorExpert) {
     607        int i = getInsertionIndexForGroup(menu, group.ordinal(), isGroupSeparatorExpert);
    590608        final JCheckBoxMenuItem mi = (JCheckBoxMenuItem) menu.add(new JCheckBoxMenuItem(action), i);
    591609        final KeyStroke ks = action.getShortcut().getKeyStroke();
     
    593611            mi.setAccelerator(ks);
    594612        }
     613        if (isEntryExpert) {
     614            ExpertToggleAction.addVisibilitySwitcher(mi);
     615        }
    595616        return mi;
    596617    }
     
    600621     * @param menu menu
    601622     * @param group group number
     623     * @param isGroupSeparatorExpert whether the added separators should only be visible if the expert mode is activated
    602624     * @return correct insertion index
    603625     */
    604     private static int getInsertionIndexForGroup(JMenu menu, int group) {
     626    private static int getInsertionIndexForGroup(JMenu menu, int group, boolean isGroupSeparatorExpert) {
    605627        if (group < 0)
    606628            return -1;
     
    619641        while (group > 0) {
    620642            menu.addSeparator();
     643            if (isGroupSeparatorExpert) {
     644                ExpertToggleAction.addVisibilitySwitcher(menu.getMenuComponent(menu.getMenuComponentCount() - 1));
     645            }
    621646            group--;
    622647            i++;
     
    832857        // -- changeset manager toggle action
    833858        final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManager,
    834                 MainMenu.WINDOW_MENU_GROUP.ALWAYS);
     859                MainMenu.WINDOW_MENU_GROUP.ALWAYS, true, false);
    835860        changesetManager.addButtonModel(mi.getModel());
    836861
Note: See TracChangeset for help on using the changeset viewer.