class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / editors / scapp / SCDialog.mm
blob1e2a2a4ef0a86e7ba850da04e869fa38f20f2ddd
1 //
2 //  SCDialogs.m
3 //  SC3lang
4 //
5 //  Created by cruxxial on Tue Dec 17 2002.
6 /*
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
22 #import "SCDialog.h"
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;
36         result = argResult;
37                 openPanel = 0;
38         }
39     return self;
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
56     if (!openPanel) {
57                 openPanel = [NSOpenPanel openPanel];
58                 [openPanel retain];
59         }
60         [openPanel setAllowsMultipleSelection: allowsMultiple];
61     if(NSOKButton == [openPanel runModalForTypes: nil]) {
62          [self returnPaths: [openPanel URLs]];
63     } else {
64         [self cancel];
65     }
69 -(void)returnPaths:(NSArray*)urls
71         int i;
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++)
78         {
79                 PyrString* pyrPathString = newPyrString(g->gc,[[[urls objectAtIndex: i ] path] cString],0,true);
81                 SetObject(array->slots + array->size, pyrPathString);
82                 array->size++;
84                 g->gc->GCWrite(array,pyrPathString);
86         }
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);
94         [self ok];
97 -(void)savePanel
99         NSSavePanel *savePanel = [NSSavePanel savePanel];
100         if([savePanel runModal] == NSFileHandlingPanelOKButton) {
101                 [self returnPath: [savePanel filename]];
102         } else {
103                 [self cancel];
104         }
107 -(void)returnPath:(NSString*)path
109         // check if greater than 512
110         int size = [path cStringLength];
111         if(size > 512) {
112                 [self error];
113                 return;
114         }
116         pthread_mutex_lock (&gLangMutex);
117         memcpy(result->slots,[path cString], size);
118         result->size = size;
119         pthread_mutex_unlock (&gLangMutex);
121         [self ok];
124 /*  better done using SCTextField
125 -(void)getStringPrompt:(NSString*)prompt defaultString:(NSString*)defaultString
128 - (void)loadGetStringUI {
129     if (!textField) {
130         if (![NSBundle loadNibNamed:@"GetStringDlg" owner:self])  {
131             NSLog(@"Failed to load GetStringDlg.nib");
132         }
133         //if (self == sharedGetStringObject)
134         [[textField window] setFrameAutosaveName:@"GetString"];
135     }
139 // get color dialog
141 // all responses
142 -(void)ok
144     pthread_mutex_lock (&gLangMutex);
145                 PyrSymbol *method = getsym("ok");
146         VMGlobals *g = gMainVMGlobals;
147         g->canCallOS = true;
148         ++g->sp;  SetObject(g->sp, receiver );
149         runInterpreter(g, method, 1);
150         g->canCallOS = false;
151     pthread_mutex_unlock (&gLangMutex);
154 -(void)cancel
156     pthread_mutex_lock (&gLangMutex);
157                 PyrSymbol *method = getsym("cancel");
158         VMGlobals *g = gMainVMGlobals;
159         g->canCallOS = true;
160         ++g->sp;  SetObject(g->sp, receiver );
161         runInterpreter(g, method, 1);
162         g->canCallOS = false;
163     pthread_mutex_unlock (&gLangMutex);
166 -(void)error
168     pthread_mutex_lock (&gLangMutex);
169                 PyrSymbol *method = getsym("errir");
170         VMGlobals *g = gMainVMGlobals;
171         g->canCallOS = true;
172         ++g->sp;  SetObject(g->sp, receiver );
173         runInterpreter(g, method, 1);
174         g->canCallOS = false;
175     pthread_mutex_unlock (&gLangMutex);
181 @end