mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 00:02:28 +00:00
made API more terse on type
This commit is contained in:
@@ -48,7 +48,7 @@ FOUNDATION_EXPORT NSString *const MPPasteBoardControllerDidClearClipboard;
|
|||||||
|
|
||||||
- (void)stashObjects;
|
- (void)stashObjects;
|
||||||
- (void)restoreObjects;
|
- (void)restoreObjects;
|
||||||
- (void)copyObjects:(NSArray *)objects;
|
- (void)copyObjects:(NSArray<id<NSPasteboardWriting>> *)objects;
|
||||||
- (void)copyObjectsWithoutTimeout:(NSArray *)objects;
|
- (void)copyObjectsWithoutTimeout:(NSArray<id<NSPasteboardWriting>> *)objects;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -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 {
|
- (void)setClearPasteboardOnShutdown:(BOOL)clearPasteboardOnShutdown {
|
||||||
if(_clearPasteboardOnShutdown != clearPasteboardOnShutdown ) {
|
if(_clearPasteboardOnShutdown != clearPasteboardOnShutdown ) {
|
||||||
_clearPasteboardOnShutdown = !_clearPasteboardOnShutdown;
|
_clearPasteboardOnShutdown = !_clearPasteboardOnShutdown;
|
||||||
@@ -79,7 +70,7 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
|
|||||||
|
|
||||||
- (void)stashObjects {
|
- (void)stashObjects {
|
||||||
self.stashedObjects = [NSMutableArray array];
|
self.stashedObjects = [NSMutableArray array];
|
||||||
for (NSPasteboardItem *item in [NSPasteboard generalPasteboard].pasteboardItems) {
|
for (NSPasteboardItem *item in NSPasteboard.generalPasteboard.pasteboardItems) {
|
||||||
NSPasteboardItem *newItem = [[NSPasteboardItem alloc] init];
|
NSPasteboardItem *newItem = [[NSPasteboardItem alloc] init];
|
||||||
for (NSString *type in item.types) {
|
for (NSString *type in item.types) {
|
||||||
NSData *data = [[item dataForType:type] mutableCopy];
|
NSData *data = [[item dataForType:type] mutableCopy];
|
||||||
@@ -93,14 +84,14 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
|
|||||||
|
|
||||||
- (void)restoreObjects {
|
- (void)restoreObjects {
|
||||||
if (self.stashedObjects) {
|
if (self.stashedObjects) {
|
||||||
[[NSPasteboard generalPasteboard] clearContents];
|
[NSPasteboard.generalPasteboard clearContents];
|
||||||
[[NSPasteboard generalPasteboard] writeObjects:self.stashedObjects];
|
[NSPasteboard.generalPasteboard writeObjects:self.stashedObjects];
|
||||||
self.stashedObjects = nil;
|
self.stashedObjects = nil;
|
||||||
self.isEmpty = YES;
|
self.isEmpty = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)copyObjects:(NSArray *)objects {
|
- (void)copyObjects:(NSArray<id<NSPasteboardWriting>> *)objects {
|
||||||
[self copyObjectsWithoutTimeout:objects];
|
[self copyObjectsWithoutTimeout:objects];
|
||||||
if(self.clearTimeout != 0) {
|
if(self.clearTimeout != 0) {
|
||||||
[NSNotificationCenter.defaultCenter postNotificationName:MPPasteBoardControllerDidCopyObjects object:self];
|
[NSNotificationCenter.defaultCenter postNotificationName:MPPasteBoardControllerDidCopyObjects object:self];
|
||||||
@@ -108,10 +99,9 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)copyObjectsWithoutTimeout:(NSArray *)objects
|
- (void)copyObjectsWithoutTimeout:(NSArray<id<NSPasteboardWriting>> *)objects {
|
||||||
{
|
[NSPasteboard.generalPasteboard clearContents];
|
||||||
[[NSPasteboard generalPasteboard] clearContents];
|
[NSPasteboard.generalPasteboard writeObjects:objects];
|
||||||
[[NSPasteboard generalPasteboard] writeObjects:objects];
|
|
||||||
self.isEmpty = NO;
|
self.isEmpty = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,19 +114,24 @@ NSString *const MPPasteBoardControllerDidClearClipboard = @"com.hicknhack.macpas
|
|||||||
self.isEmpty = YES;
|
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 {
|
- (void)_setupBindings {
|
||||||
NSUserDefaultsController *userDefaultsController = [NSUserDefaultsController sharedUserDefaultsController];
|
|
||||||
NSString *clearOnShutdownKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyClearPasteboardOnQuit];
|
|
||||||
NSString *clearTimoutKeyPath = [MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPasteboardClearTimeout];
|
|
||||||
|
|
||||||
[self bind:NSStringFromSelector(@selector(clearPasteboardOnShutdown))
|
[self bind:NSStringFromSelector(@selector(clearPasteboardOnShutdown))
|
||||||
toObject:userDefaultsController
|
toObject:NSUserDefaultsController.sharedUserDefaultsController
|
||||||
withKeyPath:clearOnShutdownKeyPath
|
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyClearPasteboardOnQuit]
|
||||||
options:nil];
|
options:nil];
|
||||||
|
|
||||||
[self bind:NSStringFromSelector(@selector(clearTimeout))
|
[self bind:NSStringFromSelector(@selector(clearTimeout))
|
||||||
toObject:userDefaultsController
|
toObject:NSUserDefaultsController.sharedUserDefaultsController
|
||||||
withKeyPath:clearTimoutKeyPath
|
withKeyPath:[MPSettingsHelper defaultControllerPathForKey:kMPSettingsKeyPasteboardClearTimeout]
|
||||||
options:nil];
|
options:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user