summaryrefslogtreecommitdiff
path: root/ext/mac-ui-macgap1-wrapper/src/MacGap/Clipboard.m
blob: 1c18dea38a07fe0934dbf6529e8ced6689c3cf91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
//  clipboard.m
//  MacGap
//
//  Created by David Zorychta on 2013-07-22.
//  Copyright (c) 2013 Twitter. All rights reserved.
//

#import "Clipboard.h"

@implementation Clipboard

- (void) copy:(NSString*)text {
    [[NSPasteboard generalPasteboard] clearContents];
    [[NSPasteboard generalPasteboard] setString:text  forType:NSStringPboardType];
}

- (NSString *) paste {
    NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
    NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
    NSDictionary *options = [NSDictionary dictionary];
    BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
    if (ok) {
        NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
        return (NSString *) [objectsToPaste objectAtIndex:0];
    }
    return @"";
}

+ (NSString*) webScriptNameForSelector:(SEL)selector
{
	id	result = nil;
	
	if (selector == @selector(copy:)) {
        result = @"copy";
    }
	
	return result;
}

+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector
{
    return NO;
}

+ (BOOL) isKeyExcludedFromWebScript:(const char*)name
{
	return YES;
}

@end