]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/function/RemoveAudioFunction.java
4f3b0ce7a0bea78614968246b5630a0d3b2d2568
[GpsPrune.git] / src / tim / prune / function / RemoveAudioFunction.java
1 package tim.prune.function;
2
3 import javax.swing.JOptionPane;
4
5 import tim.prune.App;
6 import tim.prune.GenericFunction;
7 import tim.prune.I18nManager;
8 import tim.prune.data.AudioClip;
9 import tim.prune.undo.UndoDeleteAudio;
10
11 /**
12  * Function to remove the currently selected audio clip
13  */
14 public class RemoveAudioFunction extends GenericFunction
15 {
16         /**
17          * Constructor
18          * @param inApp App object
19          */
20         public RemoveAudioFunction(App inApp) {
21                 super(inApp);
22         }
23
24         /** @return name key */
25         public String getNameKey() {
26                 return "function.removeaudio";
27         }
28
29         /**
30          * Perform the function
31          */
32         public void begin()
33         {
34                 // Delete the current audio, and optionally its point too, keeping undo information
35                 AudioClip currentAudio = _app.getTrackInfo().getCurrentAudio();
36                 if (currentAudio != null)
37                 {
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)
42                         {
43                                 // no point attached, so just delete
44                                 undoAction = new UndoDeleteAudio(currentAudio, _app.getTrackInfo().getSelection().getCurrentAudioIndex(),
45                                         null, -1);
46                                 deleted = _app.getTrackInfo().deleteCurrentAudio(false);
47                         }
48                         else
49                         {
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);
63                                 }
64                         }
65                         // Add undo information to stack if necessary
66                         if (deleted) {
67                                 _app.completeFunction(undoAction, currentAudio.getName() + " " + I18nManager.getText("confirm.media.removed"));
68                         }
69                 }
70         }
71 }