| 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 "RConsoleTextStorage.h"
|
|
|
33 |
#import "RController.h" // for currentFont
|
|
|
34 |
|
|
|
35 |
@implementation RConsoleTextStorage
|
|
|
36 |
|
|
|
37 |
- (id) init
|
|
|
38 |
{
|
|
|
39 |
self = [super init];
|
|
|
40 |
if (self) {
|
|
|
41 |
cont = [[NSMutableAttributedString alloc] init];
|
| 6041 |
bibiko |
42 |
theFont = [[[RController sharedController] currentFont] retain];
|
|
|
43 |
lastUsedColor = nil;
|
| 898 |
urbaneks |
44 |
}
|
|
|
45 |
return self;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
- (void) dealloc
|
|
|
49 |
{
|
|
|
50 |
[cont release];
|
| 6041 |
bibiko |
51 |
[theFont release];
|
|
|
52 |
if(lastUsedColor) [lastUsedColor release];
|
| 1253 |
urbaneks |
53 |
[super dealloc];
|
| 898 |
urbaneks |
54 |
}
|
|
|
55 |
|
|
|
56 |
// mandatory primitive methods
|
|
|
57 |
|
|
|
58 |
- (NSString*) string
|
|
|
59 |
{
|
|
|
60 |
return [cont string];
|
|
|
61 |
}
|
|
|
62 |
|
| 5707 |
urbaneks |
63 |
- (NSDictionary *) attributesAtIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange
|
| 898 |
urbaneks |
64 |
{
|
|
|
65 |
return [cont attributesAtIndex:index effectiveRange:aRange];
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
- (void) replaceCharactersInRange:(NSRange)aRange withString:(NSString *)aString
|
|
|
69 |
{
|
| 899 |
urbaneks |
70 |
//NSLog(@"replace [%d/%d] by %d chars [%@]", aRange.location, aRange.length, [aString length], aString);
|
| 898 |
urbaneks |
71 |
[cont replaceCharactersInRange:aRange withString:aString];
|
|
|
72 |
[self edited:NSTextStorageEditedCharacters range:aRange changeInLength:[aString length]-aRange.length];
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)aRange
|
|
|
76 |
{
|
| 899 |
urbaneks |
77 |
//NSLog(@"attrs set at [%d/%d] which amounts to [:%d] and cur len is %d", aRange.location, aRange.length, aRange.location+aRange.length, [cont length]);
|
| 898 |
urbaneks |
78 |
[cont setAttributes:attributes range:aRange];
|
|
|
79 |
[self edited:NSTextStorageEditedAttributes range:aRange changeInLength:0];
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
// end of primitive methods
|
|
|
83 |
|
|
|
84 |
// This is the default method for writing text to the console. Note that the application should use begin/endEditing and in addition to textStorage methods it may want to use setSelectedRange: and scrollRangeToVisible: of textView to update the text caret.
|
|
|
85 |
- (void) insertText: (NSString*) text atIndex: (int) index withColor: (NSColor*) color
|
|
|
86 |
{
|
| 899 |
urbaneks |
87 |
//NSLog(@"insert %d chars at %d to result in %d length", [text length], index, [cont length]+[text length]);
|
| 898 |
urbaneks |
88 |
[cont replaceCharactersInRange: NSMakeRange(index,0) withString: text];
|
| 6041 |
bibiko |
89 |
// cont will use the current attributes at cursor location, change them only if color or font were changed
|
|
|
90 |
if(!lastUsedColor || lastUsedColor != color) {
|
|
|
91 |
if(lastUsedColor) [lastUsedColor release];
|
|
|
92 |
lastUsedColor = [color retain];
|
|
|
93 |
[cont addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
94 |
theFont, NSFontAttributeName,
|
|
|
95 |
color, NSForegroundColorAttributeName,
|
|
|
96 |
nil] range:NSMakeRange(index, [text length])];
|
|
|
97 |
}
|
| 898 |
urbaneks |
98 |
[self edited:NSTextStorageEditedCharacters|NSTextStorageEditedAttributes range: NSMakeRange(index,0) changeInLength:[text length]];
|
|
|
99 |
}
|
|
|
100 |
|
| 6041 |
bibiko |
101 |
- (void)setFont:(NSFont*)aFont
|
|
|
102 |
{
|
|
|
103 |
if(theFont) [theFont release], theFont = nil;
|
|
|
104 |
theFont = [aFont retain];
|
|
|
105 |
if(lastUsedColor) [lastUsedColor release], lastUsedColor = nil;
|
|
|
106 |
}
|
|
|
107 |
|
| 898 |
urbaneks |
108 |
@end
|