Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 123 lines (95 sloc) 5.765 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
//
// UKSyntaxColoredTextViewController.h
// UKSyntaxColoredDocument
//
// Created by Uli Kusterer on 13.03.10.
// Copyright 2010 Uli Kusterer.
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//

// -----------------------------------------------------------------------------
// Headers:
// -----------------------------------------------------------------------------

#import <Cocoa/Cocoa.h>


// -----------------------------------------------------------------------------
// Constants:
// -----------------------------------------------------------------------------

#define TD_USER_DEFINED_IDENTIFIERS @"SyntaxColoring:UserIdentifiers" // Key in user defaults holding user-defined identifiers to colorize.
#define TD_SYNTAX_COLORING_MODE_ATTR @"UKTextDocumentSyntaxColoringMode" // Anything we colorize gets this attribute.


@class UKSyntaxColoredTextViewController;

@protocol UKSyntaxColoredTextViewDelegate <NSObject>

@optional
-(void) textViewControllerWillStartSyntaxRecoloring: (UKSyntaxColoredTextViewController*)sender; // Show your progress indicator.
-(void) textViewControllerProgressedWhileSyntaxRecoloring: (UKSyntaxColoredTextViewController*)sender; // Make sure it gets redrawn.
-(void) textViewControllerDidFinishSyntaxRecoloring: (UKSyntaxColoredTextViewController*)sender; // Hide your progress indicator.

-(void) selectionInTextViewController: (UKSyntaxColoredTextViewController*)sender // Update any selection status display.
              changedToStartCharacter: (NSUInteger)startCharInLine endCharacter: (NSUInteger)endCharInLine
                               inLine: (NSUInteger)lineInDoc startCharacterInDocument: (NSUInteger)startCharInDoc
               endCharacterInDocument: (NSUInteger)endCharInDoc;

-(NSString*) syntaxDefinitionFilenameForTextViewController: (UKSyntaxColoredTextViewController*)sender;
-(NSDictionary*) syntaxDefinitionDictionaryForTextViewController: (UKSyntaxColoredTextViewController*)sender;

@end



// -----------------------------------------------------------------------------
// Class:
// -----------------------------------------------------------------------------

@interface UKSyntaxColoredTextViewController : NSViewController <NSTextViewDelegate>
{
BOOL autoSyntaxColoring; // Automatically refresh syntax coloring when text is changed?
BOOL maintainIndentation; // Keep new lines indented at same depth as their predecessor?
NSTimer* recolorTimer; // Timer used to do the actual recoloring a little while after the last keypress.
BOOL syntaxColoringBusy; // Set while recolorRange is busy, so we don't recursively call recolorRange.
NSRange affectedCharRange;
NSString* replacementString;
id<UKSyntaxColoredTextViewDelegate> delegate;
}

+(void) makeSurePrefsAreInited; // No need to call this.

-(void) setDelegate: (id<UKSyntaxColoredTextViewDelegate>)delegate;
-(id) delegate;

-(IBAction) recolorCompleteFile: (id)sender;
-(IBAction) toggleAutoSyntaxColoring: (id)sender;
-(IBAction) toggleMaintainIndentation: (id)sender;
-(IBAction) indentSelection: (id)sender;
-(IBAction) unindentSelection: (id)sender;
-(IBAction) toggleCommentForSelection: (id)sender;

-(void) setAutoSyntaxColoring: (BOOL)state;
-(BOOL) autoSyntaxColoring;

-(void) setMaintainIndentation: (BOOL)state;
-(BOOL) maintainIndentation;

-(void) goToLine: (int)lineNum;
-(void) goToCharacter: (int)charNum;
-(void) goToRangeFrom: (int)startCh toChar: (int)endCh;

// Override any of the following in one of your subclasses to customize this object further:
-(NSString*) syntaxDefinitionFilename; // Defaults to "SyntaxDefinition.plist" in the app bundle's "Resources" directory.
-(NSDictionary*) syntaxDefinitionDictionary; // Defaults to loading from -syntaxDefinitionFilename.

-(NSDictionary*) defaultTextAttributes; // Style attributes dictionary for an NSAttributedString.

// Private:
-(void) turnOffWrapping;

-(void) recolorRange: (NSRange) range;

-(void) colorOneLineComment: (NSString*) startCh inString: (NSMutableAttributedString*) s
                  withColor: (NSColor*) col andMode:(NSString*)attr;
-(void) colorCommentsFrom: (NSString*) startCh to: (NSString*) endCh inString: (NSMutableAttributedString*) s
withColor: (NSColor*) col andMode:(NSString*)attr;
-(void) colorIdentifier: (NSString*) ident inString: (NSMutableAttributedString*) s
              withColor: (NSColor*) col andMode:(NSString*)attr charset: (NSCharacterSet*)cset;
-(void) colorStringsFrom: (NSString*) startCh to: (NSString*) endCh inString: (NSMutableAttributedString*) s
               withColor: (NSColor*) col andMode:(NSString*)attr andEscapeChar: (NSString*)vStringEscapeCharacter;
-(void) colorTagFrom: (NSString*) startCh to: (NSString*)endCh inString: (NSMutableAttributedString*) s
           withColor: (NSColor*) col andMode:(NSString*)attr exceptIfMode: (NSString*)ignoreAttr;

@end
Something went wrong with that request. Please try again.