| 1634 | } |
| 1635 | |
| 1636 | void ImageViewer::removeImage(shared_ptr<Image> image) { |
| 1637 | const auto id = imageId(image); |
| 1638 | if (!id) { |
| 1639 | return; |
| 1640 | } |
| 1641 | |
| 1642 | if (mDragType == EMouseDragType::ImageButtonDrag) { |
| 1643 | // If we're currently dragging the to-be-removed image, stop. |
| 1644 | if (id == mDraggedImageButtonId) { |
| 1645 | requestLayoutUpdate(); |
| 1646 | mDragType = EMouseDragType::None; |
| 1647 | } else if (id < mDraggedImageButtonId) { |
| 1648 | --mDraggedImageButtonId; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | auto nextCandidate = nextImage(image, Forward); |
| 1653 | // If we rolled over, let's rather use the previous image. We don't want to jumpt to the beginning when deleting the last image in our |
| 1654 | // list. |
| 1655 | if (imageId(nextCandidate) < id) { |
| 1656 | nextCandidate = nextImage(image, Backward); |
| 1657 | } |
| 1658 | |
| 1659 | // If `nextImage` produced the same image again, this means that `image` is the only (visible) image and hence, after removal, should be |
| 1660 | // replaced by no selection at all. |
| 1661 | if (nextCandidate == image) { |
| 1662 | nextCandidate = nullptr; |
| 1663 | } |
| 1664 | |
| 1665 | // Reset all focus as a workaround a crash caused by nanogui. |
| 1666 | // TODO: Remove once a fix exists. |
| 1667 | request_focus(); |
| 1668 | |
| 1669 | mImages.erase(begin(mImages) + *id); |
| 1670 | mImageButtonContainer->remove_child_at((int)*id); |
| 1671 | |
| 1672 | if (mImages.empty()) { |
| 1673 | selectImage(nullptr); |
| 1674 | selectReference(nullptr); |
| 1675 | return; |
| 1676 | } |
| 1677 | |
| 1678 | if (mCurrentImage == image) { |
| 1679 | selectImage(nextCandidate); |
| 1680 | } |
| 1681 | |
| 1682 | if (mCurrentReference == image) { |
| 1683 | selectReference(nextCandidate); |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | void ImageViewer::removeAllImages() { |
| 1688 | if (mImages.empty()) { |
no test coverage detected