X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fundo%2FUndoLoadPhotos.java;h=b8c2b35970fbb05482ad8cfc4dd1bbe95aa0f08a;hb=4d5796d02a15808311c09448d79e6e7d1de9d636;hp=c08532d9ab9e01f9b4b819b5ccca88cf90f016ff;hpb=23959e65a6a0d581e657b07186d18b7a1ac5afeb;p=GpsPrune.git diff --git a/tim/prune/undo/UndoLoadPhotos.java b/tim/prune/undo/UndoLoadPhotos.java index c08532d..b8c2b35 100644 --- a/tim/prune/undo/UndoLoadPhotos.java +++ b/tim/prune/undo/UndoLoadPhotos.java @@ -1,6 +1,8 @@ package tim.prune.undo; import tim.prune.I18nManager; +import tim.prune.data.DataPoint; +import tim.prune.data.Photo; import tim.prune.data.TrackInfo; /** @@ -8,17 +10,19 @@ import tim.prune.data.TrackInfo; */ public class UndoLoadPhotos implements UndoOperation { - private int _numLoaded = -1; + private int _numPhotos = -1; + private int _numPoints = -1; - // TODO: Handle possibility of photos not having datapoints (yet) /** * Constructor - * @param inNumLoaded number of photos loaded + * @param inNumPhotos number of photos loaded + * @param inNumPoints number of points loaded */ - public UndoLoadPhotos(int inNumLoaded) + public UndoLoadPhotos(int inNumPhotos, int inNumPoints) { - _numLoaded = inNumLoaded; + _numPhotos = inNumPhotos; + _numPoints = inNumPoints; } @@ -28,8 +32,8 @@ public class UndoLoadPhotos implements UndoOperation public String getDescription() { String desc = I18nManager.getText("undo.loadphotos"); - if (_numLoaded > 0) - desc = desc + " (" + _numLoaded + ")"; + if (_numPhotos > 0) + desc = desc + " (" + _numPhotos + ")"; return desc; } @@ -41,12 +45,27 @@ public class UndoLoadPhotos implements UndoOperation */ public void performUndo(TrackInfo inTrackInfo) throws UndoException { + int cropIndex; // crop track to previous size - int cropIndex = inTrackInfo.getTrack().getNumPoints() - _numLoaded; - inTrackInfo.getTrack().cropTo(cropIndex); + if (_numPoints > 0) + { + cropIndex = inTrackInfo.getTrack().getNumPoints() - _numPoints; + inTrackInfo.getTrack().cropTo(cropIndex); + } + else + { + // Loop through the points (if any) and detach them + for (int i=0; i<_numPhotos; i++) + { + Photo photo = inTrackInfo.getPhotoList().getPhoto(inTrackInfo.getPhotoList().getNumPhotos() - 1 - i); + if (photo.isConnected()) { + DataPoint point = photo.getDataPoint(); + if (point != null) {point.setPhoto(null);} + } + } + } // crop photo list to previous size - // (currently it is assumed that the number of points is the same as number of photos) - cropIndex = inTrackInfo.getPhotoList().getNumPhotos() - _numLoaded; + cropIndex = inTrackInfo.getPhotoList().getNumPhotos() - _numPhotos; inTrackInfo.getPhotoList().cropTo(cropIndex); // clear selection inTrackInfo.getSelection().clearAll();