-
Notifications
You must be signed in to change notification settings - Fork 1
/
FTSavePanelPatch.m
108 lines (88 loc) · 2.91 KB
/
FTSavePanelPatch.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
#import "FTSavePanelPatch.h"
@implementation FTSavePanelPatch
+(BOOL)allowsSubpatchesWithIdentifier:(id)identifier
{
return NO;
}
-(id)initWithIdentifier:(id)identifier
{
if(self = [super initWithIdentifier:identifier])
{
[[self userInfo] setObject:@"Kineme Save Panel" forKey:@"name"];
// set default input port values here.
[inputTitle setStringValue:@"Save"];
[inputPrompt setStringValue:@"Save"];
[inputNameFieldLabel setStringValue:@"Save As:"];
// 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(savePanel)
{
[savePanel release];
savePanel=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(showSavePanel) withObject:nil waitUntilDone:NO];
return YES;
}
- (void)showSavePanel
{
if(savePanel)
[savePanel makeKeyAndOrderFront:self];
else
{
savePanel = [[NSSavePanel alloc] init];
[savePanel setTitle:[inputTitle stringValue]];
[savePanel setMessage:[inputMessage stringValue]];
[savePanel setPrompt:[inputPrompt stringValue]];
[savePanel setNameFieldLabel:[inputNameFieldLabel stringValue]];
[savePanel setCanCreateDirectories:[inputCanCreateDirectories booleanValue]];
[savePanel 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:@","];
[savePanel setAllowedFileTypes:types];
[savePanel
beginSheetForDirectory:dir
file:[inputInitialFilename stringValue]
modalForWindow:nil
modalDelegate:self
didEndSelector:@selector(savePanelDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
}
- (void)savePanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
switch(returnCode)
{
case NSOKButton:
[outputOKSignal setBooleanValue:YES];
[outputSelectedURL setStringValue:[[panel URL] absoluteString]];
break;
case NSCancelButton:
[outputCancelSignal setBooleanValue:YES];
break;
}
[panel release];
savePanel=nil;
}
@end