Permalink
Browse files

WIP on extracting the actual syntax coloring from the document into a…

… view controller class.
  • Loading branch information...
1 parent c4b98c0 commit f397d2b03f9b75c89b22852681b1fbe3c29bb0ed @uliwitness committed Mar 13, 2010
@@ -28,6 +28,8 @@
3DFECEC706558AD20059B4E8 /* InsertionMark.tiff in Resources */ = {isa = PBXBuildFile; fileRef = 3DFECEC506558AD20059B4E8 /* InsertionMark.tiff */; };
3DFECED2065592BE0059B4E8 /* UKSCTDUserIdentifiersPrefsController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3DFECED0065592BE0059B4E8 /* UKSCTDUserIdentifiersPrefsController.h */; };
3DFECED3065592BE0059B4E8 /* UKSCTDUserIdentifiersPrefsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DFECED1065592BE0059B4E8 /* UKSCTDUserIdentifiersPrefsController.m */; };
+ 55255A4B114C077D00279B03 /* UKSyntaxColoredTextViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 55255A49114C077D00279B03 /* UKSyntaxColoredTextViewController.h */; };
+ 55255A4C114C077D00279B03 /* UKSyntaxColoredTextViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 55255A4A114C077D00279B03 /* UKSyntaxColoredTextViewController.m */; };
55D9D77C112DDF18001ADF29 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55D9D77A112DDF18001ADF29 /* MainMenu.xib */; };
55D9D780112DDF34001ADF29 /* UKSyntaxColoredTextDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55D9D77E112DDF34001ADF29 /* UKSyntaxColoredTextDocument.xib */; };
55D9D784112DDF44001ADF29 /* UKMultiSyntaxColoredTextDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55D9D782112DDF44001ADF29 /* UKMultiSyntaxColoredTextDocument.xib */; };
@@ -70,6 +72,8 @@
3DFECEC506558AD20059B4E8 /* InsertionMark.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = InsertionMark.tiff; sourceTree = "<group>"; };
3DFECED0065592BE0059B4E8 /* UKSCTDUserIdentifiersPrefsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UKSCTDUserIdentifiersPrefsController.h; sourceTree = "<group>"; };
3DFECED1065592BE0059B4E8 /* UKSCTDUserIdentifiersPrefsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UKSCTDUserIdentifiersPrefsController.m; sourceTree = "<group>"; };
+ 55255A49114C077D00279B03 /* UKSyntaxColoredTextViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UKSyntaxColoredTextViewController.h; sourceTree = "<group>"; };
+ 55255A4A114C077D00279B03 /* UKSyntaxColoredTextViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UKSyntaxColoredTextViewController.m; sourceTree = "<group>"; };
55D9D77B112DDF18001ADF29 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/MainMenu.xib; sourceTree = "<group>"; };
55D9D77F112DDF34001ADF29 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/UKSyntaxColoredTextDocument.xib; sourceTree = "<group>"; };
55D9D783112DDF44001ADF29 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/UKMultiSyntaxColoredTextDocument.xib; sourceTree = "<group>"; };
@@ -132,6 +136,8 @@
2A37F4ABFDCFA73011CA2CEA /* Classes */ = {
isa = PBXGroup;
children = (
+ 55255A49114C077D00279B03 /* UKSyntaxColoredTextViewController.h */,
+ 55255A4A114C077D00279B03 /* UKSyntaxColoredTextViewController.m */,
3D5D9F3608873A3600058C2B /* UKSyntaxColoredTextDocument.h */,
3D5D9F3708873A3600058C2B /* UKSyntaxColoredTextDocument.m */,
3D70D4BB06594E70006EC8D8 /* UKMultiSyntaxColoredTextDocument.h */,
@@ -223,6 +229,7 @@
3D5D9F3808873A3600058C2B /* UKSyntaxColoredTextDocument.h in Headers */,
3D5D9F3C08873A4B00058C2B /* NSArray+Color.h in Headers */,
55F40EF71143C4E500B2BC40 /* UKSCTDGradientBar.h in Headers */,
+ 55255A4B114C077D00279B03 /* UKSyntaxColoredTextViewController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -300,6 +307,7 @@
3D5D9F3908873A3600058C2B /* UKSyntaxColoredTextDocument.m in Sources */,
3D5D9F3D08873A4B00058C2B /* NSArray+Color.m in Sources */,
55F40EF81143C4E500B2BC40 /* UKSCTDGradientBar.m in Sources */,
+ 55255A4C114C077D00279B03 /* UKSyntaxColoredTextViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,116 @@
+//
+// 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>
+
+-(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;
+
+@end
+
+
+
+// -----------------------------------------------------------------------------
+// Class:
+// -----------------------------------------------------------------------------
+
+@interface UKSyntaxColoredTextViewController : NSViewController
+{
+ 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.
+
+-(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
Oops, something went wrong.

0 comments on commit f397d2b

Please sign in to comment.