Changeset 16394 in josm


Ignore:
Timestamp:
2020-05-10T08:05:13+02:00 (4 weeks ago)
Author:
GerdP
Message:

fix #17270: Improve History (Ctrl+H) when multiple objects are selected

  • when closing one of many history dialogs, set focus to the last
  • dialog and a new user preference warn.open.maxhistory (default 5) to show warning if more than five are opened simultaneously
File:
1 edited

Legend:

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

    r16123 r16394  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    56
    67import java.awt.Component;
     
    910import java.util.ArrayList;
    1011import java.util.Collection;
    11 import java.util.HashMap;
    1212import java.util.Iterator;
     13import java.util.LinkedHashMap;
     14import java.util.LinkedList;
    1315import java.util.List;
    14 import java.util.Map;
    1516import java.util.Map.Entry;
    1617import java.util.Objects;
     
    2930import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    3031import org.openstreetmap.josm.gui.util.WindowGeometry;
     32import org.openstreetmap.josm.spi.preferences.Config;
    3133import org.openstreetmap.josm.tools.JosmRuntimeException;
    3234import org.openstreetmap.josm.tools.Logging;
     
    5961    private static HistoryBrowserDialogManager instance;
    6062
    61     private final Map<Long, HistoryBrowserDialog> dialogs = new HashMap<>();
     63    private final LinkedHashMap<Long, HistoryBrowserDialog> dialogs = new LinkedHashMap<>();
    6264
    6365    private final Predicate<PrimitiveId> unloadedHistoryPredicate = new UnloadedHistoryPredicate();
     
    144146        dialog.setVisible(false);
    145147        dialog.dispose();
     148
     149        if (!dialogs.isEmpty()) {
     150            // see #17270: set focus to last dialog
     151            new LinkedList<>(dialogs.values()).getLast().toFront();
     152        }
    146153    }
    147154
     
    225232     */
    226233    public void showHistory(Component parent, final Collection<? extends PrimitiveId> primitives) {
     234        if (primitives.size() > Config.getPref().getInt("warn.open.maxhistory", 5) &&
     235                /* I18N english text for value 1 makes no real sense, never called for values <= maxhistory (usually 5) */
     236                JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(MainApplication.getMainFrame(),
     237                        "<html>" + trn(
     238                                "You are about to open <b>{0}</b> history dialog.<br/>Do you want to continue?",
     239                                "You are about to open <b>{0}</b> different history dialogs simultaneously.<br/>Do you want to continue?",
     240                                primitives.size(), primitives.size()) + "</html>",
     241                        tr("Confirmation"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE)) {
     242            return;
     243        }
     244
    227245        final List<PrimitiveId> realPrimitives = new ArrayList<>(primitives);
    228246        hooks.forEach(h -> h.modifyRequestedIds(realPrimitives));
Note: See TracChangeset for help on using the changeset viewer.