class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / editors / scapp / iPhone / LiveCodingViewController.mm
blob6cf9dd57e59e81a4530d346817d8b8606d0d408f
1 //
2 //  LiveCodingViewController.m
3 //  isclang
4 //
5 //  Created by Axel Balley on 30/10/08.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
9 #import "LiveCodingViewController.h"
11 extern void rtf2txt(char *txt);
13 @implementation LiveCodingViewController
15 - (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
17     if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
18         {
19                 target = 0;
20                 selector = 0;
21         }
22         return self;
25 - (void) viewDidLoad
27         [textView setAutocapitalizationType:UITextAutocapitalizationTypeNone];
28         [textView setAutocorrectionType:UITextAutocorrectionTypeNo];
29         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
30         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
31         [self showButtons:NO];
34 - (void) keyboardDidShow:(NSNotification *) notif
36         NSDictionary *info = [notif userInfo];
37         NSValue *val = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
38         CGRect r = [val CGRectValue];
39         
40         CGRect done_frame = doneButton.frame;
41         CGRect exec_frame = execButton.frame;
42         
43         r = [self.view convertRect:r fromView:nil];
44                                 
45         done_frame.origin.y = r.origin.y - done_frame.size.height - 10;
46         exec_frame.origin.y = done_frame.origin.y;
47         
48         [doneButton setFrame:done_frame];
49         [execButton setFrame:exec_frame];
50         
51         [self showButtons:YES];
54 - (void) keyboardWillHide:(NSNotification *) notif
56         [self showButtons:NO];
59 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
61         return YES;
64 - (void) setTarget:(id)t withSelector:(SEL)s
66         target = t;
67         selector = s;
70 - (void) loadFile:(NSString *)file
72         NSString *contents = [NSString stringWithContentsOfFile:file encoding:NSASCIIStringEncoding error:nil];
73         int length = [contents length];
74         char *buf = (char *) malloc(length+1);
75         [contents getCString:buf maxLength:length+1 encoding:NSASCIIStringEncoding];
76         rtf2txt(buf);
77         while (*buf=='\n') buf++;
78         
79         [textView setText:[NSString stringWithCString:buf encoding:NSASCIIStringEncoding]];
82 - (void) showButtons: (BOOL)state
84         [doneButton setHidden:!state];
85         [execButton setHidden:!state];
88 - (void) textViewDidBeginEditing: (UITextView *)theView
90         //[self showButtons:YES];
93 - (IBAction) triggerDone: (id)sender
95         [textView resignFirstResponder];
96         [self showButtons:NO];
99 - (IBAction) triggerExecute: (id)sender
101         NSRange range = [textView selectedRange];
102         NSString *text = [textView text];
103         NSUInteger start, end;
104         [text getLineStart:&start end:&end contentsEnd:nil forRange:range];
105         NSString *line = [text substringWithRange:NSMakeRange(start, end-start)];
106         
107         if (target && [target respondsToSelector:selector]) [target performSelector:selector withObject:line];
108         
109         [textView resignFirstResponder];
110         [self showButtons:NO];
113 - (IBAction) triggerExecuteFile: (id)sender
115         if (target && [target respondsToSelector:selector]) [target performSelector:selector withObject:[textView text]];
118 - (void) dealloc
120     [super dealloc];
124 @end