1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package tim.prune.function;
import javax.swing.JOptionPane;
import tim.prune.App;
import tim.prune.GenericFunction;
import tim.prune.I18nManager;
import tim.prune.data.AudioClip;
import tim.prune.undo.UndoDeleteAudio;
/**
* Function to remove the currently selected audio clip
*/
public class RemoveAudioFunction extends GenericFunction
{
/**
* Constructor
* @param inApp App object
*/
public RemoveAudioFunction(App inApp) {
super(inApp);
}
/** @return name key */
public String getNameKey() {
return "function.removeaudio";
}
/**
* Perform the function
*/
public void begin()
{
// Delete the current audio, and optionally its point too, keeping undo information
AudioClip currentAudio = _app.getTrackInfo().getCurrentAudio();
if (currentAudio != null)
{
// Audio is selected, see if it has a point or not
boolean deleted = false;
UndoDeleteAudio undoAction = null;
if (currentAudio.getDataPoint() == null)
{
// no point attached, so just delete
undoAction = new UndoDeleteAudio(currentAudio, _app.getTrackInfo().getSelection().getCurrentAudioIndex(),
null, -1);
deleted = _app.getTrackInfo().deleteCurrentAudio(false);
}
else
{
// point is attached, so need to confirm point deletion
undoAction = new UndoDeleteAudio(currentAudio, _app.getTrackInfo().getSelection().getCurrentAudioIndex(),
currentAudio.getDataPoint(), _app.getTrackInfo().getTrack().getPointIndex(currentAudio.getDataPoint()));
int response = JOptionPane.showConfirmDialog(_app.getFrame(),
I18nManager.getText("dialog.deleteaudio.deletepoint"),
I18nManager.getText(getNameKey()), JOptionPane.YES_NO_CANCEL_OPTION);
boolean deletePointToo = (response == JOptionPane.YES_OPTION);
// Cancel delete if cancel pressed or dialog closed
if (response == JOptionPane.YES_OPTION || response == JOptionPane.NO_OPTION) {
deleted = _app.getTrackInfo().deleteCurrentAudio(deletePointToo);
}
}
// Add undo information to stack if necessary
if (deleted) {
_app.completeFunction(undoAction, currentAudio.getName() + " " + I18nManager.getText("confirm.media.removed"));
}
}
}
}
|