Changeset 18685 in josm


Ignore:
Timestamp:
2023-03-07T21:44:32+01:00 (22 months ago)
Author:
taylor.smock
Message:

Fix #22767: Geotagged image deletion does not move to the next/previous image

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r18613 r18685  
    573573                    imageEntry.remove();
    574574                }
     575                selectNextImageAfterDeletion(imageEntry);
     576            }
     577        }
     578
     579        /**
     580         * Select the logical next entry after deleting the currently viewed image
     581         * @param oldEntry The image entry that was just deleted
     582         */
     583        private void selectNextImageAfterDeletion(IImageEntry<?> oldEntry) {
     584            final IImageEntry<?> currentImageEntry = ImageViewerDialog.this.currentEntry;
     585            // This is mostly just in case something changes the displayed entry (aka avoid race condition) or an image provider
     586            // sets the next image itself.
     587            if (Objects.equals(currentImageEntry, oldEntry)) {
     588                final IImageEntry<?> nextImage;
     589                if (oldEntry instanceof ImageEntry) {
     590                    nextImage = ((ImageEntry) oldEntry).getDataSet().getSelectedImage();
     591                } else if (oldEntry.getNextImage() != null) {
     592                    nextImage = oldEntry.getNextImage();
     593                } else if (oldEntry.getPreviousImage() != null) {
     594                    nextImage = oldEntry.getPreviousImage();
     595                } else {
     596                    nextImage = null;
     597                }
     598                ImageViewerDialog.getInstance().displayImages(nextImage == null ? null : Collections.singletonList(nextImage));
    575599            }
    576600        }
     
    588612        public void actionPerformed(ActionEvent e) {
    589613            if (currentEntry != null) {
    590                 List<IImageEntry<?>> toDelete = currentEntry instanceof ImageEntry ?
    591                         new ArrayList<>(((ImageEntry) currentEntry).getDataSet().getSelectedImages())
    592                         : Collections.singletonList(currentEntry);
     614                IImageEntry<?> oldEntry = ImageViewerDialog.this.currentEntry;
     615                List<IImageEntry<?>> toDelete = oldEntry instanceof ImageEntry ?
     616                        new ArrayList<>(((ImageEntry) oldEntry).getDataSet().getSelectedImages())
     617                        : Collections.singletonList(oldEntry);
    593618                int size = toDelete.size();
    594619
     
    631656                        data.updateSelectedImage();
    632657                    });
     658                    ImageViewerDialog.this.imageRemoveAction.selectNextImageAfterDeletion(oldEntry);
    633659                }
    634660            }
Note: See TracChangeset for help on using the changeset viewer.