Ticket #21430: 21430.patch

File 21430.patch, 3.3 KB (added by taylor.smock, 3 years ago)

Fix deletion of images

  • src/org/openstreetmap/josm/data/imagery/street_level/IImageEntry.java

     
    9393    }
    9494
    9595    /**
     96     * Delete the image
     97     * @return {@code true} if deletion was successful
     98     * @throws UnsupportedOperationException If the implementation does not support deletion.
     99     * Use {@link #isDeleteSupported()}} to check for support.
     100     */
     101
     102    default boolean delete() {
     103        throw new UnsupportedOperationException("remove is not supported for " + this.getClass().getSimpleName());
     104    }
     105    /**
     106     * Check if image deletion is supported
     107     * @return {@code true} if deletion is supported
     108     */
     109    default boolean isDeleteSupported() {
     110        return false;
     111    }
     112
     113    /**
    96114     * Returns a display name for this entry (shown in image viewer title bar)
    97115     * @return a display name for this entry
    98116     */
  • src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java

     
    2525import org.openstreetmap.josm.tools.ExifReader;
    2626import org.openstreetmap.josm.tools.ImageProvider;
    2727import org.openstreetmap.josm.tools.Logging;
     28import org.openstreetmap.josm.tools.Utils;
    2829
    2930/**
    3031 * Stores info about each image, with an optional thumbnail
     
    190191        return true;
    191192    }
    192193
     194    @Override
     195    public boolean isDeleteSupported() {
     196        return true;
     197    }
     198
     199    @Override
     200    public boolean delete() {
     201        return Utils.deleteFile(this.getFile());
     202    }
     203
    193204    /**
    194205     * Reads the image represented by this entry in the given target dimension.
    195206     * @param target the desired dimension used for {@linkplain IIOParam#setSourceSubsampling subsampling} or {@code null}
  • src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

     
    358358                    final List<ImageData> imageDataCollection = toDelete.stream().filter(ImageEntry.class::isInstance)
    359359                            .map(ImageEntry.class::cast).map(ImageEntry::getDataSet).distinct().collect(Collectors.toList());
    360360                    for (IImageEntry<?> delete : toDelete) {
    361                         if (delete.isRemoveSupported() && delete.remove()) {
     361                        // We have to be able to remove the image from the layer and the image from its storage location
     362                        // If either are false, then don't remove the image.
     363                        if (delete.isRemoveSupported() && delete.isDeleteSupported() && delete.remove() && delete.delete()) {
    362364                            Logging.info("File {0} deleted.", delete.getFile());
    363365                        } else {
    364366                            JOptionPane.showMessageDialog(