1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

Get rid of unnecessary class by merging ellipsis code into StringAdditions.

This commit is contained in:
Mitchell Livingston 2006-06-14 20:08:51 +00:00
parent 341b6ef526
commit 4eb8918f3a
6 changed files with 26 additions and 45 deletions

View file

@ -29,7 +29,6 @@
#import "TorrentCell.h" #import "TorrentCell.h"
#import "TorrentTableView.h" #import "TorrentTableView.h"
#import "StringAdditions.h" #import "StringAdditions.h"
#import "Utils.h"
#import <Sparkle/Sparkle.h> #import <Sparkle/Sparkle.h>
@ -1272,17 +1271,17 @@ static void sleepCallBack( void * controller, io_service_t y,
} }
//append or remove ellipsis when needed //append or remove ellipsis when needed
NSString * title = [menuItem title]; NSString * title = [menuItem title], * ellipsis = [NSString ellipsis];
if (active && [fDefaults boolForKey: @"CheckRemove"]) if (active && [fDefaults boolForKey: @"CheckRemove"])
{ {
if (![title hasSuffix: NS_ELLIPSIS]) if (![title hasSuffix: ellipsis])
[menuItem setTitle: [title stringByAppendingString: NS_ELLIPSIS]]; [menuItem setTitle: [title stringByAppendingEllipsis]];
} }
else else
{ {
if ([title hasSuffix: NS_ELLIPSIS]) if ([title hasSuffix: ellipsis])
[menuItem setTitle: [title substringToIndex: [menuItem setTitle: [title substringToIndex:
[title rangeOfString: NS_ELLIPSIS].location]]; [title rangeOfString: ellipsis].location]];
} }
return canUseMenu && [fTableView numberOfSelectedRows] > 0; return canUseMenu && [fTableView numberOfSelectedRows] > 0;
} }

View file

@ -24,7 +24,6 @@
#import "PrefsController.h" #import "PrefsController.h"
#import "StringAdditions.h" #import "StringAdditions.h"
#import "Utils.h"
#define MIN_PORT 1 #define MIN_PORT 1
#define MAX_PORT 65535 #define MAX_PORT 65535
@ -472,10 +471,10 @@
[panel setCanChooseFiles: NO]; [panel setCanChooseFiles: NO];
[panel setCanChooseDirectories: YES]; [panel setCanChooseDirectories: YES];
[panel beginSheetForDirectory: NULL file: NULL types: NULL [panel beginSheetForDirectory: nil file: nil types: nil
modalForWindow: [self window] modalDelegate: self didEndSelector: modalForWindow: [self window] modalDelegate: self didEndSelector:
@selector( folderSheetClosed:returnCode:contextInfo: ) @selector( folderSheetClosed:returnCode:contextInfo: )
contextInfo: NULL]; contextInfo: nil];
} }
@end @end

View file

@ -26,6 +26,9 @@
@interface NSString (StringAdditions) @interface NSString (StringAdditions)
+ (NSString *) ellipsis;
- (NSString *) stringByAppendingEllipsis;
+ (NSString *) stringWithInt: (int) value; + (NSString *) stringWithInt: (int) value;
+ (NSString *) stringForFileSize: (uint64_t) size; + (NSString *) stringForFileSize: (uint64_t) size;

View file

@ -23,10 +23,19 @@
*****************************************************************************/ *****************************************************************************/
#import "StringAdditions.h" #import "StringAdditions.h"
#import "Utils.h"
@implementation NSString (StringAdditions) @implementation NSString (StringAdditions)
+ (NSString *) ellipsis
{
return [NSString stringWithUTF8String: "\xE2\x80\xA6"];
}
- (NSString *) stringByAppendingEllipsis
{
return [self stringByAppendingString: [NSString ellipsis]];
}
+ (NSString *) stringWithInt: (int) value + (NSString *) stringWithInt: (int) value
{ {
return [NSString stringWithFormat: @"%d", value]; return [NSString stringWithFormat: @"%d", value];
@ -114,7 +123,7 @@
if( realWidth <= width ) if( realWidth <= width )
return [[[NSAttributedString alloc] initWithString: self attributes: attributes] autorelease]; return [[[NSAttributedString alloc] initWithString: self attributes: attributes] autorelease];
float ellipsisWidth = [NS_ELLIPSIS sizeWithAttributes: attributes].width; float ellipsisWidth = [[NSString ellipsis] sizeWithAttributes: attributes].width;
/* Width is too small */ /* Width is too small */
if ( ellipsisWidth > width ) if ( ellipsisWidth > width )
@ -150,7 +159,7 @@
} }
else; else;
return [[[NSAttributedString alloc] initWithString: [newString stringByAppendingString: NS_ELLIPSIS] return [[[NSAttributedString alloc] initWithString: [newString stringByAppendingEllipsis]
attributes: attributes] autorelease]; attributes: attributes] autorelease];
} }

View file

@ -24,7 +24,6 @@
#import "Torrent.h" #import "Torrent.h"
#import "StringAdditions.h" #import "StringAdditions.h"
#import "Utils.h"
@interface Torrent (Private) @interface Torrent (Private)
@ -167,7 +166,7 @@
break; break;
case TR_STATUS_CHECK: case TR_STATUS_CHECK:
[fStatusString setString: [@"Checking existing files" stringByAppendingString: NS_ELLIPSIS]]; [fStatusString setString: [@"Checking existing files" stringByAppendingEllipsis]];
break; break;
case TR_STATUS_DOWNLOAD: case TR_STATUS_DOWNLOAD:
@ -202,7 +201,7 @@
break; break;
case TR_STATUS_STOPPING: case TR_STATUS_STOPPING:
[fStatusString setString: [@"Stopping" stringByAppendingString: NS_ELLIPSIS]]; [fStatusString setString: [@"Stopping" stringByAppendingEllipsis]];
break; break;
} }
@ -364,7 +363,7 @@
break; break;
case TR_STATUS_CHECK: case TR_STATUS_CHECK:
return [@"Checking existing files" stringByAppendingString: NS_ELLIPSIS]; return [@"Checking existing files" stringByAppendingEllipsis];
break; break;
case TR_STATUS_DOWNLOAD: case TR_STATUS_DOWNLOAD:
@ -376,7 +375,7 @@
break; break;
case TR_STATUS_STOPPING: case TR_STATUS_STOPPING:
return [@"Stopping" stringByAppendingString: NS_ELLIPSIS]; return [@"Stopping" stringByAppendingEllipsis];
break; break;
default: default:

View file

@ -1,28 +0,0 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2005-2006 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#define NS_ELLIPSIS [NSString stringWithUTF8String: "\xE2\x80\xA6"]
#define OSX_VERSION [[[NSDictionary dictionaryWithContentsOfFile: \
@"/System/Library/CoreServices/SystemVersion.plist"] \
objectForKey: @"ProductVersion"] floatValue]