Revision: 11376
http://bibdesk.svn.sourceforge.net/bibdesk/?rev=11376&view=rev
Author: hofman
Date: 2007-10-24 15:44:09 -0700 (Wed, 24 Oct 2007)
Log Message:
-----------
Include a relative path in the file objects, because AliasHandle is not able to
handle relative paths.
Modified Paths:
--------------
branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h
branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m
branches/TRY_ARM_FILE_INTERFACE/bibdesk/BibEditor.m
Modified: branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h
===================================================================
--- branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h 2007-10-24 17:36:45 UTC
(rev 11375)
+++ branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.h 2007-10-24 22:44:09 UTC
(rev 11376)
@@ -61,28 +61,24 @@
{
BDAlias *alias;
const FSRef *fileRef;
+ NSString *relativePath;
}
-- (id)initWithAlias:(BDAlias *)anAlias;
-- (id)initWithData:(NSData *)data;
- (id)initWithBase64String:(NSString *)base64String;
- (id)initWithPath:(NSString *)aPath relativeToPath:(NSString *)basePath;
- (id)initWithURL:(NSURL *)aURL relativeToURL:(NSURL *)baseURL;
-- (const FSRef *)fsRefRelativeToURL:(NSURL *)baseURL update:(BOOL)update;
- (const FSRef *)fsRefRelativeToURL:(NSURL *)baseURL;
- (const FSRef *)fsRef;
- (NSURL *)fileURLRelativeToURL:(NSURL *)baseURL;
-- (NSURL *)fileURLRelativeToURLNoUpdate:(NSURL *)baseURL;
- (NSURL *)fileURL;
- (NSString *)pathRelativeToPath:(NSString *)basePath;
-- (NSString *)pathRelativeToPathNoUpdate:(NSString *)basePath;
- (NSString *)path;
-- (BDAlias *)aliasRelativeToPath:(NSString *)basePath;
-- (NSData *)aliasDataRelativeToPath:(NSString *)basePath;
-- (NSString *)base64StringRelativeToPath:(NSString *)basePath;
+- (NSString *)base64StringRelativeToPath:(NSString *)basePath
convertedRelativeToPath:(NSString *)newBasePath;
+- (NSString *)relativePath;
+
@end
Modified: branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m
===================================================================
--- branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m 2007-10-24 17:36:45 UTC
(rev 11375)
+++ branches/TRY_ARM_FILE_INTERFACE/bibdesk/BDSKFile.m 2007-10-24 22:44:09 UTC
(rev 11376)
@@ -391,20 +391,21 @@
@implementation BDSKAliasFile
// guaranteed to be called with a non-nil alias
-- (id)initWithAlias:(BDAlias *)anAlias;
+- (id)initWithAlias:(BDAlias *)anAlias relativePath:(NSString *)relPath;
{
if (self = [super init]) {
fileRef = NULL; // this is updated lazily, as we don't know the base
path at this point
alias = [anAlias retain];
+ relativePath = nil;
}
return self;
}
-- (id)initWithData:(NSData *)data;
+- (id)initWithAliasData:(NSData *)data relativePath:(NSString *)relPath;
{
NSParameterAssert(nil != data);
BDAlias *anAlias = [[BDAlias alloc] initWithData:data];
- self = [self initWithAlias:anAlias];
+ self = [self initWithAlias:anAlias relativePath:relPath];
[anAlias release];
return self;
}
@@ -413,23 +414,28 @@
{
NSParameterAssert(nil != base64String);
NSData *data = [[NSData alloc] initWithBase64String:base64String];
- self = [self initWithData:data];
+ NSDictionary *dictionary = [NSKeyedUnarchiver
unarchiveObjectWithData:data];
[data release];
- return self;
+ return [self initWithAliasData:[dictionary objectForKey:@"aliasData"]
relativePath:[dictionary objectForKey:@"relativePath"]];
}
- (id)initWithPath:(NSString *)aPath relativeToPath:(NSString *)basePath;
{
BDAlias *anAlias = nil;
+ NSURL *baseURL;
+ NSString *relPath = nil;
// BDAlias has a different interpretation of aPath, which is inconsistent
with the way it handles FSRef
- if (basePath)
- anAlias = [[BDAlias alloc] initWithPath:[basePath
relativePathToFilename:aPath] relativeToPath:basePath];
- else
+ if (basePath) {
+ anAlias = [[BDAlias alloc] initWithPath:aPath relativeToPath:basePath];
+ relPath = [basePath relativePathToFilename:aPath];
+ } else {
anAlias = [[BDAlias alloc] initWithPath:aPath];
+ }
if (anAlias) {
- if ((self = [self initWithAlias:anAlias]) && basePath) {
- // this initalizes the FSRef and update the alias
- [self fsRefRelativeToURL:[NSURL fileURLWithPath:basePath]
update:YES];
+ if ((self = [self initWithAlias:anAlias relativePath:relPath])) {
+ if (basePath && (baseURL = [NSURL fileURLWithPath:basePath]))
+ // this initalizes the FSRef and update the alias
+ [self fsRefRelativeToURL:baseURL];
}
[anAlias release];
} else {
@@ -446,19 +452,21 @@
- (id)initWithCoder:(NSCoder *)coder
{
OBASSERT_NOT_REACHED("BDSKAliasFile needs a base path for encoding");
- return [self initWithData:[coder decodeObject]];
+ return [self initWithAliasData:[coder decodeObject] relativePath:[coder
decodeObject]];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
OBASSERT_NOT_REACHED("BDSKAliasFile needs a base path for encoding");
- [coder encodeObject:[self aliasDataRelativeToPath:nil]];
+ [coder encodeObject:[alias aliasData]];
+ [coder encodeObject:relativePath];
}
- (void)dealloc
{
NSZoneFree([self zone], (void *)fileRef);
[alias release];
+ [relativePath release];
[super dealloc];
}
@@ -470,24 +478,46 @@
// Should we implement -isEqual: and -hash?
-- (const FSRef *)fsRefRelativeToURL:(NSURL *)baseURL update:(BOOL)update;
+- (const FSRef *)fsRefRelativeToURL:(NSURL *)baseURL;
{
- if (fileRef == NULL && alias) {
+ if (fileRef == NULL) {
FSRef aRef;
FSRef baseRef;
short aliasCount = 1;
- Boolean shouldUpdate;
- OSStatus anErr;
+ Boolean shouldUpdate = false;
+ Boolean success = false;
- if (baseURL)
- CFURLGetFSRef((CFURLRef)baseURL, &baseRef);
+ if (baseURL && relativePath) {
+ NSString *path = [[baseURL path]
stringByAppendingPathComponent:relativePath];
+ NSURL *theURL = [NSURL fileURLWithPath:path];
+
+ if (theURL != NULL) {
+ shouldUpdate = success = CFURLGetFSRef((CFURLRef)theURL,
&aRef);
+ }
+ }
- anErr = FSMatchAliasNoUI(&baseRef, kARMNoUI | kARMSearch |
kARMSearchRelFirst, [alias alias], &aliasCount, &aRef, &shouldUpdate, NULL,
NULL);
+ if (success == false && alias) {
+ if (baseURL && CFURLGetFSRef((CFURLRef)baseURL, &baseRef)) {
+ success = noErr == FSMatchAliasNoUI(&baseRef, kARMNoUI |
kARMSearch | kARMSearchRelFirst, [alias alias], &aliasCount, &aRef,
&shouldUpdate, NULL, NULL);
+ } else {
+ success = noErr == FSMatchAliasNoUI(NULL, kARMNoUI |
kARMSearch | kARMSearchRelFirst, [alias alias], &aliasCount, &aRef,
&shouldUpdate, NULL, NULL);
+ shouldUpdate = false;
+ }
+ }
- if (anErr == noErr) {
- if (update && shouldUpdate)
- FSUpdateAlias(&baseRef, &aRef, [alias alias], &shouldUpdate);
-
+ if (success && shouldUpdate) {
+ FSUpdateAlias(&baseRef, &aRef, [alias alias], &shouldUpdate);
+ if (baseURL) {
+ CFURLRef tmpURL =
CFURLCreateFromFSRef(CFAllocatorGetDefault(), &aRef);
+ if (tmpURL) {
+ [relativePath release];
+ relativePath = [[[baseURL path]
relativePathToFilename:[(NSURL *)tmpURL path]] retain];
+ CFRelease(tmpURL);
+ }
+ }
+ }
+
+ if (success) {
FSRef *newRef = (FSRef *)NSZoneMalloc([self zone], sizeof(FSRef));
if(newRef)
bcopy(&aRef, newRef, sizeof(FSRef));
@@ -497,14 +527,9 @@
return fileRef;
}
-- (const FSRef *)fsRefRelativeToURL:(NSURL *)baseURL;
-{
- return [self fsRefRelativeToURL:baseURL update:YES];
-}
-
- (const FSRef *)fsRef;
{
- return [self fsRefRelativeToURL:nil update:NO];
+ return [self fsRefRelativeToURL:nil];
}
- (NSURL *)fileURLRelativeToURL:(NSURL *)baseURL;
@@ -522,29 +547,14 @@
return aURL;
}
-- (NSURL *)fileURLRelativeToURLNoUpdate:(NSURL *)baseURL;
-{
- BOOL hadFileRef = fileRef != NULL;
- const FSRef *aRef = [self fsRefRelativeToURL:baseURL update:NO];
- NSURL *aURL = aRef == NULL ? nil :
[(id)CFURLCreateFromFSRef(CFAllocatorGetDefault(), aRef) autorelease];
- if (aURL == nil && hadFileRef) {
- NSZoneFree([self zone], (void *)fileRef);
- fileRef = NULL;
- aRef = [self fsRefRelativeToURL:baseURL update:NO];
- if (aRef != NULL)
- aURL = [(id)CFURLCreateFromFSRef(CFAllocatorGetDefault(), aRef)
autorelease];
- }
- return aURL;
-}
-
- (NSURL *)fileURL;
{
- return [self fileURLRelativeToURLNoUpdate:nil];
+ return [self fileURLRelativeToURL:nil];
}
- (NSString *)fileName;
{
- return [(NSString *)copyFileNameFromFSRef([self fsRef]) autorelease];
+ return [[self path] lastPathComponent];
}
- (NSString *)path;
@@ -554,46 +564,66 @@
- (NSString *)pathRelativeToPath:(NSString *)basePath;
{
- return [[self fileURLRelativeToURL:[NSURL fileURLWithPath:basePath]] path];
+ return [[self fileURLRelativeToURL:basePath ? [NSURL
fileURLWithPath:basePath] : nil] path];
}
-- (NSString *)pathRelativeToPathNoUpdate:(NSString *)basePath;
+- (BDAlias *)aliasRelativeToPath:(NSString *)basePath
convertedRelativeToPath:(NSString *)newBasePath;
{
- return [[self fileURLRelativeToURLNoUpdate:[NSURL
fileURLWithPath:basePath]] path];
+ // make sure the fileRef is valid
+ [self fileURLRelativeToURL:basePath ? [NSURL fileURLWithPath:basePath] :
nil];
+
+ FSRef *fsRef = (FSRef *)[self fsRefRelativeToURL:basePath ? [NSURL
fileURLWithPath:basePath] : nil];
+ FSRef baseRef;
+ NSURL *baseURL;
+ BDAlias *anAlias = nil;
+
+ if (fsRef) {
+ baseURL = newBasePath ? [NSURL fileURLWithPath:newBasePath] : nil;
+ if (baseURL && CFURLGetFSRef((CFURLRef)baseURL, &baseRef))
+ anAlias = [[[BDAlias alloc] initWithFSRef:fsRef
relativeToFSRef:&baseRef] autorelease];
+ else
+ anAlias = [[[BDAlias alloc] initWithFSRef:fsRef] autorelease];
+ } else {
+ anAlias = alias;
+ }
+
+ return anAlias;
}
-- (BDAlias *)aliasRelativeToPath:(NSString *)basePath;
+- (NSData *)aliasDataRelativeToPath:(NSString *)basePath
convertedRelativeToPath:(NSString *)newBasePath;
{
- NSParameterAssert(nil != basePath);
// make sure the fileRef is valid
- [self fileURLRelativeToURLNoUpdate:[NSURL fileURLWithPath:basePath]];
+ [self fileURLRelativeToURL:basePath ? [NSURL fileURLWithPath:basePath] :
nil];
- FSRef *fsRef = (FSRef *)[self fsRefRelativeToURL:[NSURL
fileURLWithPath:basePath] update:NO];
- FSRef baseRef, tempRef = *fsRef;
+ FSRef *fsRef = (FSRef *)[self fsRefRelativeToURL:basePath ? [NSURL
fileURLWithPath:basePath] : nil];
+ FSRef baseRef;
NSURL *baseURL;
BDAlias *anAlias = nil;
if (fsRef) {
- baseURL = [NSURL fileURLWithPath:basePath];
+ baseURL = newBasePath ? [NSURL fileURLWithPath:newBasePath] : nil;
if (baseURL && CFURLGetFSRef((CFURLRef)baseURL, &baseRef))
anAlias = [[[BDAlias alloc] initWithFSRef:fsRef
relativeToFSRef:&baseRef] autorelease];
else
anAlias = [[[BDAlias alloc] initWithFSRef:fsRef] autorelease];
} else {
- anAlias = alias;
+ anAlias = alias;
}
- return anAlias;
+ return [anAlias aliasData];
}
-- (NSData *)aliasDataRelativeToPath:(NSString *)basePath;
+- (NSString *)base64StringRelativeToPath:(NSString *)basePath
convertedRelativeToPath:(NSString *)newBasePath;
{
- return [[self aliasRelativeToPath:basePath] aliasData];
+ NSData *data = [self aliasDataRelativeToPath:basePath
convertedRelativeToPath:newBasePath];
+ NSString *path = [self pathRelativeToPath:basePath];
+ path = path && newBasePath ? [newBasePath relativePathToFilename:path] :
relativePath;
+ NSDictionary *dictionary = [NSDictionary
dictionaryWithObjectsAndKeys:data, @"aliasData", path, @"relativePath", nil];
+ return [[NSKeyedArchiver archivedDataWithRootObject:dictionary]
base64String];
}
-- (NSString *)base64StringRelativeToPath:(NSString *)basePath;
-{
- return [[self aliasDataRelativeToPath:basePath] base64String];
+- (NSString *)relativePath {
+ return relativePath;
}
@end
Modified: branches/TRY_ARM_FILE_INTERFACE/bibdesk/BibEditor.m
===================================================================
--- branches/TRY_ARM_FILE_INTERFACE/bibdesk/BibEditor.m 2007-10-24 17:36:45 UTC
(rev 11375)
+++ branches/TRY_ARM_FILE_INTERFACE/bibdesk/BibEditor.m 2007-10-24 22:44:09 UTC
(rev 11376)
@@ -118,7 +118,11 @@
- (NSURL *)fileView:(FileView *)aFileView URLAtIndex:(NSUInteger)idx;
{
- return [[publication fileAtIndex:idx] fileURLRelativeToURL:[publication
baseURL]];
+ BDSKAliasFile *file = [publication fileAtIndex:idx];
+ NSURL *aURL = [file fileURLRelativeToURL:[publication baseURL]];
+ if (aURL == nil && [file relativePath])
+ aURL = [NSURL fileURLWithPath:[file relativePath]];
+ return aURL;
}
- (BOOL)fileView:(FileView *)aFileView moveURLsAtIndexes:(NSIndexSet *)aSet
toIndex:(NSUInteger)anIndex;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit