The R Project SVN R-packages

Rev

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

Rev 6238 Rev 6240
Line 355... Line 355...
355
 
355
 
356
	[super dealloc];
356
	[super dealloc];
357
 
357
 
358
}
358
}
359
 
359
 
-
 
360
- (id)scrollView
-
 
361
{
-
 
362
	return scrollView;
-
 
363
}
-
 
364
 
360
- (void)setNonSyntaxHighlighting
365
- (void)setNonSyntaxHighlighting
361
{
366
{
362
	[theTextStorage removeAttribute:NSForegroundColorAttributeName range:NSMakeRange(0, [[theTextStorage string] length])];
367
	[theTextStorage removeAttribute:NSForegroundColorAttributeName range:NSMakeRange(0, [[theTextStorage string] length])];
363
	[theTextStorage removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0, [[theTextStorage string] length])];
368
	[theTextStorage removeAttribute:NSBackgroundColorAttributeName range:NSMakeRange(0, [[theTextStorage string] length])];
364
	[self setTextColor:[NSColor blackColor]];
369
	[self setTextColor:[NSColor blackColor]];
365
	[self setInsertionPointColor:[NSColor blackColor]];
370
	[self setInsertionPointColor:[NSColor blackColor]];
366
	[self setNeedsDisplayInRect:[self bounds]];
371
	[self setNeedsDisplayInRect:[self visibleRect]];
367
}
372
}
368
 
373
 
369
/**
374
/**
370
 * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
375
 * This method is called as part of Key Value Observing which is used to watch for prefernce changes which effect the interface.
371
 */
376
 */
Line 424... Line 429...
424
	// 		[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.1];
429
	// 		[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.1];
425
	} else if ([keyPath isEqualToString:editorCursorColorKey]) {
430
	} else if ([keyPath isEqualToString:editorCursorColorKey]) {
426
		if(shColorCursor) [shColorCursor release];
431
		if(shColorCursor) [shColorCursor release];
427
		shColorCursor = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
432
		shColorCursor = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
428
		[self setInsertionPointColor:shColorCursor];
433
		[self setInsertionPointColor:shColorCursor];
429
		[self setNeedsDisplayInRect:[self bounds]];
434
		[self setNeedsDisplayInRect:[self visibleRect]];
430
	} else if ([keyPath isEqualToString:identifierSyntaxColorKey]) {
435
	} else if ([keyPath isEqualToString:identifierSyntaxColorKey]) {
431
		if(shColorIdentifier) [shColorIdentifier release];
436
		if(shColorIdentifier) [shColorIdentifier release];
432
		shColorIdentifier = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
437
		shColorIdentifier = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
433
		if([self isEditable])
438
		if([self isEditable])
434
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.1];
439
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.1];
435
	} else if ([keyPath isEqualToString:editorBackgroundColorKey]) {
440
	} else if ([keyPath isEqualToString:editorBackgroundColorKey]) {
436
		if(shColorBackground) [shColorBackground release];
441
		if(shColorBackground) [shColorBackground release];
437
		shColorBackground = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
442
		shColorBackground = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
438
		[self setNeedsDisplayInRect:[self bounds]];
443
		[self setNeedsDisplayInRect:[self visibleRect]];
439
	} else if ([keyPath isEqualToString:editorCurrentLineBackgroundColorKey]) {
444
	} else if ([keyPath isEqualToString:editorCurrentLineBackgroundColorKey]) {
440
		if(shColorCurrentLine) [shColorCurrentLine release];
445
		if(shColorCurrentLine) [shColorCurrentLine release];
441
		shColorCurrentLine = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
446
		shColorCurrentLine = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
442
		[self setNeedsDisplayInRect:[self bounds]];
447
		[self setNeedsDisplayInRect:[self visibleRect]];
443
	} else if ([keyPath isEqualToString:editorSelectionBackgroundColorKey]) {
448
	} else if ([keyPath isEqualToString:editorSelectionBackgroundColorKey]) {
444
		NSColor *c = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
449
		NSColor *c = [[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]] retain];
445
		NSMutableDictionary *attr = [NSMutableDictionary dictionary];
450
		NSMutableDictionary *attr = [NSMutableDictionary dictionary];
446
		[attr setDictionary:[self selectedTextAttributes]];
451
		[attr setDictionary:[self selectedTextAttributes]];
447
		[attr setObject:c forKey:NSBackgroundColorAttributeName];
452
		[attr setObject:c forKey:NSBackgroundColorAttributeName];
448
		[self setSelectedTextAttributes:attr];
453
		[self setSelectedTextAttributes:attr];
449
		[self setNeedsDisplayInRect:[self bounds]];
454
		[self setNeedsDisplayInRect:[self visibleRect]];
450
 
455
 
451
	} else if ([keyPath isEqualToString:showSyntaxColoringKey]) {
456
	} else if ([keyPath isEqualToString:showSyntaxColoringKey]) {
452
		syntaxHighlightingEnabled = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
457
		syntaxHighlightingEnabled = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
453
		if(syntaxHighlightingEnabled) {
458
		if(syntaxHighlightingEnabled) {
454
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05f];
459
			[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.05f];
Line 484... Line 489...
484
		} else {
489
		} else {
485
			[self currentFunctionHint];
490
			[self currentFunctionHint];
486
		}
491
		}
487
 
492
 
488
	} else if ([keyPath isEqualToString:highlightCurrentLine]) {
493
	} else if ([keyPath isEqualToString:highlightCurrentLine]) {
489
		[self setNeedsDisplayInRect:[self bounds]];
494
		[self setNeedsDisplayInRect:[self visibleRect]];
490
 
495
 
491
	} else if ([keyPath isEqualToString:RScriptEditorDefaultFont] && ![[[[self window] windowController] document] isRTF] && ![self selectedRange].length) {
496
	} else if ([keyPath isEqualToString:RScriptEditorDefaultFont] && ![[[[self window] windowController] document] isRTF] && ![self selectedRange].length) {
492
			[self setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
497
			[self setFont:[NSUnarchiver unarchiveObjectWithData:[change objectForKey:NSKeyValueChangeNewKey]]];
493
			[self setNeedsDisplayInRect:[self bounds]];
498
			[self setNeedsDisplayInRect:[self visibleRect]];
494
	
499
	
495
		} else if ([keyPath isEqualToString:HighlightIntervalKey]) {
500
		} else if ([keyPath isEqualToString:HighlightIntervalKey]) {
496
		braceHighlightInterval = [Preferences floatForKey:HighlightIntervalKey withDefault:0.3f];
501
		braceHighlightInterval = [Preferences floatForKey:HighlightIntervalKey withDefault:0.3f];
497
	}
502
	}
498
}
503
}
499
 
504
 
500
- (void)updateLineWrappingMode
505
- (void)updateLineWrappingMode
501
{
506
{
502
 
507
 
503
	lineWrappingEnabled = [Preferences flagForKey:enableLineWrappingKey withDefault: YES];
508
	lineWrappingEnabled = [Preferences flagForKey:enableLineWrappingKey withDefault: YES];
504
 
509
	
505
	NSSize contentSize = [scrollView contentSize];
510
	NSSize contentSize = [scrollView contentSize];
506
	NSTextContainer *textContainer = [self textContainer];
511
	NSTextContainer *textContainer = [self textContainer];
507
 
512
	
508
	// [self setMinSize:contentSize];
513
	// [self setMinSize:contentSize];
509
 
514
	
510
	if (lineWrappingEnabled) {
515
	if (lineWrappingEnabled) {
511
		[scrollView setHasHorizontalScroller:YES];
516
		[scrollView setHasHorizontalScroller:YES];
512
		[textContainer setContainerSize:NSMakeSize(contentSize.width, CGFLOAT_MAX)];
517
		[textContainer setContainerSize:NSMakeSize(contentSize.width, CGFLOAT_MAX)];
513
		[textContainer setWidthTracksTextView:YES];
518
		[textContainer setWidthTracksTextView:YES];
514
		[self setHorizontallyResizable:NO];
519
		[self setHorizontallyResizable:NO];
Line 518... Line 523...
518
		[textContainer setContainerSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)];
523
		[textContainer setContainerSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)];
519
		[textContainer setWidthTracksTextView:NO];
524
		[textContainer setWidthTracksTextView:NO];
520
		[self setHorizontallyResizable:YES];
525
		[self setHorizontallyResizable:YES];
521
		[(NoodleLineNumberView*)[[self enclosingScrollView] verticalRulerView] setLineWrappingMode:NO];
526
		[(NoodleLineNumberView*)[[self enclosingScrollView] verticalRulerView] setLineWrappingMode:NO];
522
	}
527
	}
523
 
528
	
524
	[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.0f];
529
	[[[self enclosingScrollView] verticalRulerView] performSelector:@selector(refresh) withObject:nil afterDelay:0.0f];
525
 
530
 
526
	// NSSize layoutSize;
531
	// NSSize layoutSize;
527
	// 
532
	// 
528
	// lineWrappingEnabled = [Preferences flagForKey:enableLineWrappingKey withDefault: YES];
533
	// lineWrappingEnabled = [Preferences flagForKey:enableLineWrappingKey withDefault: YES];
Line 714... Line 719...
714
 
719
 
715
	// == Do highlighting partly (max R_SYNTAX_HILITE_BIAS*2 around visibleRange
720
	// == Do highlighting partly (max R_SYNTAX_HILITE_BIAS*2 around visibleRange
716
	// by considering entire lines).
721
	// by considering entire lines).
717
 
722
 
718
	// Get the text range currently displayed in the view port
723
	// Get the text range currently displayed in the view port
719
	NSRect visibleRect = [scrollView documentVisibleRect];
724
	NSRect visibleRect = [self visibleRect];
720
	NSRange visibleRange = [[self layoutManager] glyphRangeForBoundingRectWithoutAdditionalLayout:visibleRect inTextContainer:[self textContainer]];
725
	NSRange visibleRange = [[self layoutManager] glyphRangeForBoundingRectWithoutAdditionalLayout:visibleRect inTextContainer:[self textContainer]];
721
 
726
 
722
	if(!visibleRange.length) {
727
	if(!visibleRange.length) {
723
		isSyntaxHighlighting = NO;
728
		isSyntaxHighlighting = NO;
724
		return;
729
		return;
Line 862... Line 867...
862
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
867
			NSMutableAttributedStringAddAttributeValueRange(theTextStorage, NSForegroundColorAttributeName, tokenColor, tokenRange);
863
 
868
 
864
			if(breakSyntaxHighlighting) {
869
			if(breakSyntaxHighlighting) {
865
 
870
 
866
				// Cancel calling doSyntaxHighlighting
871
				// Cancel calling doSyntaxHighlighting
867
				[NSObject cancelPreviousPerformRequestsWithTarget:self 
872
				// [NSObject cancelPreviousPerformRequestsWithTarget:self 
868
										selector:@selector(doSyntaxHighlighting) 
873
				// 						selector:@selector(doSyntaxHighlighting) 
869
										object:nil];
874
				// 						object:nil];
870
 
875
				// 
871
				[self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.15f];
876
				// [self performSelector:@selector(doSyntaxHighlighting) withObject:nil afterDelay:0.15f];
872
 
877
 
873
				breakSyntaxHighlighting = 0;
878
				breakSyntaxHighlighting = 0;
874
				break;
879
				break;
875
 
880
 
876
			}
881
			}
Line 890... Line 895...
890
		[self setTypingAttributes:typeAttr];
895
		[self setTypingAttributes:typeAttr];
891
	}
896
	}
892
 
897
 
893
	[theTextStorage endEditing];
898
	[theTextStorage endEditing];
894
	isSyntaxHighlighting = NO;
899
	isSyntaxHighlighting = NO;
895
 
-
 
896
	[self setNeedsDisplayInRect:[self bounds]];
900
	[self setNeedsDisplayInRect:visibleRect];
897
 
901
 
898
}
902
}
899
 
903
 
900
-(void)resetHighlights
904
-(void)resetHighlights
901
{
905
{