mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-23 15:09:25 +00:00
54 lines
1.1 KiB
Objective-C
54 lines
1.1 KiB
Objective-C
//
|
|
// MPAutotypePaste.m
|
|
// MacPass
|
|
//
|
|
// Created by Michael Starke on 24/11/13.
|
|
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
|
|
//
|
|
|
|
#import "MPAutotypePaste.h"
|
|
#import "MPPasteBoardController.h"
|
|
|
|
#import "NSString+Commands.h"
|
|
|
|
@interface MPAutotypePaste ()
|
|
|
|
@property (strong) NSString *pasteData;
|
|
|
|
@end
|
|
|
|
@implementation MPAutotypePaste
|
|
|
|
- (instancetype)initWithString:(NSString *)aString {
|
|
self = [super init];
|
|
if(self) {
|
|
self.pasteData = aString;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)appendString:(NSString *)aString {
|
|
self.pasteData = [self.pasteData stringByAppendingString:aString];
|
|
}
|
|
|
|
|
|
- (void)execute {
|
|
if([self.pasteData length] > 0) {
|
|
MPPasteBoardController *controller = [MPPasteBoardController defaultController];
|
|
[controller stashObjects];
|
|
[controller copyObjectsWithoutTimeout:@[self.pasteData]];
|
|
[self sendPasteKeyCode];
|
|
usleep(0.1 * NSEC_PER_MSEC); // on 10.10 we need to wait a bit before restoring the pasteboard contents
|
|
[controller restoreObjects];
|
|
}
|
|
}
|
|
|
|
- (BOOL)isValid {
|
|
/* Pasting shoudl always be valid */
|
|
return YES;
|
|
}
|
|
|
|
|
|
|
|
@end
|