| 898 |
urbaneks |
1 |
/*
|
|
|
2 |
* R.app : a Cocoa front end to: "R A Computer Language for Statistical Data Analysis"
|
|
|
3 |
*
|
|
|
4 |
* R.app Copyright notes:
|
| 1254 |
iacus |
5 |
* Copyright (C) 2004-5 The R Foundation
|
| 898 |
urbaneks |
6 |
* written by Stefano M. Iacus and Simon Urbanek
|
|
|
7 |
*
|
|
|
8 |
*
|
|
|
9 |
* R Copyright notes:
|
|
|
10 |
* Copyright (C) 1995-1996 Robert Gentleman and Ross Ihaka
|
|
|
11 |
* Copyright (C) 1998-2001 The R Development Core Team
|
|
|
12 |
* Copyright (C) 2002-2004 The R Foundation
|
|
|
13 |
*
|
|
|
14 |
* This program is free software; you can redistribute it and/or modify
|
|
|
15 |
* it under the terms of the GNU General Public License as published by
|
|
|
16 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
17 |
* (at your option) any later version.
|
|
|
18 |
*
|
|
|
19 |
* This program is distributed in the hope that it will be useful,
|
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
22 |
* GNU General Public License for more details.
|
|
|
23 |
*
|
|
|
24 |
* A copy of the GNU General Public License is available via WWW at
|
|
|
25 |
* http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
|
|
|
26 |
* writing to the Free Software Foundation, Inc., 59 Temple Place,
|
|
|
27 |
* Suite 330, Boston, MA 02111-1307 USA.
|
|
|
28 |
*
|
|
|
29 |
* Created by Simon Urbanek on 1/11/05.
|
|
|
30 |
*/
|
|
|
31 |
|
|
|
32 |
#import "RConsoleController.h"
|
|
|
33 |
#import "PreferenceKeys.h"
|
| 1045 |
urbaneks |
34 |
#import "RGUI.h"
|
| 898 |
urbaneks |
35 |
|
|
|
36 |
@implementation RConsoleController
|
|
|
37 |
|
|
|
38 |
- (id) init
|
|
|
39 |
{
|
|
|
40 |
NSLog(@"RConsoleControlelr created");
|
|
|
41 |
self = [super init];
|
|
|
42 |
if (self) {
|
|
|
43 |
consoleColorsKeys = [[NSArray alloc] initWithObjects:
|
|
|
44 |
backgColorKey, inputColorKey, outputColorKey, promptColorKey,
|
| 4638 |
urbaneks |
45 |
stderrColorKey, stdoutColorKey, rootColorKey, nil];
|
| 898 |
urbaneks |
46 |
defaultConsoleColors = [[NSArray alloc] initWithObjects: // default colors
|
|
|
47 |
[NSColor whiteColor], [NSColor blueColor], [NSColor blackColor], [NSColor purpleColor],
|
| 4638 |
urbaneks |
48 |
[NSColor redColor], [NSColor grayColor], [NSColor purpleColor], nil];
|
| 898 |
urbaneks |
49 |
consoleColors = [defaultConsoleColors mutableCopy];
|
|
|
50 |
}
|
|
|
51 |
return self;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
- (void) windowDidLoad
|
|
|
55 |
{
|
| 1459 |
urbaneks |
56 |
[self updatePreferences];
|
| 898 |
urbaneks |
57 |
[[Preferences sharedPreferences] addDependent:self];
|
|
|
58 |
|
|
|
59 |
outputPosition = promptPosition = committedLength = 0;
|
|
|
60 |
|
|
|
61 |
[[self window] setBackgroundColor:[defaultConsoleColors objectAtIndex:iBackgroundColor]];
|
|
|
62 |
[[self window] setOpaque:NO]; // Needed so we can see through it when we have clear stuff on top
|
|
|
63 |
[console setDrawsBackground:NO];
|
|
|
64 |
[[console enclosingScrollView] setDrawsBackground:NO];
|
|
|
65 |
|
|
|
66 |
[console setFont:[NSFont userFixedPitchFontOfSize:currentFontSize]];
|
| 5705 |
urbaneks |
67 |
|
| 898 |
urbaneks |
68 |
// make sure the input caret has the right color
|
|
|
69 |
if (0) {
|
|
|
70 |
NSMutableDictionary *md = [[console typingAttributes] mutableCopy];
|
|
|
71 |
[md setObject: [consoleColors objectAtIndex:iInputColor] forKey: @"NSColor"];
|
|
|
72 |
[console setTypingAttributes:[NSDictionary dictionaryWithDictionary:md]];
|
|
|
73 |
[md release];
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
[console setContinuousSpellCheckingEnabled:NO]; // force 'no spell checker'
|
|
|
77 |
|
|
|
78 |
[console display];
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
- (NSUndoManager*) windowWillReturnUndoManager: (NSWindow*) sender
|
|
|
82 |
{
|
|
|
83 |
return [[self document] undoManager];
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
- (void) updatePreferences {
|
|
|
87 |
currentFontSize = [Preferences floatForKey: FontSizeKey withDefault: 11.0];
|
|
|
88 |
|
|
|
89 |
{
|
|
|
90 |
int i = 0, ccs = [consoleColorsKeys count];
|
|
|
91 |
while (i<ccs) {
|
|
|
92 |
NSColor *c = [Preferences unarchivedObjectForKey: [consoleColorsKeys objectAtIndex:i] withDefault: [consoleColors objectAtIndex:i]];
|
|
|
93 |
if (c != [consoleColors objectAtIndex:i]) {
|
|
|
94 |
[consoleColors replaceObjectAtIndex:i withObject:c];
|
|
|
95 |
if (i == iBackgroundColor) {
|
|
|
96 |
[[self window] setBackgroundColor:c];
|
|
|
97 |
[[self window] display];
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
i++;
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
[console setNeedsDisplay:YES];
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
|
|
|
107 |
{
|
| 1045 |
urbaneks |
108 |
return NLS(@"R Console");
|
| 898 |
urbaneks |
109 |
}
|
|
|
110 |
|
|
|
111 |
@end
|