get rid of unneeded code by instead using built-in function
This commit is contained in:
parent
9d203de8ef
commit
263bf6934d
|
@ -36,9 +36,6 @@
|
||||||
+ (NSString *) stringForSpeedAbbrev: (float) speed;
|
+ (NSString *) stringForSpeedAbbrev: (float) speed;
|
||||||
+ (NSString *) stringForRatio: (float) ratio;
|
+ (NSString *) stringForRatio: (float) ratio;
|
||||||
|
|
||||||
- (NSAttributedString *) attributedStringFittingInWidth: (float) width
|
|
||||||
attributes: (NSDictionary *) attributes;
|
|
||||||
|
|
||||||
- (NSComparisonResult) compareIP: (NSString *) string;
|
- (NSComparisonResult) compareIP: (NSString *) string;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -79,7 +79,8 @@
|
||||||
|
|
||||||
+ (NSString *) stringForSpeed: (float) speed
|
+ (NSString *) stringForSpeed: (float) speed
|
||||||
{
|
{
|
||||||
return [[self stringForSpeedAbbrev: speed] stringByAppendingString: NSLocalizedString(@"B/s", "Transfer speed (Bytes per second)")];
|
return [[self stringForSpeedAbbrev: speed] stringByAppendingString:
|
||||||
|
NSLocalizedString(@"B/s", "Transfer speed (Bytes per second)")];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSString *) stringForSpeedAbbrev: (float) speed
|
+ (NSString *) stringForSpeedAbbrev: (float) speed
|
||||||
|
@ -108,56 +109,6 @@
|
||||||
return [NSString stringWithFormat: @"%.0f", ratio];
|
return [NSString stringWithFormat: @"%.0f", ratio];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSAttributedString *) attributedStringFittingInWidth: (float) width
|
|
||||||
attributes: (NSDictionary *) attributes
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
float realWidth = [self sizeWithAttributes: attributes].width;
|
|
||||||
|
|
||||||
/* The whole string fits */
|
|
||||||
if( realWidth <= width )
|
|
||||||
return [[[NSAttributedString alloc] initWithString: self attributes: attributes] autorelease];
|
|
||||||
|
|
||||||
float ellipsisWidth = [[NSString ellipsis] sizeWithAttributes: attributes].width;
|
|
||||||
|
|
||||||
/* Width is too small */
|
|
||||||
if ( ellipsisWidth > width )
|
|
||||||
return [[[NSAttributedString alloc] initWithString: @"" attributes: attributes] autorelease];
|
|
||||||
|
|
||||||
/* Don't worry about ellipsis until the end */
|
|
||||||
width -= ellipsisWidth;
|
|
||||||
|
|
||||||
/* Approximate how many characters we'll need to drop... */
|
|
||||||
i = [self length] * (width / realWidth);
|
|
||||||
|
|
||||||
/* ... then refine it */
|
|
||||||
NSString * newString = [self substringToIndex: i];
|
|
||||||
realWidth = [newString sizeWithAttributes: attributes].width;
|
|
||||||
|
|
||||||
if( realWidth < width )
|
|
||||||
{
|
|
||||||
NSString * smallerString;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
smallerString = newString;
|
|
||||||
newString = [self substringToIndex: ++i];
|
|
||||||
} while ([newString sizeWithAttributes: attributes].width <= width);
|
|
||||||
|
|
||||||
newString = smallerString;
|
|
||||||
}
|
|
||||||
else if( realWidth > width )
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
newString = [self substringToIndex: --i];
|
|
||||||
} while ([newString sizeWithAttributes: attributes].width > width);
|
|
||||||
}
|
|
||||||
else;
|
|
||||||
|
|
||||||
return [[[NSAttributedString alloc] initWithString: [newString stringByAppendingEllipsis]
|
|
||||||
attributes: attributes] autorelease];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSComparisonResult) compareIP: (NSString *) string
|
- (NSComparisonResult) compareIP: (NSString *) string
|
||||||
{
|
{
|
||||||
if ([self isEqualToString: string])
|
if ([self isEqualToString: string])
|
||||||
|
|
|
@ -171,12 +171,19 @@
|
||||||
{
|
{
|
||||||
BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: view]
|
BOOL highlighted = [self isHighlighted] && [[self highlightColorWithFrame: cellFrame inView: view]
|
||||||
isEqual: [NSColor alternateSelectedControlColor]];
|
isEqual: [NSColor alternateSelectedControlColor]];
|
||||||
|
|
||||||
|
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
|
||||||
|
[paragraphStyle setLineBreakMode: NSLineBreakByTruncatingTail];
|
||||||
|
|
||||||
NSDictionary * nameAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
NSDictionary * nameAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||||
highlighted ? [NSColor whiteColor] : [NSColor controlTextColor], NSForegroundColorAttributeName,
|
highlighted ? [NSColor whiteColor] : [NSColor controlTextColor], NSForegroundColorAttributeName,
|
||||||
[NSFont messageFontOfSize: 12.0], NSFontAttributeName, nil];
|
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
|
||||||
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
||||||
NSDictionary * statusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
NSDictionary * statusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||||
highlighted ? [NSColor whiteColor] : [NSColor darkGrayColor], NSForegroundColorAttributeName,
|
highlighted ? [NSColor whiteColor] : [NSColor darkGrayColor], NSForegroundColorAttributeName,
|
||||||
[NSFont messageFontOfSize: 9.0], NSFontAttributeName, nil];
|
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
|
||||||
|
paragraphStyle, NSParagraphStyleAttributeName, nil];
|
||||||
|
[paragraphStyle release];
|
||||||
|
|
||||||
NSPoint pen = cellFrame.origin;
|
NSPoint pen = cellFrame.origin;
|
||||||
const float PADDING = 3.0, LINE_PADDING = 2.0, EXTRA_NAME_SHIFT = 1.0;
|
const float PADDING = 3.0, LINE_PADDING = 2.0, EXTRA_NAME_SHIFT = 1.0;
|
||||||
|
@ -210,16 +217,17 @@
|
||||||
//name string
|
//name string
|
||||||
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
|
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
|
||||||
pen.y = cellFrame.origin.y + PADDING;
|
pen.y = cellFrame.origin.y + PADDING;
|
||||||
NSAttributedString * nameString = [[info objectForKey: @"Name"] attributedStringFittingInWidth: mainWidth
|
|
||||||
attributes: nameAttributes];
|
NSAttributedString * nameString = [[NSAttributedString alloc] initWithString: [info objectForKey: @"Name"]
|
||||||
[nameString drawAtPoint: pen];
|
attributes: nameAttributes];
|
||||||
|
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, [nameString size].height)];
|
||||||
|
|
||||||
//progress string
|
//progress string
|
||||||
pen.y += [nameString size].height + LINE_PADDING - 1.0;
|
pen.y += [nameString size].height + LINE_PADDING - 1.0;
|
||||||
|
|
||||||
NSAttributedString * progressString = [[info objectForKey: @"ProgressString"]
|
NSAttributedString * progressString = [[NSAttributedString alloc] initWithString:
|
||||||
attributedStringFittingInWidth: mainWidth attributes: statusAttributes];
|
[info objectForKey: @"ProgressString"] attributes: statusAttributes];
|
||||||
[progressString drawAtPoint: pen];
|
[progressString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, [progressString size].height)];
|
||||||
|
|
||||||
//progress bar
|
//progress bar
|
||||||
pen.x -= EXTRA_NAME_SHIFT;
|
pen.x -= EXTRA_NAME_SHIFT;
|
||||||
|
@ -235,9 +243,14 @@
|
||||||
//status string
|
//status string
|
||||||
pen.x += EXTRA_NAME_SHIFT;
|
pen.x += EXTRA_NAME_SHIFT;
|
||||||
pen.y += LINE_PADDING;
|
pen.y += LINE_PADDING;
|
||||||
NSAttributedString * statusString = [[info objectForKey: @"StatusString"]
|
|
||||||
attributedStringFittingInWidth: mainWidth attributes: statusAttributes];
|
NSAttributedString * statusString = [[NSAttributedString alloc] initWithString:
|
||||||
[statusString drawAtPoint: pen];
|
[info objectForKey: @"StatusString"] attributes: statusAttributes];
|
||||||
|
[statusString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, [statusString size].height)];
|
||||||
|
|
||||||
|
[nameString release];
|
||||||
|
[progressString release];
|
||||||
|
[statusString release];
|
||||||
}
|
}
|
||||||
else //small size
|
else //small size
|
||||||
{
|
{
|
||||||
|
@ -258,16 +271,17 @@
|
||||||
? [info objectForKey: @"RemainingTimeString"]
|
? [info objectForKey: @"RemainingTimeString"]
|
||||||
: [info objectForKey: @"ShortStatusString"];
|
: [info objectForKey: @"ShortStatusString"];
|
||||||
|
|
||||||
NSAttributedString * statusString = [[[NSAttributedString alloc] initWithString: realStatusString
|
NSAttributedString * statusString = [[NSAttributedString alloc] initWithString: realStatusString
|
||||||
attributes: statusAttributes] autorelease];
|
attributes: statusAttributes];
|
||||||
NSAttributedString * nameString = [[info objectForKey: @"Name"] attributedStringFittingInWidth:
|
NSAttributedString * nameString = [[NSAttributedString alloc] initWithString:
|
||||||
mainWidth - [statusString size].width - LINE_PADDING attributes: nameAttributes];
|
[info objectForKey: @"Name"] attributes: nameAttributes];
|
||||||
|
|
||||||
//place name string
|
//place name string
|
||||||
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
|
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
|
||||||
pen.y = cellFrame.origin.y + LINE_PADDING;
|
pen.y = cellFrame.origin.y + LINE_PADDING;
|
||||||
|
|
||||||
[nameString drawAtPoint: pen];
|
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth - [statusString size].width - LINE_PADDING,
|
||||||
|
[nameString size].height)];
|
||||||
|
|
||||||
//place status string
|
//place status string
|
||||||
pen.x = NSMaxX(cellFrame) - PADDING - [statusString size].width;
|
pen.x = NSMaxX(cellFrame) - PADDING - [statusString size].width;
|
||||||
|
@ -285,6 +299,9 @@
|
||||||
[self buildAdvancedBar: barWidth point: pen];
|
[self buildAdvancedBar: barWidth point: pen];
|
||||||
else
|
else
|
||||||
[self buildSimpleBar: barWidth point: pen];
|
[self buildSimpleBar: barWidth point: pen];
|
||||||
|
|
||||||
|
[nameString release];
|
||||||
|
[statusString release];
|
||||||
}
|
}
|
||||||
|
|
||||||
[nameAttributes release];
|
[nameAttributes release];
|
||||||
|
|
Loading…
Reference in New Issue