The R Project SVN R-packages

Rev

Rev 1254 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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,
45
			stderrColorKey, stdoutColorKey, rootColorKey];
46
		defaultConsoleColors = [[NSArray alloc] initWithObjects: // default colors
47
			[NSColor whiteColor], [NSColor blueColor], [NSColor blackColor], [NSColor purpleColor],
48
			[NSColor redColor], [NSColor grayColor], [NSColor purpleColor]];
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]];
67
	// [fontSizeStepper setIntValue:currentFontSize];
68
    // theFont=[RTextView font];
69
    // theFont=[[NSFontManager sharedFontManager] convertFont:theFont toSize:[fontSizeStepper intValue]];
70
    // [RTextView setFont:theFont];
71
 
72
	// make sure the input caret has the right color
73
	if (0) {
74
		NSMutableDictionary *md = [[console typingAttributes] mutableCopy];
75
		[md setObject: [consoleColors objectAtIndex:iInputColor] forKey: @"NSColor"];
76
		[console setTypingAttributes:[NSDictionary dictionaryWithDictionary:md]];
77
		[md release];
78
	}
79
 
80
	[console setContinuousSpellCheckingEnabled:NO]; // force 'no spell checker'
81
 
82
	//	[RTextView changeColor: inputColor];
83
	[console display];
84
}
85
 
86
- (NSUndoManager*) windowWillReturnUndoManager: (NSWindow*) sender
87
{
88
	return [[self document] undoManager];
89
}
90
 
91
- (void) updatePreferences {
92
	currentFontSize = [Preferences floatForKey: FontSizeKey withDefault: 11.0];
93
 
94
	{
95
		int i = 0, ccs = [consoleColorsKeys count];
96
		while (i<ccs) {
97
			NSColor *c = [Preferences unarchivedObjectForKey: [consoleColorsKeys objectAtIndex:i] withDefault: [consoleColors objectAtIndex:i]];
98
			if (c != [consoleColors objectAtIndex:i]) {
99
				[consoleColors replaceObjectAtIndex:i withObject:c];
100
				if (i == iBackgroundColor) {
101
					[[self window] setBackgroundColor:c];
102
					[[self window] display];
103
				}
104
			}
105
			i++;
106
		}
107
	}
108
	[console setNeedsDisplay:YES];
109
}
110
 
111
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
112
{
1045 urbaneks 113
	return NLS(@"R Console");
898 urbaneks 114
}
115
 
116
@end