The R Project SVN R-packages

Rev

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

Rev 6231 Rev 6232
Line 120... Line 120...
120
	// we are a subclass of RTextView which has its own awake and we must call it
120
	// we are a subclass of RTextView which has its own awake and we must call it
121
	[super awakeFromNib];
121
	[super awakeFromNib];
122
 
122
 
123
	SLog(@"RScriptEditorTextView: awakeFromNib <%@>", self);
123
	SLog(@"RScriptEditorTextView: awakeFromNib <%@>", self);
124
 
124
 
-
 
125
	breakSyntaxHighlighting = 0;
-
 
126
 
125
	// Bind scrollView programmatically - if done in RDocument.xib this'd lead to
127
	// Bind scrollView programmatically - if done in RDocument.xib this'd lead to
126
	// calling awakeFromNib twice
128
	// calling awakeFromNib twice
127
	id scrView = (NSScrollView *)self.superview.superview;
129
	id scrView = (NSScrollView *)self.superview.superview;
128
	if ([scrView isKindOfClass:[NSScrollView class]]) {
130
	if ([scrView isKindOfClass:[NSScrollView class]]) {
129
		if(scrollView) [scrollView release];
131
		if(scrollView) [scrollView release];
Line 134... Line 136...
134
	prefs = [[NSUserDefaults standardUserDefaults] retain];
136
	prefs = [[NSUserDefaults standardUserDefaults] retain];
135
	[[Preferences sharedPreferences] addDependent:self];
137
	[[Preferences sharedPreferences] addDependent:self];
136
 
138
 
137
	lineNumberingEnabled = [Preferences flagForKey:showLineNumbersKey withDefault:NO];
139
	lineNumberingEnabled = [Preferences flagForKey:showLineNumbersKey withDefault:NO];
138
 
140
 
139
	// <TODO> enable for folding
-
 
140
	// theTextStorage = [[RScriptEditorTextStorage alloc] init];
141
	theTextStorage = [[RScriptEditorTextStorage alloc] init];
141
	theTextStorage = [self textStorage];
-
 
142
 
142
 
143
	// Set self as delegate for the textView's textStorage to enable syntax highlighting,
143
	// Set self as delegate for the textView's textStorage to enable syntax highlighting,
144
	[theTextStorage setDelegate:self];
144
	[theTextStorage setDelegate:self];
145
 
145
 
146
	// <TODO> enable for folding
146
	// <TODO> enable for folding
Line 352... Line 352...
352
 
352
 
353
	[super dealloc];
353
	[super dealloc];
354
 
354
 
355
}
355
}
356
 
356
 
-
 
357
- (void)setNonSyntaxHighlighting
-
 
358
{
-
 
359
	[theTextStorage removeAttribute:NSForegroundColorAttributeName range:NSMakeRange(0, [[theTextStorage string] length])];
-
 
360
	[theTextStorage removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0, [[theTextStorage string] length])];
-
 
361
	[self setTextColor:[NSColor blackColor]];
-
 
362
	[self setInsertionPointColor:[NSColor blackColor]];
-
 
363
	[self setNeedsDisplayInRect:[self bounds]];
-
 
364
}
-
 
365
 
357
/**
366
/**
358
 * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
367
 * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
359
 */
368
 */
360
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
369
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
361
{
370
{
Line 437... Line 446...
437
		[self setNeedsDisplayInRect:[self bounds]];
446
		[self setNeedsDisplayInRect:[self bounds]];
438
 
447
 
439
	} else if ([keyPath isEqualToString:showSyntaxColoringKey]) {
448
	} else if ([keyPath isEqualToString:showSyntaxColoringKey]) {
440
		syntaxHighlightingEnabled = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
449
		syntaxHighlightingEnabled = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
441
		if(syntaxHighlightingEnabled) {
450
		if(syntaxHighlightingEnabled) {
442
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.1];
451
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05f];
443
		} else {
452
		} else {
444
			[theTextStorage removeAttribute:NSForegroundColorAttributeName range:NSMakeRange(0, [[theTextStorage string] length])];
453
			[self performSelector:@selector(setNonSyntaxHighlighting) withObject:nil afterDelay:0.05f];
445
			[self setNeedsDisplayInRect:[self bounds]];
-
 
446
		}
454
		}
447
 
-
 
448
	} else if ([keyPath isEqualToString:enableLineWrappingKey]) {
455
	} else if ([keyPath isEqualToString:enableLineWrappingKey]) {
449
		[self updateLineWrappingMode];
456
		[self updateLineWrappingMode];
450
		[self setNeedsDisplayInRect:[self bounds]];
457
		[self setNeedsDisplayInRect:[self bounds]];
451
 
458
 
452
	} else if ([keyPath isEqualToString:showLineNumbersKey]) {
459
	} else if ([keyPath isEqualToString:showLineNumbersKey]) {
Line 559... Line 566...
559
	SLog(@"RScriptEditorTextView: textStorageDidProcessEditing <%@> with mask %d", self, editedMask);
566
	SLog(@"RScriptEditorTextView: textStorageDidProcessEditing <%@> with mask %d", self, editedMask);
560
 
567
 
561
	// if the user really changed the text
568
	// if the user really changed the text
562
	if(editedMask != 1) {
569
	if(editedMask != 1) {
563
 
570
 
-
 
571
		// For larger text break a running syntax highlighting for user interaction
-
 
572
		// to make them more responsive (typing and scrolling)
-
 
573
		if([[theTextStorage string] length] > 120000) {
-
 
574
			breakSyntaxHighlighting = 1;
-
 
575
		}
-
 
576
 
564
		[self checkSnippets];
577
		[self checkSnippets];
565
 
578
 
566
		// Cancel calling doSyntaxHighlighting
579
		// Cancel calling doSyntaxHighlighting
567
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
580
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
568
								selector:@selector(doSyntaxHighlighting) 
581
								selector:@selector(doSyntaxHighlighting) 
Line 760... Line 773...
760
				tokenRange = NSIntersectionRange(tokenRange, textRange);
773
				tokenRange = NSIntersectionRange(tokenRange, textRange);
761
				if (!tokenRange.length) continue;
774
				if (!tokenRange.length) continue;
762
 
775
 
763
				NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
776
				NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
764
 
777
 
-
 
778
				if(breakSyntaxHighlighting) {
-
 
779
 
-
 
780
					// Cancel calling doSyntaxHighlighting
-
 
781
					[NSObject cancelPreviousPerformRequestsWithTarget:self 
-
 
782
											selector:@selector(doSyntaxHighlighting) 
-
 
783
											object:nil];
-
 
784
 
-
 
785
					[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.15f];
-
 
786
 
-
 
787
					breakSyntaxHighlighting = 0;
-
 
788
					break;
-
 
789
 
-
 
790
				}
-
 
791
 
765
			}
792
			}
766
 
793
 
767
	} else {
794
	} else {
768
 
795
 
769
		yy_switch_to_buffer(yy_scan_string(NSStringUTF8String([selfstr substringWithRange:textRange])));
796
		yy_switch_to_buffer(yy_scan_string(NSStringUTF8String([selfstr substringWithRange:textRange])));
Line 801... Line 828...
801
			// NOTE Disabled for testing purposes for speed it up
828
			// NOTE Disabled for testing purposes for speed it up
802
			tokenRange = NSIntersectionRange(tokenRange, textRange);
829
			tokenRange = NSIntersectionRange(tokenRange, textRange);
803
			if (!tokenRange.length) continue;
830
			if (!tokenRange.length) continue;
804
 
831
 
805
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
832
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
-
 
833
 
-
 
834
			if(breakSyntaxHighlighting) {
-
 
835
 
-
 
836
				// Cancel calling doSyntaxHighlighting
-
 
837
				[NSObject cancelPreviousPerformRequestsWithTarget:self 
-
 
838
										selector:@selector(doSyntaxHighlighting) 
-
 
839
										object:nil];
-
 
840
 
-
 
841
				[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.15f];
-
 
842
 
-
 
843
				breakSyntaxHighlighting = 0;
-
 
844
				break;
-
 
845
 
806
		
846
			}
-
 
847
 
807
		}
848
		}
808
	}
849
	}
809
 
850
 
810
	// set current textColor to the color of the caret's position - 1
851
	// set current textColor to the color of the caret's position - 1
811
	// to try to suppress writing in normalColor before syntax highlighting 
852
	// to try to suppress writing in normalColor before syntax highlighting 
Line 877... Line 918...
877
	[self resetHighlights];
918
	[self resetHighlights];
878
}
919
}
879
 
920
 
880
/**
921
/**
881
 * Scrollview delegate after the textView's view port was changed.
922
 * Scrollview delegate after the textView's view port was changed.
882
 * Manily used to update the syntax highlighting for a large text size, line numbering rendering, and
923
 * Manily used to update the syntax highlighting for a large text size
883
 * status line size checking
-
 
884
 */
924
 */
885
- (void)boundsDidChangeNotification:(NSNotification *)notification
925
- (void)boundsDidChangeNotification:(NSNotification *)notification
886
{
926
{
887
 
927
 
888
	if(startListeningToBoundChanges) {
928
	if(startListeningToBoundChanges) {
Line 890... Line 930...
890
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
930
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
891
									selector:@selector(doSyntaxHighlighting) 
931
									selector:@selector(doSyntaxHighlighting) 
892
									object:nil];
932
									object:nil];
893
 
933
 
894
		if(![theTextStorage changeInLength]) {
934
		if(![theTextStorage changeInLength]) {
-
 
935
			if([[theTextStorage string] length] > 120000)
-
 
936
				breakSyntaxHighlighting = 2;
895
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05];
937
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05];
896
		}
938
		}
897
 
939
 
898
	}
940
	}
899
 
941
 
900
}
942
}
901
 
943
 
902
#pragma mark -
944
#pragma mark -
903
#pragma mark folding
945
#pragma mark Folding
904
 
946
 
905
- (void)foldSelectedLines:(id)sender
947
- (void)foldSelectedLines:(id)sender
906
{
948
{
907
 
949
 
908
	NSRange r = [self selectedRange];
950
	NSRange r = [self selectedRange];