Fixed #15 - no more ArrayOutOfBounds exception when deleting last stream

This commit is contained in:
Brita Keller 2019-06-25 22:15:13 +02:00
parent 4d4a6579c6
commit 15c24f0925
1 changed files with 15 additions and 3 deletions

View File

@ -826,15 +826,27 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
List<TrackEntry> streams = waveformPane.getStreamList(); List<TrackEntry> streams = waveformPane.getStreamList();
ISelection sel = waveformPane.getSelection(); ISelection sel = waveformPane.getSelection();
TrackEntry newSelection=null; TrackEntry newSelection=null;
if(sel instanceof IStructuredSelection && ((IStructuredSelection) sel).size()==2) { if(sel instanceof IStructuredSelection && ((IStructuredSelection) sel).size()==2) {
Iterator<?> it = ((IStructuredSelection)sel).iterator(); Iterator<?> it = ((IStructuredSelection)sel).iterator();
it.next(); it.next();
int idx = streams.indexOf(it.next()); int idx = streams.indexOf(it.next());
if(idx==streams.size()-1)
if(idx==streams.size()-1) {
//last stream gets deleted, no more selection
if(idx==0) {
newSelection=null;
}
//more than 1 stream left, last gets deleted, selection jumps to new last stream
else {
newSelection=streams.get(idx-1); newSelection=streams.get(idx-1);
else }
}
//more than 1 stream left, any stream but the last gets deleted, selection jumps to the next stream
else {
newSelection=streams.get(idx+1); newSelection=streams.get(idx+1);
} }
}
waveformPane.setSelection(new StructuredSelection()); waveformPane.setSelection(new StructuredSelection());
streams.remove(trackEntry); streams.remove(trackEntry);
if(newSelection!=null) { if(newSelection!=null) {