From b136fcbca4acebd6a90e6a5cad366d855b2c7512 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Tue, 4 Sep 2012 18:16:39 +0200 Subject: [PATCH] Proper implementation of setChoices: This will now reload the table view and resize the pop-up (if necessary). --- Frameworks/OakTextView/src/OakChoiceMenu.mm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Frameworks/OakTextView/src/OakChoiceMenu.mm b/Frameworks/OakTextView/src/OakChoiceMenu.mm index c4d55b2f..f3d03b24 100644 --- a/Frameworks/OakTextView/src/OakChoiceMenu.mm +++ b/Frameworks/OakTextView/src/OakChoiceMenu.mm @@ -75,6 +75,21 @@ enum action_t { kActionNop, kActionTab, kActionReturn, kActionCancel, kActionMov return choiceIndex == NSNotFound ? nil : [choices objectAtIndex:choiceIndex]; } +- (void)setChoices:(NSArray*)newChoices +{ + if([choices isEqualToArray:newChoices]) + return; + + id oldSelection = self.selectedChoice; + self.choiceIndex = NSNotFound; + [choices autorelease]; + choices = [newChoices retain]; + [tableView reloadData]; + self.choiceIndex = [choices indexOfObject:oldSelection]; + + [self sizeToFit]; +} + - (void)setChoiceIndex:(NSUInteger)newIndex { if(choiceIndex != newIndex)