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.AudioFile;
9 import tim.prune.undo.UndoDeleteAudio;
12 * Function to remove the currently selected audio file
14 public class RemoveAudioFunction extends GenericFunction
18 * @param inApp App object
20 public RemoveAudioFunction(App inApp) {
24 /** @return name key */
25 public String getNameKey() {
26 return "function.removeaudio";
30 * Perform the function
34 // Delete the current audio, and optionally its point too, keeping undo information
35 AudioFile currentAudio = _app.getTrackInfo().getCurrentAudio();
36 if (currentAudio != null)
38 // Audio is selected, see if it has a point or not
39 boolean deleted = false;
40 UndoDeleteAudio undoAction = null;
41 if (currentAudio.getDataPoint() == null)
43 // no point attached, so just delete
44 undoAction = new UndoDeleteAudio(currentAudio, _app.getTrackInfo().getSelection().getCurrentAudioIndex(),
46 deleted = _app.getTrackInfo().deleteCurrentAudio(false);
50 // point is attached, so need to confirm point deletion
51 undoAction = new UndoDeleteAudio(currentAudio, _app.getTrackInfo().getSelection().getCurrentAudioIndex(),
52 currentAudio.getDataPoint(), _app.getTrackInfo().getTrack().getPointIndex(currentAudio.getDataPoint()));
53 int response = JOptionPane.showConfirmDialog(_app.getFrame(),
54 I18nManager.getText("dialog.deleteaudio.deletepoint"),
55 I18nManager.getText(getNameKey()), JOptionPane.YES_NO_CANCEL_OPTION);
56 boolean deletePointToo = (response == JOptionPane.YES_OPTION);
57 // Cancel delete if cancel pressed or dialog closed
58 if (response == JOptionPane.YES_OPTION || response == JOptionPane.NO_OPTION) {
59 deleted = _app.getTrackInfo().deleteCurrentAudio(deletePointToo);
62 // Add undo information to stack if necessary
64 _app.completeFunction(undoAction, currentAudio.getFile().getName() + " " + I18nManager.getText("confirm.media.removed"));