5 // Created by cruxxial on Tue Dec 17 2002.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 @implementation SCDialog
27 +(id)receiver:(PyrObject*)argReceiver result:(PyrObject*)argResult
29 return [[super alloc] initWithReceiver: argReceiver result: argResult];
32 -(id)initWithReceiver:(PyrObject*)argReceiver result:(PyrObject*)argResult
34 if(self == [super init]) {
35 receiver = argReceiver;
42 -(void)scvmDeferWithSelector:(SEL)selector
44 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
45 [self methodSignatureForSelector: selector]];
46 [invocation setTarget:self];
47 [invocation setSelector: selector];
48 [invocation retainArguments];
50 [[SCVirtualMachine sharedInstance] defer: invocation];
54 -(void)getPaths:(BOOL)allowsMultiple
57 openPanel = [NSOpenPanel openPanel];
60 [openPanel setAllowsMultipleSelection: allowsMultiple];
61 if(NSOKButton == [openPanel runModalForTypes: nil]) {
62 [self returnPaths: [openPanel URLs]];
69 -(void)returnPaths:(NSArray*)urls
72 int count = [urls count];
74 VMGlobals *g = gMainVMGlobals;
75 pthread_mutex_lock (&gLangMutex);
76 PyrObject* array = newPyrArray(g->gc, count, 0, true);
77 for (i = 0; i < count; i++)
79 PyrString* pyrPathString = newPyrString(g->gc,[[[urls objectAtIndex: i ] path] cString],0,true);
81 SetObject(array->slots + array->size, pyrPathString);
84 g->gc->GCWrite(array,pyrPathString);
88 int classVarIndex = slotRawInt(&getsym("CocoaDialog")->u.classobj->classVarIndex);
89 SetObject(&g->classvars->slots[classVarIndex+0], array);
90 g->gc->GCWrite(g->classvars, array);
92 pthread_mutex_unlock (&gLangMutex);
99 NSSavePanel *savePanel = [NSSavePanel savePanel];
100 if([savePanel runModal] == NSFileHandlingPanelOKButton) {
101 [self returnPath: [savePanel filename]];
107 -(void)returnPath:(NSString*)path
109 // check if greater than 512
110 int size = [path cStringLength];
116 pthread_mutex_lock (&gLangMutex);
117 memcpy(result->slots,[path cString], size);
119 pthread_mutex_unlock (&gLangMutex);
124 /* better done using SCTextField
125 -(void)getStringPrompt:(NSString*)prompt defaultString:(NSString*)defaultString
128 - (void)loadGetStringUI {
130 if (![NSBundle loadNibNamed:@"GetStringDlg" owner:self]) {
131 NSLog(@"Failed to load GetStringDlg.nib");
133 //if (self == sharedGetStringObject)
134 [[textField window] setFrameAutosaveName:@"GetString"];
144 pthread_mutex_lock (&gLangMutex);
145 PyrSymbol *method = getsym("ok");
146 VMGlobals *g = gMainVMGlobals;
148 ++g->sp; SetObject(g->sp, receiver );
149 runInterpreter(g, method, 1);
150 g->canCallOS = false;
151 pthread_mutex_unlock (&gLangMutex);
156 pthread_mutex_lock (&gLangMutex);
157 PyrSymbol *method = getsym("cancel");
158 VMGlobals *g = gMainVMGlobals;
160 ++g->sp; SetObject(g->sp, receiver );
161 runInterpreter(g, method, 1);
162 g->canCallOS = false;
163 pthread_mutex_unlock (&gLangMutex);
168 pthread_mutex_lock (&gLangMutex);
169 PyrSymbol *method = getsym("errir");
170 VMGlobals *g = gMainVMGlobals;
172 ++g->sp; SetObject(g->sp, receiver );
173 runInterpreter(g, method, 1);
174 g->canCallOS = false;
175 pthread_mutex_unlock (&gLangMutex);