Ignore:
Timestamp:
2011-08-28T13:30:33+02:00 (15 years ago)
Author:
simon04
Message:

fix #6728 - add saved files to "open recent" menu

File:
1 edited

Legend:

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

    r4114 r4371  
    77import java.io.File;
    88import java.io.IOException;
    9 
     9import java.util.Collection;
     10import java.util.LinkedList;
     11import java.util.List;
    1012import javax.swing.JFileChooser;
    1113import javax.swing.JOptionPane;
     
    2325
    2426public abstract class SaveActionBase extends DiskAccessAction {
     27    private File file;
    2528
    2629    public SaveActionBase(String name, String iconName, String tooltip, Shortcut shortcut) {
     
    2831    }
    2932
     33    @Override
    3034    public void actionPerformed(ActionEvent e) {
    31         if (!isEnabled())
    32             return;
    33         doSave();
     35        if (!isEnabled()) {
     36            return;
     37        }
     38        boolean saved = doSave();
     39        if (saved) {
     40            addToFileOpenHistory();
     41        }
    3442    }
    3543
     
    4856        if(!checkSaveConditions(layer))
    4957            return false;
    50         return doInternalSave(layer, getFile(layer));
     58        file = getFile(layer);
     59        return doInternalSave(layer, file);
    5160    }
    5261
     
    224233        return true;
    225234    }
     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    }
    226250}
Note: See TracChangeset for help on using the changeset viewer.