Changeset 3710 in josm
- Timestamp:
- 2010-12-10T10:15:21+01:00 (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r3679 r3710 14 14 import java.util.Collection; 15 15 import java.util.Collections; 16 import java.util.LinkedHashSet; 16 17 import java.util.LinkedList; 17 18 import java.util.List; 18 19 20 import java.util.Set; 19 21 import javax.swing.JFileChooser; 20 22 import javax.swing.JOptionPane; … … 57 59 File[] files = fc.getSelectedFiles(); 58 60 OpenFileTask task = new OpenFileTask(Arrays.asList(files), fc.getFileFilter()); 61 task.setRecordHistory(true); 59 62 Main.worker.submit(task); 60 63 } … … 79 82 private FileFilter fileFilter; 80 83 private boolean cancelled; 84 private boolean recordHistory = false; 81 85 82 86 public OpenFileTask(List<File> files, FileFilter fileFilter, String title) { … … 88 92 public OpenFileTask(List<File> files, FileFilter fileFilter) { 89 93 this(files, fileFilter, tr("Opening files")); 94 } 95 96 /** 97 * save filename in history (for list of recently opened files) 98 * default: false 99 */ 100 public void setRecordHistory(boolean recordHistory) { 101 this.recordHistory = recordHistory; 102 } 103 104 public boolean isRecordHistory() { 105 return recordHistory; 90 106 } 91 107 … … 167 183 } 168 184 /** 169 * If the filter wasn'tchanged in the dialog, chosenImporter is null now.170 * When the filter wasexplicitlysetto AllFormatsImporter, treat this the same.185 * If the filter hasn't been changed in the dialog, chosenImporter is null now. 186 * When the filter has been set explicitly to AllFormatsImporter, treat this the same. 171 187 */ 172 188 if (chosenImporter instanceof AllFormatsImporter) { … … 210 226 // find appropriate importer 211 227 MultiMap<FileImporter, File> map = new MultiMap<FileImporter, File>(); 212 List<File> filesWithKnownImporter = new LinkedList<File>();213 228 List<File> filesWithUnknownImporter = new LinkedList<File>(); 214 229 FILES: for (File f : files) { … … 216 231 if (importer.acceptFile(f)) { 217 232 map.put(importer, f); 218 filesWithKnownImporter.add(f);219 233 continue FILES; 220 234 } … … 228 242 Collections.sort(ims); 229 243 Collections.reverse(ims); 244 245 Set<String> fileHistory = new LinkedHashSet<String>(); 246 230 247 for (FileImporter importer : ims) { 231 248 List<File> files = new ArrayList<File>(map.get(importer)); 232 249 importData(importer, files); 250 251 if (recordHistory && !importer.isBatchImporter()) { 252 for (File f : files) { 253 fileHistory.add(f.getPath()); 254 } 255 } 256 } 257 258 if (recordHistory) { 259 Collection<String> oldFileHistory = Main.pref.getCollection("file-open.history"); 260 fileHistory.addAll(oldFileHistory); 261 int maxsize = Math.max(0, Main.pref.getInteger("file-open.history.max-size", 15)); 262 Collection<String> trimmedFileHistory = new ArrayList<String>(Math.min(maxsize, fileHistory.size())); 263 int i = 0; 264 for (String s : fileHistory) { 265 if (++i > maxsize) { 266 break; 267 } 268 trimmedFileHistory.add(s); 269 } 270 Main.pref.putCollection("file-open.history", trimmedFileHistory); 233 271 } 234 272 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r3709 r3710 631 631 } 632 632 633 /** 634 * Get a list of values for a certain key 635 * @param key the identifier for the setting 636 * @return the corresponding value if the property has been set before, 637 * an empty Collection otherwise. 638 */ 639 synchronized public Collection<String> getCollection(String key) { 640 putCollectionDefault(key, null); 641 String s = get(key); 642 if (s != null && s.length() != 0) 643 return Arrays.asList(s.split("\u001e")); 644 return Collections.emptyList(); 645 } 646 633 647 synchronized public void removeFromCollection(String key, String value) { 634 648 List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList())); … … 638 652 639 653 synchronized public boolean putCollection(String key, Collection<String> val) { 640 String s = null; 641 if(val != null) 642 { 643 for(String a : val) 644 { 645 if (a == null) { 646 a = ""; 647 } 648 if(s != null) { 649 s += "\u001e" + a; 650 } else { 651 s = a; 652 } 653 } 654 } 655 return put(key, s); 654 return put(key, join("\u001e", val)); 656 655 } 657 656 658 657 synchronized private void putCollectionDefault(String key, Collection<String> val) { 659 if (val == null) { 660 putDefault(key, null); 661 } else { 662 String s = null; 663 for(String a : val) 664 { 665 if(s != null) { 666 s += "\u001e" + a; 667 } else { 668 s = a; 669 } 670 } 671 putDefault(key, s); 672 } 658 putDefault(key, join("\u001e", val)); 673 659 } 674 660 … … 766 752 } 767 753 754 /** 755 * Joins a collection of strings into a single string with fields 756 * separated by the value of sep. 757 * @param sep the separator 758 * @param values collection of strings, null strings are converted to the 759 * empty string 760 * @return null if values is null. The joined string otherwise. 761 */ 762 public static String join(String sep, Collection<?> values) { 763 if (values == null) 764 return null; 765 if (values.isEmpty()) 766 return ""; 767 StringBuilder s = null; 768 for (Object a : values) { 769 if (a == null) { 770 a = ""; 771 } 772 if(s != null) { 773 s.append(sep).append(a.toString()); 774 } else { 775 s = new StringBuilder(a.toString()); 776 } 777 } 778 return s.toString(); 779 } 780 768 781 } -
trunk/src/org/openstreetmap/josm/gui/FileDrop.java
r3385 r3710 78 78 // start asynchronous loading of files 79 79 OpenFileAction.OpenFileTask task = new OpenFileAction.OpenFileTask(Arrays.asList(files), null); 80 task.setRecordHistory(true); 80 81 Main.worker.submit(task); 81 82 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r3704 r3710 85 85 import org.openstreetmap.josm.actions.audio.AudioSlowerAction; 86 86 import org.openstreetmap.josm.actions.search.SearchAction; 87 import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu; 87 88 import org.openstreetmap.josm.gui.layer.Layer; 88 89 import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction; … … 102 103 public final NewAction newAction = new NewAction(); 103 104 public final OpenFileAction openFile = new OpenFileAction(); 105 public final RecentlyOpenedFilesMenu recentlyOpened = new RecentlyOpenedFilesMenu(); 104 106 public final OpenLocationAction openLocation = new OpenLocationAction(); 105 107 public final JosmAction save = new SaveAction(); … … 223 225 add(fileMenu, newAction); 224 226 add(fileMenu, openFile); 227 fileMenu.add(recentlyOpened); 225 228 add(fileMenu, openLocation); 226 229 fileMenu.addSeparator(); -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetMenu.java
r3083 r3710 58 58 Component co = (Component)s; 59 59 JPopupMenu pm = new JPopupMenu(getName()); 60 for(Component c : menu.getMenuComponents()) 60 for (Component c : menu.getMenuComponents()) { 61 61 pm.add(copyMenuComponent(c)); 62 {63 62 } 64 63 pm.show(co, co.getWidth()/2, co.getHeight()/2);
Note:
See TracChangeset
for help on using the changeset viewer.