Simplify creating an OakEncodingPopUpButton

We now do the (sort of required) sizeToFit in the initializer. Users can still bypass this by using initWithFrame:pullsDown: instead of init:.
This commit is contained in:
Allan Odgaard
2012-08-20 22:34:38 +02:00
parent c3bb5857ed
commit 4606e4bca5
2 changed files with 12 additions and 6 deletions

View File

@@ -74,12 +74,7 @@ namespace
{
// TODO transliteration / BOM check box
NSAlert* alert = [[NSAlert alertWithMessageText:[NSString stringWithCxxString:text::format("Unable to save document using “%s” as encoding.", encoding.c_str())] defaultButton:@"Retry" alternateButton:@"Cancel" otherButton:nil informativeTextWithFormat:@"Please choose another encoding:"] retain];
OakEncodingPopUpButton* encodingChooser = [[[OakEncodingPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO] autorelease];
[encodingChooser sizeToFit];
NSRect frame = [encodingChooser frame];
if(NSWidth(frame) > 200)
[encodingChooser setFrameSize:NSMakeSize(200, NSHeight(frame))];
[alert setAccessoryView:encodingChooser];
[alert setAccessoryView:[[OakEncodingPopUpButton new] autorelease]];
[alert beginSheetModalForWindow:_window modalDelegate:_self didEndSelector:@selector(encodingSheetDidEnd:returnCode:contextInfo:) contextInfo:NULL];
[[alert window] recalculateKeyViewLoop];
}

View File

@@ -187,6 +187,17 @@ namespace // PopulateMenu{Flat,Hierarchical}
return self;
}
- (id)init
{
if(self = [self initWithFrame:NSZeroRect pullsDown:NO])
{
[self sizeToFit];
if(NSWidth([self frame]) > 200)
[self setFrameSize:NSMakeSize(200, NSHeight([self frame]))];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];