1 package tim.prune.function;
3 import javax.swing.JOptionPane;
6 import tim.prune.GenericFunction;
7 import tim.prune.I18nManager;
8 import tim.prune.data.Photo;
9 import tim.prune.undo.UndoDeletePhoto;
12 * Function to remove the currently selected photo
14 public class RemovePhotoFunction extends GenericFunction
18 * @param inApp App object
20 public RemovePhotoFunction(App inApp) {
24 /** @return name key */
25 public String getNameKey() {
26 return "function.removephoto";
30 * Perform the function
34 // Delete the current photo, and optionally its point too, keeping undo information
35 Photo currentPhoto = _app.getTrackInfo().getCurrentPhoto();
36 if (currentPhoto != null)
38 // Photo is selected, see if it has a point or not
39 boolean photoDeleted = false;
40 UndoDeletePhoto undoAction = null;
41 if (currentPhoto.getDataPoint() == null)
43 // no point attached, so just delete photo
44 undoAction = new UndoDeletePhoto(currentPhoto, _app.getTrackInfo().getSelection().getCurrentPhotoIndex(),
46 photoDeleted = _app.getTrackInfo().deleteCurrentPhoto(false);
50 // point is attached, so need to confirm point deletion
51 undoAction = new UndoDeletePhoto(currentPhoto, _app.getTrackInfo().getSelection().getCurrentPhotoIndex(),
52 currentPhoto.getDataPoint(), _app.getTrackInfo().getTrack().getPointIndex(currentPhoto.getDataPoint()));
53 int response = JOptionPane.showConfirmDialog(_app.getFrame(),
54 I18nManager.getText("dialog.deletephoto.deletepoint"),
55 I18nManager.getText("dialog.deletephoto.title"),
56 JOptionPane.YES_NO_CANCEL_OPTION);
57 boolean deletePointToo = (response == JOptionPane.YES_OPTION);
58 // Cancel delete if cancel pressed or dialog closed
59 if (response == JOptionPane.YES_OPTION || response == JOptionPane.NO_OPTION) {
60 photoDeleted = _app.getTrackInfo().deleteCurrentPhoto(deletePointToo);
63 // Add undo information to stack if necessary
65 _app.completeFunction(undoAction, currentPhoto.getName() + " " + I18nManager.getText("confirm.media.removed"));