-
Notifications
You must be signed in to change notification settings - Fork 1
/
FTOpenPanelPatch.m
112 lines (94 loc) · 3.11 KB
/
FTOpenPanelPatch.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
112
#import "FTOpenPanelPatch.h"
@implementation FTOpenPanelPatch
+(BOOL)allowsSubpatchesWithIdentifier:(id)identifier
{
return NO;
}
-(id)initWithIdentifier:(id)identifier
{
if(self = [super initWithIdentifier:identifier])
{
[[self userInfo] setObject:@"Kineme Open Panel" forKey:@"name"];
// set default input port values here.
[inputTitle setStringValue:@"Open"];
[inputPrompt setStringValue:@"Open"];
[inputCanChooseFiles setBooleanValue:YES];
// only allow the window to actually activate if we're in the QC Editor or a QuartzBuilder application, so we don't spam users totally unexpectedly (from Finder, for example).
if([[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey] isEqualToString:@"com.apple.QuartzComposer.editor"])
allowed=YES;
else if(objc_getClass("RunnerController") && objc_getClass("RunnerWindow") && objc_getClass("RunnerView") && objc_getClass("QBParameterView"))
allowed=YES;
}
return self;
}
-(void)disable:(QCOpenGLContext*)context
{
if(openPanel)
{
[openPanel release];
openPanel=nil;
}
}
-(BOOL)execute:(QCOpenGLContext*)context time:(double)time arguments:(NSDictionary*)arguments
{
if(!allowed)
return YES;
[outputOKSignal setBooleanValue:NO];
[outputCancelSignal setBooleanValue:NO];
if([inputStartSignal wasUpdated] && [inputStartSignal booleanValue])
[self performSelectorOnMainThread:@selector(showOpenPanel) withObject:nil waitUntilDone:NO];
return YES;
}
- (void)showOpenPanel
{
if(openPanel)
[openPanel makeKeyAndOrderFront:self];
else
{
openPanel = [[NSOpenPanel alloc] init];
[openPanel setTitle:[inputTitle stringValue]];
[openPanel setMessage:[inputMessage stringValue]];
[openPanel setPrompt:[inputPrompt stringValue]];
[openPanel setCanChooseFiles:[inputCanChooseFiles booleanValue]];
[openPanel setCanChooseDirectories:[inputCanChooseDirectories booleanValue]];
[openPanel setAllowsMultipleSelection:[inputAllowsMultipleSelection booleanValue]];
[openPanel setAllowsOtherFileTypes:NO];
NSString *dir=nil;
NSURL *url = [NSURL URLWithString:[inputInitialURL stringValue]];
if([url isFileURL])
dir = [url path];
NSArray *types = nil;
NSString *typestr = [[inputAllowedFileTypes stringValue] stringByReplacingOccurrencesOfString:@" " withString:@""];
if([typestr length])
types = [typestr componentsSeparatedByString:@","];
[openPanel
beginForDirectory:dir
file:nil
types:types
modelessDelegate:self
didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
}
- (void)openPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
switch(returnCode)
{
case NSOKButton:
[outputOKSignal setBooleanValue:YES];
NSMutableArray *a = [[NSMutableArray alloc] initWithCapacity:10];
for(NSURL *u in [panel URLs])
[a addObject:[u absoluteString]];
QCStructure *s = [[QCStructure alloc] initWithArray:a];
[a release];
[outputSelectedURLs setStructureValue:s];
[s release];
break;
case NSCancelButton:
[outputCancelSignal setBooleanValue:YES];
break;
}
[panel release];
openPanel=nil;
}
@end