Changeset 15633 in josm for trunk/src/org/openstreetmap


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

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

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
5 edited

Legend:

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

    r8510 r15633  
    2323    boolean isButtonVisible();
    2424
     25    boolean isExpert();
     26
    2527    void setShowHideButtonListener(ShowHideButtonListener l);
    2628}
  • trunk/src/org/openstreetmap/josm/gui/IconToggleButton.java

    r12846 r15633  
    162162
    163163    @Override
     164    public boolean isExpert() {
     165        return isExpert;
     166    }
     167
     168    @Override
    164169    public void setShowHideButtonListener(ShowHideButtonListener l) {
    165170        listener = l;
  • 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
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r15445 r15633  
    4444import javax.swing.plaf.basic.BasicSplitPaneUI;
    4545
     46import org.openstreetmap.josm.actions.ExpertToggleAction;
    4647import org.openstreetmap.josm.actions.mapmode.DeleteAction;
    4748import org.openstreetmap.josm.actions.mapmode.DrawAction;
     
    671672            JPopupMenu menu = new JPopupMenu();
    672673            for (HideableButton b : buttons) {
    673                 final HideableButton t = b;
    674                 menu.add(new JCheckBoxMenuItem(new AbstractAction() {
    675                     {
    676                         putValue(NAME, t.getActionName());
    677                         putValue(SMALL_ICON, t.getIcon());
    678                         putValue(SELECTED_KEY, t.isButtonVisible());
    679                         putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button"));
    680                     }
    681 
    682                     @Override
    683                     public void actionPerformed(ActionEvent e) {
    684                         if ((Boolean) getValue(SELECTED_KEY)) {
    685                             t.showButton();
    686                         } else {
    687                             t.hideButton();
     674                if (!b.isExpert() || ExpertToggleAction.isExpert()) {
     675                    final HideableButton t = b;
     676                    menu.add(new JCheckBoxMenuItem(new AbstractAction() {
     677                        {
     678                            putValue(NAME, t.getActionName());
     679                            putValue(SMALL_ICON, t.getIcon());
     680                            putValue(SELECTED_KEY, t.isButtonVisible());
     681                            putValue(SHORT_DESCRIPTION, tr("Hide or show this toggle button"));
    688682                        }
    689                         validateToolBarsVisibility();
    690                     }
    691                 }));
     683
     684                        @Override
     685                        public void actionPerformed(ActionEvent e) {
     686                            if ((Boolean) getValue(SELECTED_KEY)) {
     687                                t.showButton();
     688                            } else {
     689                                t.hideButton();
     690                            }
     691                            validateToolBarsVisibility();
     692                        }
     693                    }));
     694                }
    692695            }
    693696            if (button != null && button.isShowing()) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r14903 r15633  
    266266        windowMenuItem = MainMenu.addWithCheckbox(MainApplication.getMenu().windowMenu,
    267267                (JosmAction) getToggleAction(),
    268                 MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG);
     268                MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG, false, true);
    269269    }
    270270
Note: See TracChangeset for help on using the changeset viewer.