Revision: 27227
http://sourceforge.net/p/bibdesk/svn/27227
Author: hofman
Date: 2022-01-16 17:19:34 +0000 (Sun, 16 Jan 2022)
Log Message:
-----------
Rename auto file command to publication command and remove custom implementation
Modified Paths:
--------------
trunk/bibdesk/BDSKAutoFileCommand.h
trunk/bibdesk/BDSKAutoFileCommand.m
Modified: trunk/bibdesk/BDSKAutoFileCommand.h
===================================================================
--- trunk/bibdesk/BDSKAutoFileCommand.h 2022-01-16 16:51:22 UTC (rev 27226)
+++ trunk/bibdesk/BDSKAutoFileCommand.h 2022-01-16 17:19:34 UTC (rev 27227)
@@ -39,7 +39,7 @@
#import <Cocoa/Cocoa.h>
-@interface BDSKAutoFileCommand : NSScriptCommand {
+@interface BDSKPublicationCommand : NSScriptCommand {
NSScriptObjectSpecifier *keySpecifier;
}
@property (nonatomic, readonly) NSScriptObjectSpecifier *keySpecifier;
Modified: trunk/bibdesk/BDSKAutoFileCommand.m
===================================================================
--- trunk/bibdesk/BDSKAutoFileCommand.m 2022-01-16 16:51:22 UTC (rev 27226)
+++ trunk/bibdesk/BDSKAutoFileCommand.m 2022-01-16 17:19:34 UTC (rev 27227)
@@ -1,5 +1,5 @@
//
-// BDSKAutoFileCommand.m
+// BDSKPublicationCommand.m
// Bibdesk
//
// Created by Christiaan Hofman on 7/3/07.
@@ -36,17 +36,10 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#import "BDSKAutoFileCommand.h"
-#import "BDSKStringConstants.h"
-#import "BibItem.h"
-#import "BibDocument.h"
-#import "BDSKOwnerProtocol.h"
-#import "BDSKFiler.h"
-#import "BDSKTypeManager.h"
-#import "BDSKAppController.h"
+#import "BDSKPublicationCommand.h"
-@implementation BDSKAutoFileCommand
+@implementation BDSKPublicationCommand
@synthesize keySpecifier;
@@ -77,182 +70,4 @@
}
}
-- (id)performDefaultImplementation {
- NSScriptObjectSpecifier *keySpec = [self keySpecifier];
- NSString *keyClass = [[keySpec keyClassDescription] className];
- NSDictionary *params = [self evaluatedArguments];
- NSNumber *indexNumber = [params objectForKey:@"index"];
- NSString *location = [params objectForKey:@"to"];
- NSString *field = [params objectForKey:@"for"];
- NSNumber *checkNumber = [params objectForKey:@"check"];
- BOOL check = checkNumber ? [checkNumber boolValue] : YES;
- BibItem *pub = [self evaluatedReceivers];
- BibDocument *doc = nil;
- NSInteger start = 0, end = 0;
- NSMutableIndexSet *indexes = nil;
- NSArray *files = nil;
-
- if (field && [field isKindOfClass:[NSString class]] == NO) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- return nil;
- }
- if (indexNumber && [indexNumber isKindOfClass:[NSNumber class]] == NO) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- return nil;
- }
-
- if (pub == nil) {
- [self setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
- [self setScriptErrorString:@"Could not find a publication to auto
file."];
- return nil;
- }
- if ([pub isKindOfClass:[BibItem class]] == NO) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Receiver is not a publication."];
- return nil;
- }
-
- if (keySpec == nil) {
- if (indexNumber) {
- if (field && [field isEqualToString:BDSKLocalFileString] == NO) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Cannot pass both an index and a
field."];
- return nil;
- }
- field = BDSKLocalFileString;
- start = [indexNumber integerValue];
- end = start > 0 ? --start : start;
- } else if ([field isEqualToString:BDSKLocalFileString] || (field ==
nil && [[NSUserDefaults standardUserDefaults]
boolForKey:BDSKUseLocalUrlAndUrlKey] == NO)) {
- field = BDSKLocalFileString;
- start = 0;
- end = location ? 0 : -1;
- } else {
- field = [field fieldName] ?: BDSKLocalUrlString;
- }
- } else if ([keyClass isEqualToString:@"field"]) {
- if (field) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Cannot pass both a field and a field
name."];
- return nil;
- }
- if (indexNumber) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Cannot pass both a field and an
index."];
- return nil;
- }
- if ([keySpec isKindOfClass:[NSNameSpecifier class]] == NO) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Invalid field specifier."];
- return nil;
- }
- field = [[(NSNameSpecifier *)keySpec name] fieldName];
- } else if ([keyClass isEqualToString:@"linked file"]) {
- if (field) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Cannot pass both a linked file and a
field name."];
- return nil;
- }
- if (indexNumber) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Cannot pass both a linked file and an
index."];
- return nil;
- }
- field = BDSKLocalFileString;
- // NSPropertySpecifier, NSIndexSpecifier, NSRangeSpecifier,
NSMiddleSpecifier, NSWhoseSpecifier
- NSInteger i, count = -2;
- NSInteger *indices = [keySpec
indicesOfObjectsByEvaluatingWithContainer:pub count:&count];
- if (count < -1) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Do not understand linked file
specifier."];
- return nil;
- }
- if (count == 0) {
- return nil;
- } else if (count == -1) {
- start = 0;
- end = -1;
- } else {
- end = start = indices[0];
- for (i = 1; i < count; i++) {
- if (indices[i] = end + 1) {
- end++;
- } else {
- // not a single range, use an index set, start/end only
holds the first range
- if (indexes == nil)
- indexes = [NSMutableIndexSet
indexSetWithIndexesInRange:NSMakeRange(start, end + 1 - start)];
- [indexes addIndex:indices[i]];
- }
- }
- }
- } else {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Receiver should be a publication, field,
or linked file(s)."];
- [self setScriptErrorOffendingObjectDescriptor:[keySpec descriptor]];
- return nil;
- }
-
- doc = (BibDocument *)[pub owner];
-
- if ([doc isDocument] == NO) {
- [self setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
- [self setScriptErrorString:@"Cannot auto file for external items."];
- return nil;
- }
-
- if ([field isEqualToString:BDSKLocalFileString]) {
- files = [pub localFiles];
- NSInteger count = [files count];
- if (count == 0)
- return nil;
- if (start < 0)
- start += count;
- if (end < 0)
- end += count;
- if (start < 0 || end < 0 || start >= count || end >= count || end <
start || (NSInteger)[indexes lastIndex] >= count) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"Invalid linked file index."];
- return nil;
- }
- if (location && (end > start || [indexes count] > 0)) {
- [self
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
- [self setScriptErrorString:@"Only a single linked file can be
moved to a given location."];
- return nil;
- }
- if (indexes)
- files = [files objectsAtIndexes:indexes];
- else if (start > 0 || end < count - 1)
- files = [files subarrayWithRange:NSMakeRange(start, end + 1 -
start)];
- }
-
- if (location) {
- if ([location isKindOfClass:[NSString class]] == NO && [location
isKindOfClass:[NSURL class]] == NO) {
- [self setScriptErrorNumber:NSArgumentsWrongScriptError];
- [self setScriptErrorString:@"The 'to' argument should be a path or
a file."];
- return nil;
- }
- if ([location isKindOfClass:[NSURL class]])
- location = [(NSURL *)location path];
- else if ([location hasPrefix:@"file://"])
- location = [[NSURL URLWithString:location] path];
- else if ([location hasPrefix:@"~"])
- location = [location stringByExpandingTildeInPath];
- else if ([location isAbsolutePath] == NO) // or should we use the
papers folder?
- location = [[([doc basePath] ?: NSHomeDirectory())
stringByAppendingPathComponent:location] stringByStandardizingPath];
- NSArray *paperInfos = [NSArray arrayWithObject:[NSDictionary
dictionaryWithObjectsAndKeys:pub, BDSKFilerPublicationKey, location,
BDSKFilerNewPathKey, [files firstObject], BDSKFilerFileKey, nil]];
- [[BDSKFiler sharedFiler] movePapers:paperInfos forField:field
fromDocument:doc options:BDSKAutoFileOptionInitial
actionName:NSLocalizedString(@"AppleScript",@"Undo action name for
AppleScript")];
- if (files)
- return [files valueForKey:@"URL"];
- else
- return [pub localFileURLForField:field];
- } else if (files) {
- [[BDSKFiler sharedFiler] autoFileLinkedFiles:files fromDocument:doc
check:check actionName:NSLocalizedString(@"AppleScript",@"Undo action name for
AppleScript")];
- return [files valueForKey:@"URL"];
- } else {
- [[BDSKFiler sharedFiler] autoFileItems:[NSArray arrayWithObjects:pub,
nil] forField:field fromDocument:doc check:check
actionName:NSLocalizedString(@"AppleScript",@"Undo action name for
AppleScript")];
- return [pub localFileURLForField:field];
- }
-
- return nil;
-}
-
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit