The R Project SVN R-packages

Rev

Rev 6128 | Rev 6232 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6128 Rev 6137
Line 40... Line 40...
40
@implementation RScriptEditorTextStorage
40
@implementation RScriptEditorTextStorage
41
 
41
 
42
@synthesize lineFoldingEnabled = _lineFoldingEnabled;
42
@synthesize lineFoldingEnabled = _lineFoldingEnabled;
43
 
43
 
44
static NSTextAttachment *sharedAttachment = nil;
44
static NSTextAttachment *sharedAttachment = nil;
-
 
45
static SEL _getSel;
-
 
46
static SEL _setSel;
45
 
47
 
46
+ (void)initialize
48
+ (void)initialize
47
{
49
{
48
 
50
 
49
	if ([self class] == [RScriptEditorTextStorage class]) {
51
	if ([self class] == [RScriptEditorTextStorage class]) {
50
		FoldingSignTextAttachmentCell *cell = [[FoldingSignTextAttachmentCell alloc] initImageCell:nil];
52
		FoldingSignTextAttachmentCell *cell = [[FoldingSignTextAttachmentCell alloc] initImageCell:nil];
51
		sharedAttachment = [[NSTextAttachment alloc] init];
53
		sharedAttachment = [[NSTextAttachment alloc] init];
52
		[sharedAttachment setAttachmentCell:cell];
54
		[sharedAttachment setAttachmentCell:cell];
53
		[cell release];
55
		[cell release];
-
 
56
		_getSel = @selector(attributesAtIndex:effectiveRange:);
-
 
57
		_setSel = @selector(setAttributes:range:);
54
	}
58
	}
55
}
59
}
56
 
60
 
57
+ (NSTextAttachment *)attachment
61
+ (NSTextAttachment *)attachment
58
{
62
{
Line 63... Line 67...
63
{
67
{
64
	self = [super init];
68
	self = [super init];
65
 
69
 
66
	if (self != nil) {
70
	if (self != nil) {
67
		_attributedString = [[NSTextStorage alloc] init];
71
		_attributedString = [[NSTextStorage alloc] init];
-
 
72
		_getImp = [_attributedString methodForSelector:_getSel];
-
 
73
		_setImp = [_attributedString methodForSelector:_setSel];
68
	}
74
	}
69
 
75
 
70
	return self;
76
	return self;
71
}
77
}
72
 
78
 
Line 85... Line 91...
85
 
91
 
86
 
92
 
87
- (NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range
93
- (NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range
88
{
94
{
89
 
95
 
90
	if(!_lineFoldingEnabled) return [_attributedString attributesAtIndex:location effectiveRange:range];
96
	NSDictionary *attributes = (*_getImp)(_attributedString, _getSel, location, range);
91
 
97
 
92
	NSDictionary *attributes = [_attributedString attributesAtIndex:location effectiveRange:range];
98
	if(!_lineFoldingEnabled) return attributes;
93
 
99
 
94
	if (_lineFoldingEnabled) {
-
 
95
		id value;
100
	id value;
96
		NSRange effectiveRange;
101
	NSRange effectiveRange;
97
 
102
 
98
		value = [attributes objectForKey:foldingAttributeName];
103
	value = [attributes objectForKey:foldingAttributeName];
99
		if (value && [value boolValue]) {
104
	if (value && [value boolValue]) {
100
			[_attributedString attribute:foldingAttributeName atIndex:location longestEffectiveRange:&effectiveRange inRange:NSMakeRange(0, [_attributedString length])];
105
		[_attributedString attribute:foldingAttributeName atIndex:location longestEffectiveRange:&effectiveRange inRange:NSMakeRange(0, [_attributedString length])];
101
 
106
 
102
			// We adds NSAttachmentAttributeName if in lineFoldingAttributeName
107
		// We adds NSAttachmentAttributeName if in lineFoldingAttributeName
103
			if (location == effectiveRange.location) { // beginning of a folded range
108
		if (location == effectiveRange.location) { // beginning of a folded range
104
				NSMutableDictionary *dict = [attributes mutableCopyWithZone:NULL];
109
			NSMutableDictionary *dict = [attributes mutableCopyWithZone:NULL];
105
				[dict setObject:[RScriptEditorTextStorage attachment] forKey:NSAttachmentAttributeName];
110
			[dict setObject:sharedAttachment forKey:NSAttachmentAttributeName];
106
				attributes = [dict autorelease];
111
			attributes = [dict autorelease];
107
				effectiveRange.length = 1;
112
			effectiveRange.length = 1;
108
			} else {
113
		} else {
109
				++(effectiveRange.location); --(effectiveRange.length);
114
			++(effectiveRange.location); --(effectiveRange.length);
110
			}
-
 
111
			if (range) *range = effectiveRange;
-
 
112
		}
115
		}
-
 
116
		if (range) *range = effectiveRange;
113
	}
117
	}
114
 
118
 
115
	return attributes;
119
	return attributes;
-
 
120
 
116
}
121
}
117
 
122
 
118
// NSMutableAttributedString primitives
123
// NSMutableAttributedString primitives
119
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str
124
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str
120
{
125
{
Line 122... Line 127...
122
	[self edited:NSTextStorageEditedCharacters range:range changeInLength:[str length] - range.length];
127
	[self edited:NSTextStorageEditedCharacters range:range changeInLength:[str length] - range.length];
123
}
128
}
124
 
129
 
125
- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range
130
- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range
126
{
131
{
127
	[_attributedString setAttributes:attrs range:range];
132
	(*_setImp)(_attributedString, _setSel, attrs, range);
128
	[self edited:NSTextStorageEditedAttributes range:range changeInLength:0];
133
	[self edited:NSTextStorageEditedAttributes range:range changeInLength:0];
129
}
134
}
130
 
135
 
131
// Attribute Fixing Overrides
136
// Attribute Fixing Overrides
132
/*
137
/*