Skip to content

Commit

Permalink
Fixes & Updates.
Browse files Browse the repository at this point in the history
— "-pixelHeightInWidth:forcedFont:" in our NSString helper did not work at all.
— Rewrote the internal components of TVCInputPromptDialog to use smarter API.
  • Loading branch information
emsquared committed Jul 27, 2012
1 parent 5ac3028 commit 29feb95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
11 changes: 6 additions & 5 deletions Classes/Helpers/Cocoa (Objective-C)/NSStringHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -682,18 +682,19 @@ - (NSInteger)wrappedLineCount:(NSInteger)boundWidth lineMultiplier:(NSInteger)li

- (CGFloat)pixelHeightInWidth:(NSInteger)width forcedFont:(NSFont *)font
{
NSMutableAttributedString *baseMutable = self.mutableCopy;

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
[paragraphStyle setLineBreakMode:NSLineBreakByCharWrapping];

NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

attributes[NSFontAttributeName] = font;
attributes[NSParagraphStyleAttributeName] = paragraphStyle;

[baseMutable setAttributes:attributes range:NSMakeRange(0, baseMutable.length)];


NSAttributedString *baseMutable;

baseMutable = [NSAttributedString alloc];
baseMutable = [baseMutable initWithString:self attributes:attributes];

NSRect bounds = [baseMutable boundingRectWithSize:NSMakeSize(width, 0.0)
options:NSStringDrawingUsesLineFragmentOrigin];

Expand Down
48 changes: 18 additions & 30 deletions Classes/Views/TVCInputPromptDialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@

// Dirty NSAlert substitution

#define _textContainerWidth 298.0
#define _textContainerPadding 3
#define _textContainerHeightFix 5

#define _informativeTextFont [NSFont fontWithName:@"Lucida Grande" size:11.0]

@implementation TVCInputPromptDialog

Expand All @@ -62,47 +62,35 @@ - (void)alertWithMessageText:(NSString *)messageTitle
[self.userInputField setStringValue:userInputText];
}

[self.dialogTitle setStringValue:messageTitle];
[self.defaultButton setTitle:defaultButtonTitle];
[self.alternateButton setTitle:alternateButtonTitle];
[self.informationalText setStringValue:informativeText];
[self.defaultButton setTitle:defaultButtonTitle];
[self.alternateButton setTitle:alternateButtonTitle];

[self.dialogTitle setStringValue:messageTitle];
[self.informationalText setStringValue:informativeText];
}

- (void)runModal
{
NSRect infoTextFrame = [self.informationalText frame];

NSLayoutManager *layoutManager = [NSLayoutManager new];
NSString *informativeText = [self.informationalText stringValue];

NSTextStorage *textStorage = [[NSTextStorage alloc] initWithString:[self.informationalText stringValue]];
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(_textContainerWidth, FLT_MAX)];

[layoutManager addTextContainer:textContainer];

[textStorage addLayoutManager:layoutManager];
[textStorage addAttribute:NSFontAttributeName
value:[NSFont fontWithName:@"Lucida Grande" size:11.0]
range:NSMakeRange(0, [textStorage length])];

[textContainer setLineFragmentPadding:0.0];

[layoutManager glyphRangeForTextContainer:textContainer];

NSInteger newHeight = ([layoutManager usedRectForTextContainer:textContainer].size.height + _textContainerHeightFix);
NSInteger heightDiff = (infoTextFrame.size.height - newHeight);

NSRect windowFrame = [self.dialogWindow frame];
NSRect infoTextFrame = [self.informationalText frame];
NSRect windowFrame = [self.dialogWindow frame];

CGFloat newHeight = [informativeText pixelHeightInWidth:infoTextFrame.size.width
forcedFont:_informativeTextFont];

NSInteger heightDiff = (infoTextFrame.size.height - newHeight);

infoTextFrame.size.height = (newHeight + _textContainerPadding);
windowFrame.size.height = ((windowFrame.size.height - heightDiff) + _textContainerPadding);
infoTextFrame.size.height = (newHeight + _textContainerPadding);
windowFrame.size.height = ((windowFrame.size.height - heightDiff) + _textContainerPadding);

[self.dialogWindow setFrame:windowFrame display:NO animate:NO];
[self.dialogWindow makeKeyAndOrderFront:nil];

[self.informationalText setFrame:infoTextFrame];

while ([self.dialogWindow isVisible]) {
continue;
continue; // Loop until we have a value.
}
}

Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<key>TXBundleBuildCodeName</key>
<string>Turtle Soup</string>
<key>TXBundleBuildNumber</key>
<string>12124</string>
<string>12128</string>
<key>TXBundleBuildReference</key>
<string>2.1.1-263-g4604582-debug</string>
<string>2.1.1-264-g5ac3028-debug</string>
</dict>
</plist>

0 comments on commit 29feb95

Please sign in to comment.