Changeset 3710 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2010-12-10T10:15:21+01:00 (13 years ago)
Author:
bastiK
Message:

new list of recently opened files; little preference rework

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

Legend:

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

    r3679 r3710  
    1414import java.util.Collection;
    1515import java.util.Collections;
     16import java.util.LinkedHashSet;
    1617import java.util.LinkedList;
    1718import java.util.List;
    1819
     20import java.util.Set;
    1921import javax.swing.JFileChooser;
    2022import javax.swing.JOptionPane;
     
    5759        File[] files = fc.getSelectedFiles();
    5860        OpenFileTask task = new OpenFileTask(Arrays.asList(files), fc.getFileFilter());
     61        task.setRecordHistory(true);
    5962        Main.worker.submit(task);
    6063    }
     
    7982        private FileFilter fileFilter;
    8083        private boolean cancelled;
     84        private boolean recordHistory = false;
    8185
    8286        public OpenFileTask(List<File> files, FileFilter fileFilter, String title) {
     
    8892        public OpenFileTask(List<File> files, FileFilter fileFilter) {
    8993            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;
    90106        }
    91107
     
    167183            }
    168184            /**
    169              * If the filter wasn't changed in the dialog, chosenImporter is null now.
    170              * When the filter was explicitly set to 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.
    171187             */
    172188            if (chosenImporter instanceof AllFormatsImporter) {
     
    210226                // find appropriate importer
    211227                MultiMap<FileImporter, File> map = new MultiMap<FileImporter, File>();
    212                 List<File> filesWithKnownImporter = new LinkedList<File>();
    213228                List<File> filesWithUnknownImporter = new LinkedList<File>();
    214229                FILES: for (File f : files) {
     
    216231                        if (importer.acceptFile(f)) {
    217232                            map.put(importer, f);
    218                             filesWithKnownImporter.add(f);
    219233                            continue FILES;
    220234                        }
     
    228242                Collections.sort(ims);
    229243                Collections.reverse(ims);
     244
     245                Set<String> fileHistory = new LinkedHashSet<String>();
     246
    230247                for (FileImporter importer : ims) {
    231248                    List<File> files = new ArrayList<File>(map.get(importer));
    232249                    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);
    233271                }
    234272            }
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r3709 r3710  
    631631    }
    632632
     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
    633647    synchronized public void removeFromCollection(String key, String value) {
    634648        List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList()));
     
    638652
    639653    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));
    656655    }
    657656   
    658657    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));
    673659    }
    674660   
     
    766752    }
    767753
     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
    768781}
  • trunk/src/org/openstreetmap/josm/gui/FileDrop.java

    r3385 r3710  
    7878                        // start asynchronous loading of files
    7979                        OpenFileAction.OpenFileTask task = new OpenFileAction.OpenFileTask(Arrays.asList(files), null);
     80                        task.setRecordHistory(true);
    8081                        Main.worker.submit(task);
    8182                    }
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r3704 r3710  
    8585import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
    8686import org.openstreetmap.josm.actions.search.SearchAction;
     87import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
    8788import org.openstreetmap.josm.gui.layer.Layer;
    8889import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
     
    102103    public final NewAction newAction = new NewAction();
    103104    public final OpenFileAction openFile = new OpenFileAction();
     105    public final RecentlyOpenedFilesMenu recentlyOpened = new RecentlyOpenedFilesMenu();
    104106    public final OpenLocationAction openLocation = new OpenLocationAction();
    105107    public final JosmAction save = new SaveAction();
     
    223225        add(fileMenu, newAction);
    224226        add(fileMenu, openFile);
     227        fileMenu.add(recentlyOpened);
    225228        add(fileMenu, openLocation);
    226229        fileMenu.addSeparator();
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetMenu.java

    r3083 r3710  
    5858            Component co = (Component)s;
    5959            JPopupMenu pm = new JPopupMenu(getName());
    60             for(Component c : menu.getMenuComponents())
     60            for (Component c : menu.getMenuComponents()) {
    6161                pm.add(copyMenuComponent(c));
    62             {
    6362            }
    6463            pm.show(co, co.getWidth()/2, co.getHeight()/2);
Note: See TracChangeset for help on using the changeset viewer.