Revision: 17928
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=17928&view=rev
Author: hofman
Date: 2011-06-03 10:58:13 +0000 (Fri, 03 Jun 2011)
Log Message:
-----------
Use temporary collection for sorting by local URL fields so we don't need an
extra userInfo for the sort descriptor.
Modified Paths:
--------------
trunk/bibdesk/BDSKTableSortDescriptor.h
trunk/bibdesk/BDSKTableSortDescriptor.m
trunk/bibdesk/BibDocument.m
trunk/bibdesk/BibItem.h
trunk/bibdesk/BibItem.m
trunk/bibdesk/NSString_BDSKExtensions.h
trunk/bibdesk/NSString_BDSKExtensions.m
trunk/bibdesk/NSURL_BDSKExtensions.h
trunk/bibdesk/NSURL_BDSKExtensions.m
Modified: trunk/bibdesk/BDSKTableSortDescriptor.h
===================================================================
--- trunk/bibdesk/BDSKTableSortDescriptor.h 2011-06-03 06:35:19 UTC (rev
17927)
+++ trunk/bibdesk/BDSKTableSortDescriptor.h 2011-06-03 10:58:13 UTC (rev
17928)
@@ -45,12 +45,8 @@
CFIndex keyCount;
SEL selector;
BOOL ascending;
- id userInfo;
}
-+ (BDSKTableSortDescriptor *)tableSortDescriptorForIdentifier:(NSString *)tcID
ascending:(BOOL)ascend userInfo:(id)userInfo;
+ (BDSKTableSortDescriptor *)tableSortDescriptorForIdentifier:(NSString *)tcID
ascending:(BOOL)ascend;
-- (id)initWithKey:(NSString *)key ascending:(BOOL)flag selector:(SEL)theSel
userInfo:(id)info;
-
@end
Modified: trunk/bibdesk/BDSKTableSortDescriptor.m
===================================================================
--- trunk/bibdesk/BDSKTableSortDescriptor.m 2011-06-03 06:35:19 UTC (rev
17927)
+++ trunk/bibdesk/BDSKTableSortDescriptor.m 2011-06-03 10:58:13 UTC (rev
17928)
@@ -42,16 +42,13 @@
#import "NSColor_BDSKExtensions.h"
#import "BibAuthor.h"
#import "NSString_BDSKExtensions.h"
+#import "NSURL_BDSKExtensions.h"
@implementation BDSKTableSortDescriptor
+ (BDSKTableSortDescriptor *)tableSortDescriptorForIdentifier:(NSString *)tcID
ascending:(BOOL)ascend{
- return [self tableSortDescriptorForIdentifier:tcID ascending:ascend
userInfo:nil];
-}
-+ (BDSKTableSortDescriptor *)tableSortDescriptorForIdentifier:(NSString *)tcID
ascending:(BOOL)ascend userInfo:(id)userInfo{
-
NSParameterAssert([NSString isEmptyString:tcID] == NO);
BDSKTableSortDescriptor *sortDescriptor = nil;
@@ -151,15 +148,7 @@
}else if([tcID isLocalFileField]){
// compare UTI for file fields so the subsort is more useful
- if ([userInfo respondsToSelector:@selector(stringByStandardizingPath)])
- userInfo = [userInfo stringByStandardizingPath];
- else
- userInfo = nil;
- BOOL isDir = NO;
- if (userInfo && [[NSFileManager defaultManager]
fileExistsAtPath:userInfo isDirectory:&isDir] && isDir)
- sortDescriptor = [[self alloc] initWithKey:tcID ascending:ascend
selector:@selector(UTICompare:basePath:) userInfo:userInfo];
- else
- sortDescriptor = [[self alloc] initWithKey:tcID ascending:ascend
selector:@selector(UTICompare:)];
+ sortDescriptor = [[self alloc] initWithKey:[NSString
stringWithFormat:@"URLFields.%@", tcID] ascending:ascend
selector:@selector(UTICompare:)];
}else if([tcID isEqualToString:BDSKLocalFileString]){
@@ -193,18 +182,12 @@
- (id)initWithKey:(NSString *)key ascending:(BOOL)flag selector:(SEL)theSel;
{
- return [self initWithKey:key ascending:flag selector:theSel userInfo:nil];
-}
-
-- (id)initWithKey:(NSString *)key ascending:(BOOL)flag selector:(SEL)theSel
userInfo:(id)info;
-{
if(self = [super initWithKey:key ascending:flag selector:theSel]){
[self cacheKeys];
// since NSSortDescriptor ivars are declared @private, we have to use
@defs to access them directly; use our own instead, since this won't be
subclassed
selector = theSel;
ascending = flag;
- userInfo = [info retain];
}
return self;
}
@@ -216,7 +199,6 @@
[self cacheKeys];
selector = [self selector];
ascending = [self ascending];
- userInfo = [([aCoder allowsKeyedCoding] ? [aCoder
decodeObjectForKey:@"userInfo"] : [aCoder decodeObject]) retain];
}
return self;
}
@@ -224,24 +206,22 @@
- (void)encodeWithCoder:(NSCoder *)aCoder
{
[super encodeWithCoder:aCoder];
- [aCoder allowsKeyedCoding] ? [aCoder encodeObject:userInfo
forKey:@"userInfo"] : [aCoder encodeObject:userInfo];
}
- (id)copyWithZone:(NSZone *)aZone
{
- return [[[self class] allocWithZone:aZone] initWithKey:[self key]
ascending:[self ascending] selector:[self selector] userInfo:userInfo];
+ return [[[self class] allocWithZone:aZone] initWithKey:[self key]
ascending:[self ascending] selector:[self selector]];
}
- (void)dealloc
{
BDSKCFDESTROY(keys);
- BDSKDESTROY(userInfo);
[super dealloc];
}
- (id)reversedSortDescriptor
{
- return [[[[self class] alloc] initWithKey:[self key] ascending:NO ==
ascending selector:selector userInfo:userInfo] autorelease];
+ return [[[[self class] alloc] initWithKey:[self key] ascending:NO ==
ascending selector:selector] autorelease];
}
static inline void __GetValuesUsingCache(BDSKTableSortDescriptor *sort, id
object1, id object2, id *value1, id *value2)
@@ -284,19 +264,11 @@
NSComparisonResult result;
- if (userInfo) {
- // we use the IMP directly since performSelector: returns an id
- typedef NSComparisonResult (*comparatorIMP)(id, SEL, id, id);
- comparatorIMP comparator = (comparatorIMP)[value1
methodForSelector:selector];
- result = comparator(value1, selector, value2, userInfo);
- } else {
- // we use the IMP directly since performSelector: returns an id
- typedef NSComparisonResult (*comparatorIMP)(id, SEL, id);
- comparatorIMP comparator = (comparatorIMP)[value1
methodForSelector:selector];
- result = comparator(value1, selector, value2);
- }
+ // we use the IMP directly since performSelector: returns an id
+ typedef NSComparisonResult (*comparatorIMP)(id, SEL, id);
+ comparatorIMP comparator = (comparatorIMP)[value1
methodForSelector:selector];
+ result = comparator(value1, selector, value2);
-
return ascending ? result : -result;
}
Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2011-06-03 06:35:19 UTC (rev 17927)
+++ trunk/bibdesk/BibDocument.m 2011-06-03 10:58:13 UTC (rev 17928)
@@ -2498,10 +2498,9 @@
docFlags.previousSortDescending = docFlags.sortDescending;
}
- NSString *userInfo = [[self fileURL] path];
NSMutableArray *sortDescriptors = [NSMutableArray arrayWithObjects:
- [BDSKTableSortDescriptor tableSortDescriptorForIdentifier:sortKey
ascending:!docFlags.sortDescending userInfo:userInfo],
- [BDSKTableSortDescriptor
tableSortDescriptorForIdentifier:previousSortKey
ascending:!docFlags.previousSortDescending userInfo:userInfo], nil];
+ [BDSKTableSortDescriptor tableSortDescriptorForIdentifier:sortKey
ascending:!docFlags.sortDescending],
+ [BDSKTableSortDescriptor
tableSortDescriptorForIdentifier:previousSortKey
ascending:!docFlags.previousSortDescending], nil];
// Set the graphic for the new column header
NSTableColumn *oldTC = [tableView highlightedTableColumn];
@@ -2510,7 +2509,7 @@
if (tmpSortKey) {
newTC = [tableView tableColumnWithIdentifier:tmpSortKey];
ascending = !docFlags.tmpSortDescending;
- [sortDescriptors insertObject:[BDSKTableSortDescriptor
tableSortDescriptorForIdentifier:tmpSortKey
ascending:!docFlags.tmpSortDescending userInfo:userInfo] atIndex:0];
+ [sortDescriptors insertObject:[BDSKTableSortDescriptor
tableSortDescriptorForIdentifier:tmpSortKey
ascending:!docFlags.tmpSortDescending] atIndex:0];
} else {
newTC = [tableView tableColumnWithIdentifier:sortKey];
ascending = !docFlags.sortDescending;
Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h 2011-06-03 06:35:19 UTC (rev 17927)
+++ trunk/bibdesk/BibItem.h 2011-06-03 10:58:13 UTC (rev 17928)
@@ -795,6 +795,8 @@
// NSURL equivalents of the localFilePath... methods
- (NSURL *)localFileURLForField:(NSString *)field;
+- (BDSKFieldCollection *)URLFields;
+
- (BOOL)isValidLocalFilePath:(NSString *)proposedPath;
- (void)customFieldsDidChange:(NSNotification *)aNotification;
Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m 2011-06-03 06:35:19 UTC (rev 17927)
+++ trunk/bibdesk/BibItem.m 2011-06-03 10:58:13 UTC (rev 17928)
@@ -2631,6 +2631,12 @@
return [[self localURL] path];
}
+- (BDSKFieldCollection *)URLFields {
+ BDSKFieldCollection *collection = [[[BDSKFieldCollection alloc]
initWithItem:self] autorelease];
+ [collection setType:BDSKURLFieldCollection];
+ return collection;
+}
+
#pragma mark File conversion
typedef struct _conversionContext {
Modified: trunk/bibdesk/NSString_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSString_BDSKExtensions.h 2011-06-03 06:35:19 UTC (rev
17927)
+++ trunk/bibdesk/NSString_BDSKExtensions.h 2011-06-03 10:58:13 UTC (rev
17928)
@@ -356,25 +356,6 @@
*/
- (NSComparisonResult)triStateCompare:(NSString *)other;
-/*!
- @method UTICompare:
- @abstract Compares the UTI of two files on disk case-insensitively.
- @discussion The receiver and/or argument may be an absolute or relative
path, or string representation of a URL. If a file is a relative path, the UTI
from its path extension is used. Aliases are resolved in this comparison, so
it may be slow.
- @param other (description)
- @result (description)
-*/
-- (NSComparisonResult)UTICompare:(NSString *)other;
-
-/*!
- @method UTICompare:basePath:
- @abstract Compares the UTI of two files on disk case-insensitively.
- @discussion The receiver and/or argument may be an absolute or relative
path, or string representation of a URL. If a file is a relative path, it is
completed using basePath. If a file is a relative path and basePath is nil, the
UTI from its path extension is used. Aliases are resolved in this comparison,
so it may be slow.
- @param other (description)
- @param basePath (description)
- @result (description)
-*/
-- (NSComparisonResult)UTICompare:(NSString *)other basePath:(NSString
*)basePath;
-
- (BOOL)isCaseInsensitiveEqual:(NSString *)aString;
#pragma mark -
Modified: trunk/bibdesk/NSString_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSString_BDSKExtensions.m 2011-06-03 06:35:19 UTC (rev
17927)
+++ trunk/bibdesk/NSString_BDSKExtensions.m 2011-06-03 10:58:13 UTC (rev
17928)
@@ -994,59 +994,6 @@
return NSOrderedDescending;
}
-static NSURL *CreateFileURLFromPathOrURLString(NSString *aPath, NSString
*basePath)
-{
- // default return values
- NSURL *fileURL = nil;
-
- if ([aPath hasPrefix:@"file://"]) {
- fileURL = [[NSURL alloc] initWithString:aPath];
- } else if ([aPath length]) {
- unichar ch = [aPath characterAtIndex:0];
- if ('/' != ch && '~' != ch)
- aPath = [basePath stringByAppendingPathComponent:aPath];
- if (aPath)
- fileURL = [[NSURL alloc] initFileURLWithPath:[aPath
stringByStandardizingPath]];
- }
- return fileURL;
-}
-
-static NSString *UTIForPathOrURLString(NSString *aPath, NSString *basePath)
-{
- NSString *theUTI = nil;
- NSURL *fileURL = nil;
- // !!! We return nil when a file doesn't exist if it's a properly
resolvable path/URL, but we have no way of checking existence with a relative
path. Returning nil is preferable, since then nonexistent files will be sorted
to the top or bottom and they're easy to find.
- if ((fileURL = CreateFileURLFromPathOrURLString(aPath, basePath))) {
- // UTI will be nil for a file that doesn't exist, yet had an
absolute/resolvable path
- if (fileURL) {
- theUTI = [[NSWorkspace sharedWorkspace] typeOfFile:[[[fileURL
path] stringByStandardizingPath] stringByResolvingSymlinksInPath] error:NULL];
- [fileURL release];
- }
-
- } else {
-
- // fall back to extension; this is probably a relative path, so we'll
assume it exists
- NSString *extension = [aPath pathExtension];
- if ([extension isEqualToString:@""] == NO)
- theUTI =
[(id)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
(CFStringRef)extension, NULL) autorelease];
- }
- return theUTI;
-}
-
-- (NSComparisonResult)UTICompare:(NSString *)other{
- return [self UTICompare:other basePath:nil];
-}
-
-- (NSComparisonResult)UTICompare:(NSString *)other basePath:(NSString
*)basePath{
- NSString *otherUTI = UTIForPathOrURLString(other, basePath);
- NSString *selfUTI = UTIForPathOrURLString(self, basePath);
- if (nil == selfUTI)
- return (nil == otherUTI ? NSOrderedSame : NSOrderedDescending);
- if (nil == otherUTI)
- return NSOrderedAscending;
- return [selfUTI caseInsensitiveCompare:otherUTI];
-}
-
- (BOOL)isCaseInsensitiveEqual:(NSString *)aString {
return [self caseInsensitiveCompare:aString] == NSOrderedSame;
}
Modified: trunk/bibdesk/NSURL_BDSKExtensions.h
===================================================================
--- trunk/bibdesk/NSURL_BDSKExtensions.h 2011-06-03 06:35:19 UTC (rev
17927)
+++ trunk/bibdesk/NSURL_BDSKExtensions.h 2011-06-03 10:58:13 UTC (rev
17928)
@@ -51,6 +51,8 @@
+ (NSCharacterSet *)illegalURLCharacterSet;
- (NSString *)precomposedPath;
+- (NSComparisonResult)UTICompare:(NSURL *)other;
+
- (NSArray *)SkimNotes;
- (NSString *)textSkimNotes;
- (NSAttributedString *)richTextSkimNotes;
Modified: trunk/bibdesk/NSURL_BDSKExtensions.m
===================================================================
--- trunk/bibdesk/NSURL_BDSKExtensions.m 2011-06-03 06:35:19 UTC (rev
17927)
+++ trunk/bibdesk/NSURL_BDSKExtensions.m 2011-06-03 10:58:13 UTC (rev
17928)
@@ -235,6 +235,16 @@
return [[self path] precomposedStringWithCanonicalMapping];
}
+- (NSComparisonResult)UTICompare:(NSURL *)other {
+ NSString *otherUTI = [[NSWorkspace sharedWorkspace] typeOfFile:[other
path] error:NULL];
+ NSString *selfUTI = [[NSWorkspace sharedWorkspace] typeOfFile:[self path]
error:NULL];
+ if (nil == selfUTI)
+ return (nil == otherUTI ? NSOrderedSame : NSOrderedDescending);
+ if (nil == otherUTI)
+ return NSOrderedAscending;
+ return [selfUTI caseInsensitiveCompare:otherUTI];
+}
+
#pragma mark Skim Notes
- (NSArray *)SkimNotes {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today.
http://p.sf.net/sfu/quest-dev2dev2
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit