From 0676521ba57b2bf8dca5d7db3cce87f6e7233add Mon Sep 17 00:00:00 2001
From: windu2b <windu.2b@gmail.com>
Date: Sun, 18 Aug 2013 22:55:16 +0200
Subject: [PATCH] Adds a non-persistent checkbox which allows to add several
 duplicate elements in one shot.

The option is non-persistent : it is reset before and after each attempt to add.
---
 .../josm/gui/ConditionalOptionPaneUtil.java        | 68 ++++++++++++++++++++--
 .../dialogs/relation/GenericRelationEditor.java    |  7 ++-
 2 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java b/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java
index 86346b0..7e8900e 100644
--- a/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java
+++ b/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java
@@ -55,6 +55,27 @@ public class ConditionalOptionPaneUtil {
     }
 
     /**
+     * Replies the preference value for the preference key "message." + <code>prefKey</code>.
+     * The default value if the preference key is missing is true.
+     *
+     * @param  prefKey the preference key
+     * @return the preference value for the preference key "message." + <code>prefKey</code>
+     */
+    public static boolean getNonPersistentDialogShowingEnabled(String prefKey) {
+        return Main.pref.getBoolean("message."+prefKey+"_nonPersistent", true);
+    }
+
+    /**
+     * sets the value for the preference key "message." + <code>prefKey</code>.
+     *
+     * @param prefKey the key
+     * @param enabled the value
+     */
+    public static void setNonPersistentDialogShowingEnabled(String prefKey, boolean enabled) {
+        Main.pref.put("message."+prefKey+"_nonPersistent", enabled);
+    }
+
+    /**
      * Returns the preference value for the preference key "message." + <code>prefKey</code> + ".value".
      * The default value if the preference key is missing is -1.
      *
@@ -76,6 +97,27 @@ public class ConditionalOptionPaneUtil {
     }
 
     /**
+     * Returns the preference value for the preference key "message." + <code>prefKey</code> + "_nonPersistent" + ".value".
+     * The default value if the preference key is missing is -1.
+     *
+     * @param  prefKey the preference key
+     * @return the preference value for the preference key "message." + <code>prefKey</code> + ".value"
+     */
+    public static Integer getNonPersistentDialogReturnValue(String prefKey) {
+        return Main.pref.getInteger("message."+prefKey+"_nonPersistent"+".value", -1);
+    }
+
+    /**
+     * sets the value for the preference key "message." + <code>prefKey</code> + "_nonPersistent" + ".value".
+     *
+     * @param prefKey the key
+     * @param value the value
+     */
+    public static void setNonPersistentDialogReturnValue(String prefKey, Integer value) {
+        Main.pref.putInteger("message."+prefKey+"_nonPersistent"+".value", value);
+    }
+
+    /**
      * Displays an confirmation dialog with some option buttons given by <code>optionType</code>.
      * It is always on top even if there are other open windows like detached dialogs,
      * relation editors, history browsers and the like.
@@ -102,15 +144,21 @@ public class ConditionalOptionPaneUtil {
      * @return the option selected by user. {@link JOptionPane#CLOSED_OPTION} if the dialog was closed.
      */
     static public int showOptionDialog(String preferenceKey, Component parent, Object message, String title, int optionType, int messageType, Object [] options, Object defaultOption) throws HeadlessException {
-        int ret = getDialogReturnValue(preferenceKey);
-        if (!getDialogShowingEnabled(preferenceKey) && ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)))
+        int ret = getDialogReturnValue(preferenceKey) | getNonPersistentDialogReturnValue(preferenceKey);
+        if ((!getDialogShowingEnabled(preferenceKey) || !getNonPersistentDialogShowingEnabled(preferenceKey)) && ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)))
             return ret;
         MessagePanel pnl = new MessagePanel(false, message);
         ret = JOptionPane.showOptionDialog(parent, pnl, title, optionType, messageType, null, options, defaultOption);
 
-        if (((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)) && !pnl.getDialogShowingEnabled()) {
-            setDialogShowingEnabled(preferenceKey, false);
-            setDialogReturnValue(preferenceKey, ret);
+        if ((ret == JOptionPane.YES_OPTION) || (ret == JOptionPane.NO_OPTION)) {
+            if(!pnl.getDialogShowingEnabled() ) {
+                setDialogShowingEnabled(preferenceKey, false);
+                setDialogReturnValue(preferenceKey, ret);
+            }
+            if( !pnl.getNonPersistentDialogShowingEnabled()) {
+                setNonPersistentDialogShowingEnabled(preferenceKey, false);
+                setNonPersistentDialogReturnValue(preferenceKey, ret);
+            }
         }
         return ret;
     }
@@ -196,10 +244,13 @@ public class ConditionalOptionPaneUtil {
      */
     private static class MessagePanel extends JPanel {
         JCheckBox cbShowDialog;
+        JCheckBox cbShowNonPersistentDialog;
 
         public MessagePanel(boolean donotshow, Object message) {
             cbShowDialog = new JCheckBox(tr("Do not show again (remembers choice)"));
             cbShowDialog.setSelected(donotshow);
+            cbShowNonPersistentDialog = new JCheckBox(tr("Do not show again (just this time)"));
+            cbShowNonPersistentDialog.setSelected(donotshow);
             setLayout(new GridBagLayout());
 
             if (message instanceof Component) {
@@ -207,11 +258,16 @@ public class ConditionalOptionPaneUtil {
             } else {
                 add(new JLabel(message.toString()),GBC.eop());
             }
-            add(cbShowDialog, GBC.eol());
+            add(cbShowDialog, GBC.std());
+            add(cbShowNonPersistentDialog, GBC.eol());
         }
 
         public boolean getDialogShowingEnabled() {
             return !cbShowDialog.isSelected();
         }
+
+        public boolean getNonPersistentDialogShowingEnabled() {
+            return !cbShowNonPersistentDialog.isSelected();
+        }
     }
 }
diff --git a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
index fdfc49a..1f1a600 100644
--- a/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
+++ b/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
@@ -769,6 +769,8 @@ public class GenericRelationEditor extends RelationEditor  {
             if (primitives == null || primitives.isEmpty())
                 return primitives;
             ArrayList<OsmPrimitive> ret = new ArrayList<OsmPrimitive>();
+            ConditionalOptionPaneUtil.setNonPersistentDialogShowingEnabled("add_primitive_to_relation", true);
+            ConditionalOptionPaneUtil.setNonPersistentDialogReturnValue("add_primitive_to_relation", 0);
             for (OsmPrimitive primitive : primitives) {
                 if (primitive instanceof Relation && getRelation() != null && getRelation().equals(primitive)) {
                     warnOfCircularReferences(primitive);
@@ -783,6 +785,8 @@ public class GenericRelationEditor extends RelationEditor  {
                     ret.add(primitive);
                 }
             }
+            ConditionalOptionPaneUtil.setNonPersistentDialogShowingEnabled("add_primitive_to_relation", true);
+            ConditionalOptionPaneUtil.setNonPersistentDialogReturnValue("add_primitive_to_relation", 0);
             return ret;
         }
     }
-- 
1.8.3.4

