made API more terse on type

This commit is contained in:
michael starke
2017-09-26 17:06:59 +02:00
parent 8ef532a208
commit fb49a4ac23
2 changed files with 22 additions and 27 deletions

View File

@@ -48,7 +48,7 @@ FOUNDATION_EXPORT NSString *const MPPasteBoardControllerDidClearClipboard;
- (void)stashObjects;
- (void)restoreObjects;
- (void)copyObjects:(NSArray *)objects;
- (void)copyObjectsWithoutTimeout:(NSArray *)objects;
- (void)copyObjects:(NSArray<id<NSPasteboardWriting>> *)objects;
- (void)copyObjectsWithoutTimeout:(NSArray<id<NSPasteboardWriting>> *)objects;
@end

View File

@@ -61,15 +61,6 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
}
}
- (void)_updateNotifications {
if(self.clearPasteboardOnShutdown) {
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_clearPasteboardContents) name:NSApplicationWillTerminateNotification object:nil];
}
else {
[NSNotificationCenter.defaultCenter removeObserver:self];
}
}
- (void)setClearPasteboardOnShutdown:(BOOL)clearPasteboardOnShutdown {
if(_clearPasteboardOnShutdown != clearPasteboardOnShutdown ) {
_clearPasteboardOnShutdown = !_clearPasteboardOnShutdown;
@@ -79,7 +70,7 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
- (void)stashObjects {
self.stashedObjects = [NSMutableArray array];
for (NSPasteboardItem *item in [NSPasteboard generalPasteboard].pasteboardItems) {
for (NSPasteboardItem *item in NSPasteboard.generalPasteboard.pasteboardItems) {
NSPasteboardItem *newItem = [[NSPasteboardItem alloc] init];
for (NSString *type in item.types) {
NSData *data = [[item dataForType:type] mutableCopy];
@@ -93,14 +84,14 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
- (void)restoreObjects {
if (self.stashedObjects) {
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] writeObjects:self.stashedObjects];
[NSPasteboard.generalPasteboard clearContents];
[NSPasteboard.generalPasteboard writeObjects:self.stashedObjects];
self.stashedObjects = nil;
self.isEmpty = YES;
}
}
- (void)copyObjects:(NSArray *)objects {
- (void)copyObjects:(NSArray<id<NSPasteboardWriting>> *)objects {
[self copyObjectsWithoutTimeout:objects];
if(self.clearTimeout != 0) {
[NSNotificationCenter.defaultCenter postNotificationName:MPPasteBoardControllerDidCopyObjects object:self];
@@ -108,10 +99,9 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
}
}
- (void)copyObjectsWithoutTimeout:(NSArray *)objects
{
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] writeObjects:objects];
- (void)copyObjectsWithoutTimeout:(NSArray<id<NSPasteboardWriting>> *)objects {
[NSPasteboard.generalPasteboard clearContents];
[NSPasteboard.generalPasteboard writeObjects:objects];
self.isEmpty = NO;
}
@@ -124,19 +114,24 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
self.isEmpty = YES;
}
- (void)_updateNotifications {
if(self.clearPasteboardOnShutdown) {
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_clearPasteboardContents) name:NSApplicationWillTerminateNotification object:nil];
}
else {
[NSNotificationCenter.defaultCenter removeObserver:self];
}
}
- (void)_setupBindings {
NSUserDefaultsController *userDefaultsController = [NSUserDefaultsController sharedUserDefaultsController];
NSString *clearOnShutdownKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyClearPasteboardOnQuit];
NSString *clearTimoutKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPasteboardClearTimeout];
[self bind:NSStringFromSelector(@selector(clearPasteboardOnShutdown))
toObject:userDefaultsController
withKeyPath:clearOnShutdownKeyPath
toObject:NSUserDefaultsController.sharedUserDefaultsController
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyClearPasteboardOnQuit]
options:nil];
[self bind:NSStringFromSelector(@selector(clearTimeout))
toObject:userDefaultsController
withKeyPath:clearTimoutKeyPath
toObject:NSUserDefaultsController.sharedUserDefaultsController
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPasteboardClearTimeout]
options:nil];
}