From 60964a00b297faafa50e8133994db641bfc2421a Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Wed, 6 Jul 2022 00:02:34 -0700 Subject: [PATCH] [Path Config] Remove exact items by token id Should use the exact token object to remove them, rather than doing a path comparison. Signed-off-by: Christopher Snowhill --- Preferences/Preferences/GeneralPane.m | 6 ++-- .../SandboxPathBehaviorController.h | 2 +- .../SandboxPathBehaviorController.m | 33 ++++++++----------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Preferences/Preferences/GeneralPane.m b/Preferences/Preferences/GeneralPane.m index eee2be0bc..2d21b3315 100644 --- a/Preferences/Preferences/GeneralPane.m +++ b/Preferences/Preferences/GeneralPane.m @@ -36,9 +36,9 @@ - (IBAction)deleteSelectedPaths:(id)sender { NSArray *selectedObjects = [sandboxPathBehaviorController selectedObjects]; if(selectedObjects && [selectedObjects count]) { - NSArray *paths = [selectedObjects valueForKey:@"path"]; - for(NSString *path in paths) { - [sandboxPathBehaviorController removePath:path]; + NSArray *tokens = [selectedObjects valueForKey:@"token"]; + for(id token in tokens) { + [sandboxPathBehaviorController removeToken:token]; } } } diff --git a/Preferences/Preferences/SandboxPathBehaviorController.h b/Preferences/Preferences/SandboxPathBehaviorController.h index 3ce4d57b5..d2a04c958 100644 --- a/Preferences/Preferences/SandboxPathBehaviorController.h +++ b/Preferences/Preferences/SandboxPathBehaviorController.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SandboxPathBehaviorController : NSArrayController - (void)addUrl:(NSURL *)url; -- (void)removePath:(NSString *)path; +- (void)removeToken:(id)token; - (void)removeStaleEntries; - (BOOL)matchesPath:(NSURL *)url; diff --git a/Preferences/Preferences/SandboxPathBehaviorController.m b/Preferences/Preferences/SandboxPathBehaviorController.m index c3f6fd9e5..7b02200e6 100644 --- a/Preferences/Preferences/SandboxPathBehaviorController.m +++ b/Preferences/Preferences/SandboxPathBehaviorController.m @@ -73,36 +73,29 @@ } } -- (void)removePath:(NSString *)path { +- (void)removeToken:(id)token { + NSPersistentContainer *pc = [NSClassFromString(@"PlaylistController") sharedPersistentContainer]; + NSArray *objects = [[self arrangedObjects] copy]; + + BOOL updated = NO; for(NSDictionary *obj in objects) { - if([[obj objectForKey:@"path"] isEqualToString:path]) { + if([[obj objectForKey:@"token"] isEqualTo:token]) { [self removeObject:obj]; + [pc.viewContext deleteObject:token]; + updated = YES; break; } } - NSPersistentContainer *pc = [NSClassFromString(@"PlaylistController") sharedPersistentContainer]; - - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"path == %@", path]; - - NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"SandboxToken"]; - request.predicate = predicate; - - NSError *error = nil; - NSArray *results = [pc.viewContext executeFetchRequest:request error:&error]; - - if(results && [results count] > 0) { - for(SandboxToken *token in results) { - [pc.viewContext deleteObject:token]; + if(updated) { + NSError *error; + [pc.viewContext save:&error]; + if(error) { + ALog(@"Error deleting bookmark: %@", [error localizedDescription]); } } - - [pc.viewContext save:&error]; - if(error) { - ALog(@"Error deleting bookmark: %@", [error localizedDescription]); - } } - (void)removeStaleEntries {