| Line 37... |
Line 37... |
| 37 |
- (id) init
|
37 |
- (id) init
|
| 38 |
{
|
38 |
{
|
| 39 |
self = [super init];
|
39 |
self = [super init];
|
| 40 |
if (self) {
|
40 |
if (self) {
|
| 41 |
cont = [[NSMutableAttributedString alloc] init];
|
41 |
cont = [[NSMutableAttributedString alloc] init];
|
| - |
|
42 |
theFont = [[[RController sharedController] currentFont] retain];
|
| - |
|
43 |
lastUsedColor = nil;
|
| 42 |
}
|
44 |
}
|
| 43 |
return self;
|
45 |
return self;
|
| 44 |
}
|
46 |
}
|
| 45 |
|
47 |
|
| 46 |
- (void) dealloc
|
48 |
- (void) dealloc
|
| 47 |
{
|
49 |
{
|
| 48 |
[cont release];
|
50 |
[cont release];
|
| - |
|
51 |
[theFont release];
|
| - |
|
52 |
if(lastUsedColor) [lastUsedColor release];
|
| 49 |
[super dealloc];
|
53 |
[super dealloc];
|
| 50 |
}
|
54 |
}
|
| 51 |
|
55 |
|
| 52 |
// mandatory primitive methods
|
56 |
// mandatory primitive methods
|
| 53 |
|
57 |
|
| Line 80... |
Line 84... |
| 80 |
// 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.
|
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.
|
| 81 |
- (void) insertText: (NSString*) text atIndex: (int) index withColor: (NSColor*) color
|
85 |
- (void) insertText: (NSString*) text atIndex: (int) index withColor: (NSColor*) color
|
| 82 |
{
|
86 |
{
|
| 83 |
//NSLog(@"insert %d chars at %d to result in %d length", [text length], index, [cont length]+[text length]);
|
87 |
//NSLog(@"insert %d chars at %d to result in %d length", [text length], index, [cont length]+[text length]);
|
| 84 |
[cont replaceCharactersInRange: NSMakeRange(index,0) withString: text];
|
88 |
[cont replaceCharactersInRange: NSMakeRange(index,0) withString: text];
|
| - |
|
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];
|
| 85 |
[cont addAttribute:@"NSColor" value:color range: NSMakeRange(index, [text length])];
|
93 |
[cont addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
|
| - |
|
94 |
theFont, NSFontAttributeName,
|
| - |
|
95 |
color, NSForegroundColorAttributeName,
|
| 86 |
[cont addAttribute:@"NSFont" value:[[RController sharedController] currentFont] range: NSMakeRange(index, [text length])];
|
96 |
nil] range:NSMakeRange(index, [text length])];
|
| - |
|
97 |
}
|
| 87 |
[self edited:NSTextStorageEditedCharacters|NSTextStorageEditedAttributes range: NSMakeRange(index,0) changeInLength:[text length]];
|
98 |
[self edited:NSTextStorageEditedCharacters|NSTextStorageEditedAttributes range: NSMakeRange(index,0) changeInLength:[text length]];
|
| 88 |
}
|
99 |
}
|
| 89 |
|
100 |
|
| - |
|
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 |
|
| 90 |
@end
|
108 |
@end
|