Revision: 22826 http://sourceforge.net/p/bibdesk/svn/22826 Author: hofman Date: 2018-10-14 12:30:25 +0000 (Sun, 14 Oct 2018) Log Message: ----------- Properly create new search bookmark for scripting, add property for search term
Modified Paths: -------------- trunk/bibdesk/BDSKGroup+Scripting.m trunk/bibdesk/BDSKSearchBookmark+Scripting.h trunk/bibdesk/BDSKSearchBookmark+Scripting.m trunk/bibdesk/BDSKServerInfo+Scripting.h trunk/bibdesk/BDSKServerInfo+Scripting.m trunk/bibdesk/Scripting/BibDesk.sdef Modified: trunk/bibdesk/BDSKGroup+Scripting.m =================================================================== --- trunk/bibdesk/BDSKGroup+Scripting.m 2018-10-14 06:30:37 UTC (rev 22825) +++ trunk/bibdesk/BDSKGroup+Scripting.m 2018-10-14 12:30:25 UTC (rev 22826) @@ -556,7 +556,7 @@ } - (void)setScriptingServerInfo:(NSDictionary *)info { - BDSKServerInfo *serverInfo = [[self class] newServerInfo:[self serverInfo] withScriptingServerInfo:info]; + BDSKServerInfo *serverInfo = [[self serverInfo] newServerInfoWithScriptingServerInfo:info]; if (serverInfo != nil && [NSString isEmptyString:[serverInfo name]] == NO) { [self setServerInfo:serverInfo]; [[self undoManager] setActionName:NSLocalizedString(@"AppleScript",@"Undo action name for AppleScript")]; Modified: trunk/bibdesk/BDSKSearchBookmark+Scripting.h =================================================================== --- trunk/bibdesk/BDSKSearchBookmark+Scripting.h 2018-10-14 06:30:37 UTC (rev 22825) +++ trunk/bibdesk/BDSKSearchBookmark+Scripting.h 2018-10-14 12:30:25 UTC (rev 22826) @@ -43,6 +43,8 @@ - (NSDictionary *)scriptingServerInfo; +- (NSString *)scriptingSearchTerm; + - (BDSKSearchBookmark *)scriptingParent; - (NSArray *)entireContents; Modified: trunk/bibdesk/BDSKSearchBookmark+Scripting.m =================================================================== --- trunk/bibdesk/BDSKSearchBookmark+Scripting.m 2018-10-14 06:30:37 UTC (rev 22825) +++ trunk/bibdesk/BDSKSearchBookmark+Scripting.m 2018-10-14 12:30:25 UTC (rev 22826) @@ -47,6 +47,10 @@ return [[[[BDSKServerInfo alloc] initWithDictionary:[self info]] autorelease] scriptingServerInfo]; } +- (NSString *)scriptingSearchTerm { + return [[self info] objectForKey:@"search term"] ?: @""; +} + - (BDSKSearchBookmark *)scriptingParent { return [parent parent] == nil ? nil : parent; } @@ -79,7 +83,7 @@ if ([key isEqualToString:@"search bookmarks"]) { if ([self bookmarkType] != BDSKSearchBookmarkTypeFolder) { [[NSScriptCommand currentCommand] setScriptErrorNumber:NSReceiversCantHandleCommandScriptError]; - [[NSScriptCommand currentCommand] setScriptErrorString:@"Invalid container for new bookmark."]; + [[NSScriptCommand currentCommand] setScriptErrorString:@"Invalid container for new search bookmark."]; return nil; } BDSKSearchBookmark *bookmark = nil; @@ -86,6 +90,7 @@ NSDictionary *anInfo = [properties objectForKey:@"scriptingServerInfo"] ?: contentsValue; NSString *aLabel = [properties objectForKey:@"label"]; NSNumber *aType = [properties objectForKey:@"bookmarkType"]; + NSString *aSearchTerm = [properties objectForKey:@"scriptingSearchTerm"]; NSInteger type; if ([aType respondsToSelector:@selector(integerValue)]) type = [aType integerValue]; @@ -94,10 +99,15 @@ switch (type) { case BDSKSearchBookmarkTypeBookmark: { - NSString *theType = [anInfo objectForKey:@"type"] ?: BDSKSearchGroupEntrez; - NSMutableDictionary *info = [[[[BDSKServerInfo defaultServerInfoWithType:theType] scriptingServerInfo] mutableCopy] autorelease]; - [info addEntriesFromDictionary:anInfo]; - bookmark = [[BDSKSearchBookmark alloc] initWithInfo:info label:aLabel]; + NSString *serverType = [anInfo objectForKey:@"type"] ?: BDSKSearchGroupEntrez; + BDSKServerInfo *serverInfo = [[BDSKServerInfo defaultServerInfoWithType:serverType] newServerInfoWithScriptingServerInfo:anInfo]; + NSDictionary *theInfo = [serverInfo dictionaryValue]; + if ([NSString isEmptyString:aSearchTerm] == NO) { + theInfo = [[theInfo mutableCopy] autorelease]; + [(NSMutableDictionary *)theInfo setObject:aSearchTerm forKey:@"search term"]; + } + bookmark = [[BDSKSearchBookmark alloc] initWithInfo:theInfo label:aLabel]; + [serverInfo release]; break; } case BDSKSearchBookmarkTypeFolder: Modified: trunk/bibdesk/BDSKServerInfo+Scripting.h =================================================================== --- trunk/bibdesk/BDSKServerInfo+Scripting.h 2018-10-14 06:30:37 UTC (rev 22825) +++ trunk/bibdesk/BDSKServerInfo+Scripting.h 2018-10-14 12:30:25 UTC (rev 22826) @@ -47,4 +47,6 @@ - (NSString *)scriptingName; +- (BDSKServerInfo *)newServerInfoWithScriptingServerInfo:(NSDictionary *)info; + @end Modified: trunk/bibdesk/BDSKServerInfo+Scripting.m =================================================================== --- trunk/bibdesk/BDSKServerInfo+Scripting.m 2018-10-14 06:30:37 UTC (rev 22825) +++ trunk/bibdesk/BDSKServerInfo+Scripting.m 2018-10-14 12:30:25 UTC (rev 22826) @@ -37,6 +37,7 @@ */ #import "BDSKServerInfo+Scripting.h" +#import "BDSKSearchGroup.h" #import "NSObject_BDSKExtensions.h" @implementation BDSKServerInfo (Scripting) @@ -80,4 +81,87 @@ return [self name]; } +- (BDSKServerInfo *)newServerInfoWithScriptingServerInfo:(NSDictionary *)info { + NSString *serverType = [info objectForKey:@"type"] ?: [self type]; + BDSKMutableServerInfo *serverInfo = nil; + NSString *serverName = [info valueForKey:@"name"]; + NSString *serverDatabase = [info valueForKey:@"database"]; + NSString *serverHost = [info valueForKey:@"host"]; + NSString *serverPort = [info valueForKey:@"port"]; + + if ([serverType isEqualToString:[self type]]) { + serverInfo = [self mutableCopy]; + + NSString *value; + NSNumber *number; + + if (serverName) + [serverInfo setName:serverName]; + if (serverDatabase) + [serverInfo setDatabase:serverDatabase]; + if ([serverType isEqualToString:BDSKSearchGroupZoom]) { + if (serverHost) + [serverInfo setHost:serverHost]; + if (serverPort) + [serverInfo setPort:serverPort]; + if ((value = [info valueForKey:@"username"])) + [serverInfo setUsername:value]; + if ((value = [info valueForKey:@"password"])) + [serverInfo setPassword:value]; + if ((value = [info valueForKey:@"recordSyntax"])) + [serverInfo setRecordSyntax:value]; + if ((value = [info valueForKey:@"resultEncoding"])) + [serverInfo setResultEncoding:value]; + if ((number = [info valueForKey:@"removeDiacritics"])) + [serverInfo setRemoveDiacritics:[number boolValue]]; + } else if ([serverType isEqualToString:BDSKSearchGroupISI]) { + if ((value = [info valueForKey:@"username"])) + [serverInfo setUsername:value]; + if ((value = [info valueForKey:@"password"])) + [serverInfo setPassword:value]; + if ((number = [info valueForKey:@"lite"])) + [serverInfo setLite:[number boolValue]]; + } + } else if (serverType) { + NSMutableDictionary *serverOptions = nil; + + if ([serverType isEqualToString:BDSKSearchGroupZoom]) { + serverOptions = [NSMutableDictionary dictionary]; + [serverOptions setValue:[info valueForKey:@"username"] forKey:@"username"]; + [serverOptions setValue:[info valueForKey:@"password"] forKey:@"password"]; + [serverOptions setValue:[info valueForKey:@"resultEncoding"] forKey:@"resultEncoding"]; + [serverOptions setValue:[info valueForKey:@"removeDiacritics"] forKey:@"removeDiacritics"]; + } else if ([serverType isEqualToString:BDSKSearchGroupISI]) { + serverOptions = [NSMutableDictionary dictionary]; + [serverOptions setValue:[info valueForKey:@"username"] forKey:@"username"]; + [serverOptions setValue:[info valueForKey:@"password"] forKey:@"password"]; + [serverOptions setValue:[info valueForKey:@"lite"] forKey:@"lite"]; + } + + serverInfo = [[BDSKMutableServerInfo alloc] initWithType:serverType name:serverName database:serverDatabase host:serverHost port:serverPort options:serverOptions]; + } + + BOOL isValid = YES; + id value, validatedValue; + + if ([NSString isEmptyString:[serverInfo database]]) + isValid = NO; + else if ([serverInfo isZoom] && ([NSString isEmptyString:[serverInfo host]] || [[serverInfo port] integerValue] == 0)) + isValid = NO; + for (NSString *key in info) { + if (isValid == NO) break; + value = validatedValue = [info valueForKey:key]; + if ((isValid = [serverInfo validateValue:&validatedValue forKey:key error:NULL]) && + [validatedValue isEqual:value] == NO) + [serverInfo setValue:validatedValue forKey:key]; + } + + if (isValid == NO) { + [serverInfo release]; + serverInfo = nil; + } + + return serverInfo; +} + @end Modified: trunk/bibdesk/Scripting/BibDesk.sdef =================================================================== --- trunk/bibdesk/Scripting/BibDesk.sdef 2018-10-14 06:30:37 UTC (rev 22825) +++ trunk/bibdesk/Scripting/BibDesk.sdef 2018-10-14 12:30:25 UTC (rev 22826) @@ -1616,9 +1616,13 @@ <cocoa key="bookmarkType"/> </property> <contents name="server info" code="SrvI" type="search server info" access="r" - description="The server info for the bookmark."> + description="The server info for the search bookmark."> <cocoa key="scriptingServerInfo"/> </contents> + <property name="search term" code="Term" type="text" + description="The search term for the search bookmark"> + <cocoa key="scriptingSearchTerm"/> + </property> <property name="container" code="ctnr" type="bookmark" access="r" description="The folder bookmark containing this bookmark."> <cocoa key="scriptingParent"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit