Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/ImageData.java
r15333 r15348 263 263 264 264 /** 265 * Remove the current selected image from the list 266 * @since 15348 267 */ 268 public void removeSelectedImages() { 269 List<ImageEntry> selected = getSelectedImages(); 270 if (selected.isEmpty()) { 271 return; 272 } 273 for (ImageEntry img: getSelectedImages()) { 274 data.remove(img); 275 } 276 setSelectedImageIndex(-1, true); 277 } 278 279 /** 265 280 * Determines if the image is selected 266 281 * @param image the {@link ImageEntry} image -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java
r15333 r15348 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 6 7 import java.awt.BorderLayout; … … 289 290 private class ImageRemoveAction extends JosmAction { 290 291 ImageRemoveAction() { 291 super(null, new ImageProvider("dialogs", "delete"), tr("Remove photo from layer"), Shortcut.registerShortcut(292 "geoimage:deleteimagefromlayer", tr("Geoimage: {0}", tr("Remove photo from layer")), KeyEvent.VK_DELETE, Shortcut.SHIFT),292 super(null, new ImageProvider("dialogs", "delete"), tr("Remove photo(s) from layer"), Shortcut.registerShortcut( 293 "geoimage:deleteimagefromlayer", tr("Geoimage: {0}", tr("Remove photo(s) from layer")), KeyEvent.VK_DELETE, Shortcut.SHIFT), 293 294 false, null, false); 294 295 } … … 297 298 public void actionPerformed(ActionEvent e) { 298 299 if (currentData != null) { 299 currentData.removeSelectedImage ();300 currentData.removeSelectedImages(); 300 301 } 301 302 } … … 304 305 private class ImageRemoveFromDiskAction extends JosmAction { 305 306 ImageRemoveFromDiskAction() { 306 super(null, new ImageProvider("dialogs", "geoimage/deletefromdisk"), tr("Delete image filefrom disk"),307 super(null, new ImageProvider("dialogs", "geoimage/deletefromdisk"), tr("Delete photo file(s) from disk"), 307 308 Shortcut.registerShortcut( 308 "geoimage:deletefilefromdisk", tr("Geoimage: {0}", tr("Delete Filefrom disk")), KeyEvent.VK_DELETE, Shortcut.CTRL_SHIFT),309 "geoimage:deletefilefromdisk", tr("Geoimage: {0}", tr("Delete file(s) from disk")), KeyEvent.VK_DELETE, Shortcut.CTRL_SHIFT), 309 310 false, null, false); 310 311 } … … 313 314 public void actionPerformed(ActionEvent e) { 314 315 if (currentData != null && currentData.getSelectedImage() != null) { 315 ImageEntry toDelete = currentData.getSelectedImage(); 316 List<ImageEntry> toDelete = currentData.getSelectedImages(); 317 int size = toDelete.size(); 316 318 317 319 int result = new ExtendedDialog( … … 320 322 tr("Cancel"), tr("Delete")) 321 323 .setButtonIcons("cancel", "dialogs/delete") 322 .setContent(new JLabel("<html><h3>" + tr("Delete the file {0} from disk?", toDelete.getFile().getName()) 323 + "<p>" + tr("The image file will be permanently lost!") + "</h3></html>", 324 .setContent(new JLabel("<html><h3>" 325 + trn("Delete the file from disk?", 326 "Delete the {0} files from disk?", size, size) 327 + "<p>" + trn("The image file will be permanently lost!", 328 "The images files will be permanently lost!", size) + "</h3></html>", 324 329 ImageProvider.get("dialogs/geoimage/deletefromdisk"), SwingConstants.LEFT)) 325 330 .toggleEnable("geoimage.deleteimagefromdisk") … … 330 335 331 336 if (result == 2) { 332 currentData.removeSelectedImage(); 333 334 if (Utils.deleteFile(toDelete.getFile())) { 335 Logging.info("File " + toDelete.getFile() + " deleted."); 336 } else { 337 JOptionPane.showMessageDialog( 338 MainApplication.getMainFrame(), 339 tr("Image file could not be deleted."), 340 tr("Error"), 341 JOptionPane.ERROR_MESSAGE 342 ); 337 currentData.removeSelectedImages(); 338 for (ImageEntry delete : toDelete) { 339 if (Utils.deleteFile(delete.getFile())) { 340 Logging.info("File " + delete.getFile() + " deleted."); 341 } else { 342 JOptionPane.showMessageDialog( 343 MainApplication.getMainFrame(), 344 tr("Image file could not be deleted."), 345 tr("Error"), 346 JOptionPane.ERROR_MESSAGE 347 ); 348 } 343 349 } 344 350 } … … 497 503 imgDisplay.setOsdText(osd.toString()); 498 504 } else { 505 boolean hasMultipleImages = entries != null && entries.size() > 1; 499 506 // if this method is called to reinitialize dialog content with a blank image, 500 507 // do not actually show the dialog again with a blank image if currently hidden (fix #10672) … … 504 511 setNextEnabled(false); 505 512 setPreviousEnabled(false); 506 btnDelete.setEnabled( false);507 btnDeleteFromDisk.setEnabled( false);513 btnDelete.setEnabled(hasMultipleImages); 514 btnDeleteFromDisk.setEnabled(hasMultipleImages); 508 515 btnCopyPath.setEnabled(false); 509 if ( entries != null && entries.size() > 1) {516 if (hasMultipleImages) { 510 517 imgDisplay.setEmptyText(tr("Multiple images selected")); 511 518 btnFirst.setEnabled(!isFirstImageSelected(data)); -
trunk/test/unit/org/openstreetmap/josm/data/ImageDataTest.java
r15334 r15348 183 183 184 184 @Test 185 public void testRemoveSelectedWithImageTriggerListener() { 185 public void testRemoveSelectedImages() { 186 List<ImageEntry> list = getOneImage(); 187 list.add(new ImageEntry()); 188 189 ImageData data = new ImageData(list); 190 data.selectFirstImage(); 191 data.addImageToSelection(list.get(1)); 192 data.removeSelectedImages(); 193 assertEquals(0, data.getImages().size()); 194 assertEquals(0, data.getSelectedImages().size()); 195 } 196 197 @Test 198 public void testRemoveSelectedImageTriggerListener() { 186 199 List<ImageEntry> list = getOneImage(); 187 200 list.add(new ImageEntry()); … … 200 213 data.selectFirstImage(); 201 214 data.removeSelectedImage(); 215 } 216 217 @Test 218 public void testRemoveSelectedImagesTriggerListener() { 219 List<ImageEntry> list = getOneImage(); 220 list.add(new ImageEntry()); 221 ImageData data = new ImageData(list); 222 ImageDataUpdateListener listener = new ImageDataUpdateListener() { 223 @Override 224 public void selectedImageChanged(ImageData data) {} 225 226 @Override 227 public void imageDataUpdated(ImageData data) {} 228 }; 229 new Expectations(listener) {{ 230 listener.selectedImageChanged(data); times = 2; 231 }}; 232 data.addImageDataUpdateListener(listener); 233 data.selectFirstImage(); 234 data.removeSelectedImages(); 202 235 } 203 236
Note:
See TracChangeset
for help on using the changeset viewer.