Handle the case where pasteboard selector returns “no selection” (-1)

This is based on a bug report which I have been unable to reproduce, as the pasteboard selector should always have one item selected.
This commit is contained in:
Allan Odgaard
2017-07-12 11:49:00 +02:00
parent 511e370b77
commit 5c853a7cb2

View File

@@ -590,16 +590,19 @@ static BOOL HasPersistentStore = NO;
[pasteboardSelector setWidth:width];
if(singleClick)
[pasteboardSelector setPerformsActionOnSingleClick];
selectedRow = [pasteboardSelector showAtLocation:location];
NSSet* keep = [NSSet setWithArray:[pasteboardSelector entries]];
NSInteger newSelection = [pasteboardSelector showAtLocation:location];
NSArray* newEntries = [pasteboardSelector entries];
NSSet* keep = [NSSet setWithArray:newEntries];
for(OakPasteboardEntry* entry in entries)
{
if(![keep containsObject:entry])
[entry.managedObjectContext deleteObject:entry];
}
self.currentEntry = [[pasteboardSelector entries] objectAtIndex:selectedRow];
if(newSelection != -1)
self.currentEntry = [newEntries objectAtIndex:newSelection];
return [pasteboardSelector shouldSendAction];
}