The R Project SVN R-packages

Rev

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

Rev 5724 Rev 5741
Line 218... Line 218...
218
	if (c) shColorCursor = c;
218
	if (c) shColorCursor = c;
219
	else shColorCursor=[NSColor blackColor];
219
	else shColorCursor=[NSColor blackColor];
220
	[shColorCursor retain]; 
220
	[shColorCursor retain]; 
221
	[self setInsertionPointColor:shColorCursor];
221
	[self setInsertionPointColor:shColorCursor];
222
 
222
 
223
 
-
 
224
	// Register observers for the when editor background colors preference changes
223
	// Register observers for the when editor background colors preference changes
225
	[prefs addObserver:self forKeyPath:normalSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
224
	[prefs addObserver:self forKeyPath:normalSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
226
	[prefs addObserver:self forKeyPath:stringSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
225
	[prefs addObserver:self forKeyPath:stringSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
227
	[prefs addObserver:self forKeyPath:numberSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
226
	[prefs addObserver:self forKeyPath:numberSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
228
	[prefs addObserver:self forKeyPath:keywordSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
227
	[prefs addObserver:self forKeyPath:keywordSyntaxColorKey options:NSKeyValueObservingOptionNew context:NULL];
Line 363... Line 362...
363
		}
362
		}
364
 
363
 
365
	} else if ([keyPath isEqualToString:highlightCurrentLine]) {
364
	} else if ([keyPath isEqualToString:highlightCurrentLine]) {
366
		[self setNeedsDisplay:YES];
365
		[self setNeedsDisplay:YES];
367
 
366
 
368
	} else if ([keyPath isEqualToString:RScriptEditorDefaultFont]) {
367
	} else if ([keyPath isEqualToString:RScriptEditorDefaultFont] && ![[[[self window] windowController] document] isRTF] && ![self selectedRange].length) {
369
		[self setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
368
			[self setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
370
		[self setNeedsDisplay:YES];
369
			[self setNeedsDisplay:YES];
371
 
370
	
372
	} else if ([keyPath isEqualToString:HighlightIntervalKey]) {
371
		} else if ([keyPath isEqualToString:HighlightIntervalKey]) {
373
		braceHighlightInterval = [Preferences floatForKey:HighlightIntervalKey withDefault:0.3f];
372
		braceHighlightInterval = [Preferences floatForKey:HighlightIntervalKey withDefault:0.3f];
374
	}
373
	}
375
}
374
}
376
 
375
 
377
- (void)drawRect:(NSRect)rect
376
- (void)drawRect:(NSRect)rect
Line 416... Line 415...
416
	SLog(@"RScriptEditorTextView: textStorageDidProcessEditing <%@> with mask %d", self, editedMask);
415
	SLog(@"RScriptEditorTextView: textStorageDidProcessEditing <%@> with mask %d", self, editedMask);
417
 
416
 
418
	// if the user really changed the text
417
	// if the user really changed the text
419
	if(editedMask != 1) {
418
	if(editedMask != 1) {
420
 
419
 
421
		// Cancel setting undo break point
420
		// Cancel calling doSyntaxHighlighting
422
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
421
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
423
								selector:@selector(breakUndoCoalescing) 
422
								selector:@selector(doSyntaxHighlighting) 
424
								object:nil];
423
								object:nil];
425
 
424
 
-
 
425
		[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.0f];
-
 
426
 
426
		// Cancel calling doSyntaxHighlighting
427
		// Cancel setting undo break point
427
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
428
		[NSObject cancelPreviousPerformRequestsWithTarget:self 
428
								selector:@selector(doSyntaxHighlighting) 
429
								selector:@selector(breakUndoCoalescing) 
429
								object:nil];
430
								object:nil];
430
 
431
 
431
		// Cancel calling doSyntaxHighlighting
432
		// Cancel calling doSyntaxHighlighting
432
		[NSObject cancelPreviousPerformRequestsWithTarget:[self delegate] 
433
		[NSObject cancelPreviousPerformRequestsWithTarget:[self delegate] 
433
								selector:@selector(functionRescan) 
434
								selector:@selector(functionRescan) 
434
								object:nil];
435
								object:nil];
435
 
436
 
436
		[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.0];
-
 
437
 
-
 
438
		// Improve undo behaviour, i.e. it depends how fast the user types
437
		// Improve undo behaviour, i.e. it depends how fast the user types
439
		[self performSelector:@selector(breakUndoCoalescing) withObject:nil afterDelay:0.8];
438
		[self performSelector:@selector(breakUndoCoalescing) withObject:nil afterDelay:0.8];
440
 
439
 
441
		[[self delegate] performSelector:@selector(functionRescan) withObject:nil afterDelay:0.05];
440
		[[self delegate] performSelector:@selector(functionRescan) withObject:nil afterDelay:0.05];
442
 
441
 
Line 595... Line 594...
595
	if (!textRange.length)
594
	if (!textRange.length)
596
		return;
595
		return;
597
 
596
 
598
	[theTextStorage beginEditing];
597
	[theTextStorage beginEditing];
599
 
598
 
600
	NSColor *tokenColor;
599
	NSColor *tokenColor = nil;
601
 
600
 
602
	size_t tokenEnd, token;
601
	size_t tokenEnd, token;
603
	NSRange tokenRange;
602
	NSRange tokenRange;
604
 
603
 
605
	// first remove the old colors and kQuote
604
	// first remove the old colors and kQuote
Line 668... Line 667...
668
		else if(token < 4)
667
		else if(token < 4)
669
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, kQuote, kQuoteValue, tokenRange);
668
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, kQuote, kQuoteValue, tokenRange);
670
		
669
		
671
 
670
 
672
	}
671
	}
-
 
672
 
-
 
673
	// set current textColor to the color of the caret's position - 1
-
 
674
	// to try to suppress writing in normalColor before syntax highlighting 
-
 
675
	NSUInteger ix = [self selectedRange].location;
-
 
676
	if(ix > 1) {
-
 
677
		NSMutableDictionary *typeAttr = [NSMutableDictionary dictionary];
-
 
678
		[typeAttr setDictionary:[self typingAttributes]];
-
 
679
		NSColor *c = [theTextStorage attribute:NSForegroundColorAttributeName atIndex:ix-1 effectiveRange:nil];
-
 
680
		if(c) [typeAttr setObject:c forKey:NSForegroundColorAttributeName];
-
 
681
		[self setTypingAttributes:typeAttr];
-
 
682
	}
-
 
683
 
673
	[theTextStorage endEditing];
684
	[theTextStorage endEditing];
674
 
685
 
675
}
686
}
676
 
687
 
677
-(void)resetHighlights
688
-(void)resetHighlights
Line 738... Line 749...
738
 
749
 
739
}
750
}
740
 
751
 
741
#pragma mark -
752
#pragma mark -
742
 
753
 
-
 
754
- (void)changeFont:(id)sender
-
 
755
{
-
 
756
 
-
 
757
	NSFont *font;
-
 
758
	font = [[NSFontPanel sharedFontPanel] panelConvertFont:[NSUnarchiver unarchiveObjectWithData:[prefs dataForKey:RScriptEditorDefaultFont]]];
-
 
759
 
-
 
760
	if([[[[self window] windowController] document] isRTF] || [self selectedRange].length) {
-
 
761
		// register font change for undo
-
 
762
		[self shouldChangeTextInRange:[self selectedRange] replacementString:[[self string] substringWithRange:[self selectedRange]]];
-
 
763
		[theTextStorage addAttribute:NSFontAttributeName value:font range:[self selectedRange]];
-
 
764
	} else {
-
 
765
		[prefs setObject:[NSArchiver archivedDataWithRootObject:font] forKey:RScriptEditorDefaultFont];
-
 
766
	}
-
 
767
 
-
 
768
}
-
 
769
 
-
 
770
 
743
- (void)updatePreferences
771
- (void)updatePreferences
744
{
772
{
745
	
773
	
746
}
774
}
747
@end
775
@end