Changeset 14668 in josm


Ignore:
Timestamp:
2019-01-08T21:33:32+01:00 (6 years ago)
Author:
simon04
Message:

fix #17185 - Do not offer unsupported file types for saving OsmDataLayer

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r13352 r14668  
    1313import java.util.Objects;
    1414import java.util.ServiceConfigurationError;
     15import java.util.function.Predicate;
    1516
    1617import javax.swing.filechooser.FileFilter;
     
    316317     * @param fileChooser the file chooser
    317318     * @param extension the default extension
    318      * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
    319      *                 If false, only the file filters that include {@code extension} will be proposed
    320      * @since 5438
    321      */
    322     public static void applyChoosableImportFileFilters(AbstractFileChooser fileChooser, String extension, boolean allTypes) {
     319     * @param additionalTypes matching types will additionally be added to the "file type" combobox.
     320     * @since 14668 (signature)
     321     */
     322    public static void applyChoosableImportFileFilters(
     323            AbstractFileChooser fileChooser, String extension, Predicate<ExtensionFileFilter> additionalTypes) {
    323324        for (ExtensionFileFilter filter: getImportExtensionFileFilters()) {
    324325
    325             if (allTypes || filter.acceptName("file."+extension)) {
     326            if (additionalTypes.test(filter) || filter.acceptName("file."+extension)) {
    326327                fileChooser.addChoosableFileFilter(filter);
    327328            }
     
    336337     * @param fileChooser the file chooser
    337338     * @param extension the default extension
    338      * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
    339      *                 If false, only the file filters that include {@code extension} will be proposed
    340      * @since 5438
    341      */
    342     public static void applyChoosableExportFileFilters(AbstractFileChooser fileChooser, String extension, boolean allTypes) {
     339     * @param additionalTypes matching types will additionally be added to the "file type" combobox.
     340     * @since 14668 (signature)
     341     */
     342    public static void applyChoosableExportFileFilters(
     343            AbstractFileChooser fileChooser, String extension, Predicate<ExtensionFileFilter> additionalTypes) {
    343344        for (ExtensionFileFilter filter: getExportExtensionFileFilters()) {
    344             if (allTypes || filter.acceptName("file."+extension)) {
     345            if (additionalTypes.test(filter) || filter.acceptName("file."+extension)) {
    345346                fileChooser.addChoosableFileFilter(filter);
    346347            }
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r14648 r14668  
    105105import org.openstreetmap.josm.gui.io.UploadDialog;
    106106import org.openstreetmap.josm.gui.io.UploadLayerTask;
     107import org.openstreetmap.josm.gui.io.importexport.NoteExporter;
    107108import org.openstreetmap.josm.gui.io.importexport.OsmImporter;
     109import org.openstreetmap.josm.gui.io.importexport.ValidatorErrorExporter;
     110import org.openstreetmap.josm.gui.io.importexport.WMSLayerImporter;
    108111import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
    109112import org.openstreetmap.josm.gui.preferences.display.DrawingPreference;
     
    11871190            .extension(extension)
    11881191            .file(file)
    1189             .allTypes(true)
     1192            .additionalTypes(t -> t != WMSLayerImporter.FILE_FILTER && t != NoteExporter.FILE_FILTER && t != ValidatorErrorExporter.FILE_FILTER)
    11901193            .getFileForSave();
    11911194    }
  • trunk/src/org/openstreetmap/josm/gui/widgets/FileChooserManager.java

    r14153 r14668  
    66import java.util.Collection;
    77import java.util.Collections;
     8import java.util.function.Predicate;
    89
    910import javax.swing.JFileChooser;
     
    4647    private int selectionMode = JFileChooser.FILES_ONLY;
    4748    private String extension;
    48     private boolean allTypes;
     49    private Predicate<ExtensionFileFilter> additionalTypes = ignore -> false;
    4950    private File file;
    5051
     
    261262
    262263    /**
     264     * Builder method to set {@code additionalTypes} property.
     265     * @param value matching types will additionally be added to the "file type" combobox.
     266     * @return this
     267     */
     268    public FileChooserManager additionalTypes(Predicate<ExtensionFileFilter> value) {
     269        additionalTypes = value;
     270        return this;
     271    }
     272
     273    /**
    263274     * Builder method to set {@code allTypes} property.
    264275     * @param value If true, all the files types known by JOSM will be proposed in the "file type" combobox.
     
    267278     */
    268279    public FileChooserManager allTypes(boolean value) {
    269         allTypes = value;
     280        additionalTypes = ignore -> value;
    270281        return this;
    271282    }
     
    311322            }
    312323        } else if (open) {
    313             ExtensionFileFilter.applyChoosableImportFileFilters(fc, extension, allTypes);
     324            ExtensionFileFilter.applyChoosableImportFileFilters(fc, extension, additionalTypes);
    314325        } else {
    315             ExtensionFileFilter.applyChoosableExportFileFilters(fc, extension, allTypes);
     326            ExtensionFileFilter.applyChoosableExportFileFilters(fc, extension, additionalTypes);
    316327        }
    317328        return this;
Note: See TracChangeset for help on using the changeset viewer.