]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/undo/UndoLoad.java
Version 12, December 2010
[GpsPrune.git] / tim / prune / undo / UndoLoad.java
index c9aee483868cac1d4f4c20b2e481331f112c18bf..377f21c22f93f7b0a95f7c73378a30a09d5276c7 100644 (file)
@@ -2,6 +2,7 @@ package tim.prune.undo;
 \r
 import tim.prune.I18nManager;\r
 import tim.prune.data.DataPoint;\r
+import tim.prune.data.FileInfo;\r
 import tim.prune.data.PhotoList;\r
 import tim.prune.data.TrackInfo;\r
 \r
@@ -13,8 +14,10 @@ public class UndoLoad implements UndoOperation
        private int _cropIndex = -1;\r
        private int _numLoaded = -1;\r
        private DataPoint[] _contents = null;\r
-       private String _previousFilename = null;\r
        private PhotoList _photoList = null;\r
+       private FileInfo _oldFileInfo = null;\r
+       // Numbers of each media before operation\r
+       private int _numPhotos = -1, _numAudios = -1;\r
 \r
 \r
        /**\r
@@ -27,7 +30,6 @@ public class UndoLoad implements UndoOperation
                _cropIndex = inIndex;\r
                _numLoaded = inNumLoaded;\r
                _contents = null;\r
-               _previousFilename = null;\r
        }\r
 \r
 \r
@@ -42,8 +44,7 @@ public class UndoLoad implements UndoOperation
                _cropIndex = -1;\r
                _numLoaded = inNumLoaded;\r
                _contents = inOldTrackInfo.getTrack().cloneContents();\r
-               if (inOldTrackInfo.getFileInfo().getNumFiles() == 1)\r
-                       _previousFilename = inOldTrackInfo.getFileInfo().getFilename();\r
+               _oldFileInfo = inOldTrackInfo.getFileInfo().clone();\r
                _photoList = inPhotoList;\r
        }\r
 \r
@@ -59,6 +60,16 @@ public class UndoLoad implements UndoOperation
                return desc;\r
        }\r
 \r
+       /**\r
+        * Set the number of photos and audios before the load operation\r
+        * @param inNumPhotos number of photos\r
+        * @param inNumAudios number of audios\r
+        */\r
+       public void setNumPhotosAudios(int inNumPhotos, int inNumAudios)\r
+       {\r
+               _numPhotos = inNumPhotos;\r
+               _numAudios = inNumAudios;\r
+       }\r
 \r
        /**\r
         * Perform the undo operation on the given Track\r
@@ -66,11 +77,12 @@ public class UndoLoad implements UndoOperation
         */\r
        public void performUndo(TrackInfo inTrackInfo) throws UndoException\r
        {\r
-               // remove file from fileinfo\r
-               inTrackInfo.getFileInfo().removeFile();\r
-               if (_previousFilename != null)\r
-               {\r
-                       inTrackInfo.getFileInfo().setFile(_previousFilename);\r
+               // remove source from fileinfo\r
+               if (_oldFileInfo == null) {\r
+                       inTrackInfo.getFileInfo().removeSource();\r
+               }\r
+               else {\r
+                       inTrackInfo.setFileInfo(_oldFileInfo);\r
                }\r
                // Crop / replace\r
                if (_contents == null)\r
@@ -81,10 +93,12 @@ public class UndoLoad implements UndoOperation
                else\r
                {\r
                        // replace photos how they were\r
-                       if (_photoList != null)\r
-                       {\r
+                       if (_photoList != null) {\r
                                inTrackInfo.getPhotoList().restore(_photoList);\r
                        }\r
+                       // Crop media lists to previous size (if specified)\r
+                       if (_numPhotos > -1) {inTrackInfo.getPhotoList().cropTo(_numPhotos);}\r
+                       if (_numAudios > -1) {inTrackInfo.getAudioList().cropTo(_numAudios);}\r
                        // replace track contents with old\r
                        if (!inTrackInfo.getTrack().replaceContents(_contents))\r
                        {\r
@@ -94,4 +108,4 @@ public class UndoLoad implements UndoOperation
                // clear selection\r
                inTrackInfo.getSelection().clearAll();\r
        }\r
-}
\ No newline at end of file
+}\r