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.AudioClip;
9 import tim.prune.undo.UndoDeleteAudio;
12 * Function to remove the currently selected audio clip
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 AudioClip 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 final int pointIndex = _app.getTrackInfo().getTrack().getPointIndex(currentAudio.getDataPoint());
52 undoAction = new UndoDeleteAudio(currentAudio, _app.getTrackInfo().getSelection().getCurrentAudioIndex(),
53 currentAudio.getDataPoint(), pointIndex);
54 undoAction.setAtBoundaryOfSelectedRange(pointIndex == _app.getTrackInfo().getSelection().getStart() ||
55 pointIndex == _app.getTrackInfo().getSelection().getEnd());
56 int response = JOptionPane.showConfirmDialog(_app.getFrame(),
57 I18nManager.getText("dialog.deleteaudio.deletepoint"),
58 I18nManager.getText(getNameKey()), JOptionPane.YES_NO_CANCEL_OPTION);
59 boolean deletePointToo = (response == JOptionPane.YES_OPTION);
60 // Cancel delete if cancel pressed or dialog closed
61 if (response == JOptionPane.YES_OPTION || response == JOptionPane.NO_OPTION) {
62 deleted = _app.getTrackInfo().deleteCurrentAudio(deletePointToo);
65 // Add undo information to stack if necessary
67 _app.completeFunction(undoAction, currentAudio.getName() + " " + I18nManager.getText("confirm.media.removed"));