Revision: 27971
http://sourceforge.net/p/bibdesk/svn/27971
Author: hofman
Date: 2022-09-30 16:09:03 +0000 (Fri, 30 Sep 2022)
Log Message:
-----------
Remove custom server files when resetting search grouop servers, so they will
remain reset. Allow removing default servers more persistently, by saving a
basically empty server file with only the name.
Modified Paths:
--------------
trunk/bibdesk/BDSKSearchGroupServerManager.h
trunk/bibdesk/BDSKSearchGroupServerManager.m
Modified: trunk/bibdesk/BDSKSearchGroupServerManager.h
===================================================================
--- trunk/bibdesk/BDSKSearchGroupServerManager.h 2022-09-30 15:05:35 UTC
(rev 27970)
+++ trunk/bibdesk/BDSKSearchGroupServerManager.h 2022-09-30 16:09:03 UTC
(rev 27971)
@@ -43,6 +43,7 @@
@interface BDSKSearchGroupServerManager : NSObject {
NSMutableArray *searchGroupServers;
NSMutableDictionary *searchGroupServerFiles;
+ NSMutableSet *defaultSearchGroupServerNames;
NSArray *sortDescriptors;
}
@@ -50,9 +51,6 @@
- (void)resetServers;
-- (void)saveServerFile:(BDSKServerInfo *)serverInfo;
-- (void)deleteServerFile:(BDSKServerInfo *)serverInfo;
-
@property (nonatomic, readonly) NSArray *servers;
- (void)addServer:(BDSKServerInfo *)info;
Modified: trunk/bibdesk/BDSKSearchGroupServerManager.m
===================================================================
--- trunk/bibdesk/BDSKSearchGroupServerManager.m 2022-09-30 15:05:35 UTC
(rev 27970)
+++ trunk/bibdesk/BDSKSearchGroupServerManager.m 2022-09-30 16:09:03 UTC
(rev 27971)
@@ -44,6 +44,11 @@
#define SERVERS_FILENAME @"SearchGroupServers"
#define SERVERS_DIRNAME @"SearchGroupServers"
+@interface BDSKSearchGroupServerManager ()
+- (void)saveServerFile:(BDSKServerInfo *)serverInfo
forSuppression:(BOOL)suppression;
+- (void)deleteServerFile:(BDSKServerInfo *)serverInfo;
+@end
+
@implementation BDSKSearchGroupServerManager
@dynamic servers;
@@ -73,15 +78,24 @@
} else if (isSearchFileAtPath([serversPath
stringByAppendingPathComponent:file])) {
NSString *path = [serversPath
stringByAppendingPathComponent:file];
NSDictionary *dict = [NSDictionary
dictionaryWithContentsOfFile:path];
- BDSKServerInfo *info = [[BDSKServerInfo alloc]
initWithDictionary:dict];
- if (info) {
- NSUInteger idx = [[searchGroupServers valueForKey:@"name"]
indexOfObject:[info name]];
+ NSString *name = nil;
+ if ([dict count] == 1 && (name = [dict objectForKey:@"name"]))
{
+ NSUInteger idx = [[searchGroupServers valueForKey:@"name"]
indexOfObject:name];
if (idx != NSNotFound)
- [searchGroupServers replaceObjectAtIndex:idx
withObject:info];
- else
- [searchGroupServers addObject:info];
- [searchGroupServerFiles setObject:path forKey:[info name]];
- [info release];
+ [searchGroupServers removeObjectAtIndex:idx];
+ [searchGroupServerFiles setObject:path forKey:name];
+ } else {
+ BDSKServerInfo *info = [[BDSKServerInfo alloc]
initWithDictionary:dict];
+ if (info) {
+ name = [info name];
+ NSUInteger idx = [[searchGroupServers
valueForKey:@"name"] indexOfObject:name];
+ if (idx != NSNotFound)
+ [searchGroupServers replaceObjectAtIndex:idx
withObject:info];
+ else
+ [searchGroupServers addObject:info];
+ [searchGroupServerFiles setObject:path forKey:name];
+ [info release];
+ }
}
}
}
@@ -98,6 +112,7 @@
searchGroupServers = [[NSMutableArray alloc] init];
searchGroupServerFiles = [[NSMutableDictionary alloc] init];
+ defaultSearchGroupServerNames = [[NSMutableSet alloc] init];
sortDescriptors = [[NSArray alloc] initWithObjects:typeSort, nameSort,
nil];
[self resetServers];
[self loadCustomServers];
@@ -107,7 +122,6 @@
- (void)resetServers {
[searchGroupServers removeAllObjects];
- [searchGroupServerFiles removeAllObjects];
NSString *path = [[NSBundle mainBundle] pathForResource:SERVERS_FILENAME
ofType:@"plist"];
@@ -115,6 +129,7 @@
for (NSDictionary *dict in serverDicts) {
BDSKServerInfo *info = [[BDSKServerInfo alloc]
initWithDictionary:dict];
if (info) {
+ [defaultSearchGroupServerNames addObject:[info name]];
[searchGroupServers addObject:info];
[info release];
}
@@ -121,12 +136,25 @@
}
[searchGroupServers sortUsingDescriptors:sortDescriptors];
+
+ // there are no files registered on init
+ NSWorkspace *ws = [NSWorkspace sharedWorkspace];
+ for (path in [searchGroupServerFiles allValues])
+ [ws performFileOperation:NSWorkspaceRecycleOperation source:[path
stringByDeletingLastPathComponent] destination:@"" files:[NSArray
arrayWithObjects:[path lastPathComponent], nil] tag:NULL];
+ [searchGroupServerFiles removeAllObjects];
}
-- (void)saveServerFile:(BDSKServerInfo *)serverInfo {
+- (void)saveServerFile:(BDSKServerInfo *)serverInfo
forSuppression:(BOOL)suppression {
NSError *error = nil;
NSPropertyListFormat format = NSPropertyListXMLFormat_v1_0;
- NSData *data = [NSPropertyListSerialization
dataWithPropertyList:[serverInfo dictionaryValue] format:format options:0
error:&error];
+ NSDictionary *dict = nil;
+ NSData *data = nil;
+
+ if (suppression)
+ dict = [NSDictionary dictionaryWithObjectsAndKeys:[serverInfo name],
@"name", nil];
+ else
+ dict = [serverInfo dictionaryValue];
+ data = [NSPropertyListSerialization dataWithPropertyList:[serverInfo
dictionaryValue] format:format options:0 error:&error];
if (error) {
NSLog(@"Error writing: %@", error);
} else {
@@ -167,7 +195,7 @@
- (void)addServer:(BDSKServerInfo *)serverInfo
{
// this also makes sure any password is saved in the keychain
- [self saveServerFile:serverInfo];
+ [self saveServerFile:serverInfo forSuppression:NO];
[searchGroupServers addObject:[[serverInfo copy] autorelease]];
[searchGroupServers sortUsingDescriptors:sortDescriptors];
}
@@ -175,13 +203,17 @@
- (void)setServer:(BDSKServerInfo *)serverInfo atIndex:(NSUInteger)idx {
// this also makes sure any password is saved in the keychain
[self deleteServerFile:[searchGroupServers objectAtIndex:idx]];
- [self saveServerFile:serverInfo];
+ [self saveServerFile:serverInfo forSuppression:NO];
[searchGroupServers replaceObjectAtIndex:idx withObject:[[serverInfo copy]
autorelease]];
[searchGroupServers sortUsingDescriptors:sortDescriptors];
}
- (void)removeServerAtIndex:(NSUInteger)idx {
- [self deleteServerFile:[searchGroupServers objectAtIndex:idx]];
+ BDSKServerInfo *info = [searchGroupServers objectAtIndex:idx];
+ if ([defaultSearchGroupServerNames containsObject:[info name]])
+ [self saveServerFile:info forSuppression:YES];
+ else
+ [self deleteServerFile:info];
[searchGroupServers removeObjectAtIndex:idx];
}
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