-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pasteboard.m
111 lines (86 loc) · 1.98 KB
/
Pasteboard.m
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#import "Pasteboard.h"
#import "AppController.h"
#import "Clip.h"
@implementation Pasteboard
@synthesize lastCount;
@synthesize lastCountInt;
-(id) init
{
// GET PASTEBOARD
// Create our pasteboard interface
pb = [NSPasteboard generalPasteboard];
lastCount = [[NSNumber numberWithInt:[pb changeCount]] retain];
lastCountInt = [pb changeCount];
text = @"";
return self;
}
- (NSString *) typeNS
{
// TODO: Image support
/*BOOL image = [[pb pasteboardTypes] containsObject:@"public.png"];
if(image){
return @"image";
}
else {
return @"text";
}*/
return [[pb types] objectAtIndex:1];
}
- (NSString *) text
{
return [pb stringForType:NSPasteboardTypeString];
}
/*- (NSImageRep *) image
{
NSImage *image = [[NSImage alloc] initWithData: [pb dataForType:NSPasteboardTypePNG]];
NSImage *image2 = [[NSImage alloc ] initWithPasteboard:pb];
NSImageRep *imagerep = [NSImageRep imageRepWithPasteboard:pb];
return imagerep;
}*/
- (void) setImage:(NSImageRep *) image
{
[pb clearContents];
[pb writeObjects:[NSArray arrayWithObject:image]];
}
- (void) setText:(NSString *) string
{
[pb clearContents];
[pb writeObjects:[NSArray arrayWithObject:string]];
}
- (int) nowCount
{
return [pb changeCount];
}
- (BOOL) isText
{
// Test for strings on the pasteboard.
NSArray *classes = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];
if([pb canReadObjectForClasses:classes options:options])
{
return YES;
}
return NO;
}
- (BOOL) isImage
{
// Test for strings on the pasteboard.
NSArray *classes = [NSArray arrayWithObject:[NSImage class]];
NSDictionary *options = [NSDictionary dictionary];
if([pb canReadObjectForClasses:classes options:options])
{
return YES;
}
return NO;
}
/*- (BOOL) pasteUpdate
{
if(lastCountInt != [self currCount])
{
return YES;
}
else {
return NO;
}
}*/
@end