Changeset 16966 in josm for trunk/src


Ignore:
Timestamp:
2020-08-29T16:38:58+02:00 (4 years ago)
Author:
simon04
Message:

fix #19732 - Preferences: open previously selected preference tab

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java

    r16505 r16966  
    109109        } else if (subTab != null) {
    110110            p.selectSubPreferencesTabByClass(subTab);
     111        } else {
     112            p.selectPreviouslySelectedPreferences();
    111113        }
    112114        p.setVisible(true);
  • trunk/src/org/openstreetmap/josm/gui/preferences/DefaultTabPreferenceSetting.java

    r16553 r16966  
    142142
    143143    @Override
     144    public Class<? extends SubPreferenceSetting> getSelectedSubTab() {
     145        if (tabpane == null || subSettingMap == null) {
     146            return null;
     147        }
     148        final Component selected = tabpane.getSelectedComponent();
     149        return subSettingMap.entrySet().stream()
     150                .filter(e -> e.getValue() == selected)
     151                .map(e -> e.getKey().getClass())
     152                .findFirst().orElse(null);
     153    }
     154
     155    @Override
    144156    public String getHelpContext() {
    145157        return HelpUtil.ht("/Action/Preferences");
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java

    r14601 r16966  
    3131import org.openstreetmap.josm.tools.ImageProvider;
    3232import org.openstreetmap.josm.tools.InputMapUtils;
     33import org.openstreetmap.josm.tools.Pair;
    3334
    3435/**
     
    4546    private final WindowEventHandler windowEventHandler = new WindowEventHandler();
    4647    private boolean canceled;
     48    private static Pair<Class<? extends TabPreferenceSetting>, Class<? extends SubPreferenceSetting>> previouslySelected;
    4749
    4850    /**
     
    145147
    146148    /**
     149     * Select preferences tab that was selected previously.
     150     */
     151    public void selectPreviouslySelectedPreferences() {
     152        if (previouslySelected != null && previouslySelected.b != null) {
     153            tpPreferences.selectSubTabByPref(previouslySelected.b);
     154        } else if (previouslySelected != null && previouslySelected.a != null) {
     155            tpPreferences.selectTabByPref(previouslySelected.a);
     156        }
     157    }
     158
     159    /**
    147160     * Select preferences tab by name.
    148161     * @param name preferences tab name (icon)
     
    215228    @Override
    216229    public void dispose() {
     230        previouslySelected = tpPreferences.getSelectedTab();
    217231        removeWindowListener(windowEventHandler);
    218232        super.dispose();
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r16553 r16966  
    7171import org.openstreetmap.josm.tools.ImageProvider;
    7272import org.openstreetmap.josm.tools.Logging;
     73import org.openstreetmap.josm.tools.Pair;
    7374import org.openstreetmap.josm.tools.Utils;
    7475import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
     
    354355            Logging.trace(ignore);
    355356            return false;
     357        }
     358    }
     359
     360    /**
     361     * Returns the currently selected preference and sub preference setting
     362     * @return the currently selected preference and sub preference setting
     363     */
     364    public Pair<Class<? extends TabPreferenceSetting>, Class<? extends SubPreferenceSetting>> getSelectedTab() {
     365        final Component selected = getSelectedComponent();
     366        if (selected instanceof PreferenceTab) {
     367            final TabPreferenceSetting setting = ((PreferenceTab) selected).getTabPreferenceSetting();
     368            return Pair.create(setting.getClass(), setting.getSelectedSubTab());
     369        } else {
     370            return null;
    356371        }
    357372    }
  • trunk/src/org/openstreetmap/josm/gui/preferences/TabPreferenceSetting.java

    r13431 r16966  
    7272
    7373    /**
     74     * Returns the currently selected sub preference setting
     75     * @return the currently selected sub preference setting
     76     */
     77    Class<? extends SubPreferenceSetting> getSelectedSubTab();
     78
     79    /**
    7480     * Selects the specified sub preference settings, if applicable. Not all Tab preference settings need to implement this.
    7581     * @param subPref The sub preference settings to be selected.
Note: See TracChangeset for help on using the changeset viewer.