diff --git a/src/org/openstreetmap/josm/actions/OpenFileAction.java b/src/org/openstreetmap/josm/actions/OpenFileAction.java
index 53957f9..a61bda6 100644
|
a
|
b
|
public class OpenFileAction extends DiskAccessAction {
|
| 275 | 275 | // remove the files which failed to load from the list |
| 276 | 276 | fileHistory.removeAll(failedAll); |
| 277 | 277 | int maxsize = Math.max(0, Main.pref.getInteger("file-open.history.max-size", 15)); |
| 278 | | Collection<String> trimmedFileHistory = new ArrayList<String>(Math.min(maxsize, fileHistory.size())); |
| 279 | | int i = 0; |
| 280 | | for (String s : fileHistory) { |
| 281 | | if (++i > maxsize) { |
| 282 | | break; |
| 283 | | } |
| 284 | | trimmedFileHistory.add(s); |
| 285 | | } |
| 286 | | Main.pref.putCollection("file-open.history", trimmedFileHistory); |
| | 278 | Main.pref.putCollectionBounded("file-open.history", maxsize, fileHistory); |
| 287 | 279 | } |
| 288 | 280 | } |
| 289 | 281 | } |
diff --git a/src/org/openstreetmap/josm/actions/SaveActionBase.java b/src/org/openstreetmap/josm/actions/SaveActionBase.java
index 99ac086..293c29d 100644
|
a
|
b
|
import static org.openstreetmap.josm.tools.I18n.tr;
|
| 6 | 6 | import java.awt.event.ActionEvent; |
| 7 | 7 | import java.io.File; |
| 8 | 8 | import java.io.IOException; |
| 9 | | |
| | 9 | import java.util.Collection; |
| | 10 | import java.util.LinkedList; |
| | 11 | import java.util.List; |
| 10 | 12 | import javax.swing.JFileChooser; |
| 11 | 13 | import javax.swing.JOptionPane; |
| 12 | 14 | import javax.swing.filechooser.FileFilter; |
| … |
… |
import org.openstreetmap.josm.io.FileExporter;
|
| 22 | 24 | import org.openstreetmap.josm.tools.Shortcut; |
| 23 | 25 | |
| 24 | 26 | public abstract class SaveActionBase extends DiskAccessAction { |
| | 27 | private File file; |
| 25 | 28 | |
| 26 | 29 | public SaveActionBase(String name, String iconName, String tooltip, Shortcut shortcut) { |
| 27 | 30 | super(name, iconName, tooltip, shortcut); |
| 28 | 31 | } |
| 29 | 32 | |
| | 33 | @Override |
| 30 | 34 | public void actionPerformed(ActionEvent e) { |
| 31 | | if (!isEnabled()) |
| | 35 | if (!isEnabled()) { |
| 32 | 36 | return; |
| 33 | | doSave(); |
| | 37 | } |
| | 38 | boolean saved = doSave(); |
| | 39 | if (saved) { |
| | 40 | addToFileOpenHistory(); |
| | 41 | } |
| 34 | 42 | } |
| 35 | 43 | |
| 36 | 44 | public boolean doSave() { |
| … |
… |
public abstract class SaveActionBase extends DiskAccessAction {
|
| 47 | 55 | public boolean doSave(Layer layer) { |
| 48 | 56 | if(!checkSaveConditions(layer)) |
| 49 | 57 | return false; |
| 50 | | return doInternalSave(layer, getFile(layer)); |
| | 58 | file = getFile(layer); |
| | 59 | return doInternalSave(layer, file); |
| 51 | 60 | } |
| 52 | 61 | |
| 53 | 62 | public boolean doSave(Layer layer, File file) { |
| … |
… |
public abstract class SaveActionBase extends DiskAccessAction {
|
| 223 | 232 | } |
| 224 | 233 | return true; |
| 225 | 234 | } |
| | 235 | |
| | 236 | protected void addToFileOpenHistory() { |
| | 237 | String filepath; |
| | 238 | try { |
| | 239 | filepath = file.getCanonicalPath(); |
| | 240 | } catch (IOException ign) { |
| | 241 | return; |
| | 242 | } |
| | 243 | |
| | 244 | int maxsize = Math.max(0, Main.pref.getInteger("file-open.history.max-size", 15)); |
| | 245 | Collection<String> oldHistory = Main.pref.getCollection("file-open.history"); |
| | 246 | List<String> history = new LinkedList<String>(oldHistory); |
| | 247 | history.add(0, filepath); |
| | 248 | Main.pref.putCollectionBounded("file-open.history", maxsize, history); |
| | 249 | } |
| 226 | 250 | } |
diff --git a/src/org/openstreetmap/josm/data/Preferences.java b/src/org/openstreetmap/josm/data/Preferences.java
index c8444f5..ea3e992 100644
|
a
|
b
|
public class Preferences {
|
| 740 | 740 | return put(key, Utils.join("\u001e", val)); |
| 741 | 741 | } |
| 742 | 742 | |
| | 743 | /** |
| | 744 | * Saves at most {@code maxsize} items of collection {@code val}. |
| | 745 | */ |
| | 746 | public boolean putCollectionBounded(String key, int maxsize, Collection<String> val) { |
| | 747 | Collection<String> newCollection = new ArrayList<String>(maxsize); |
| | 748 | for (String i : val) { |
| | 749 | if (newCollection.size() >= maxsize) { |
| | 750 | break; |
| | 751 | } |
| | 752 | newCollection.add(i); |
| | 753 | } |
| | 754 | return putCollection(key, newCollection); |
| | 755 | } |
| | 756 | |
| 743 | 757 | synchronized private void putCollectionDefault(String key, Collection<String> val) { |
| 744 | 758 | putDefault(key, Utils.join("\u001e", val)); |
| 745 | 759 | } |