File: programming/cocoa/UKSyntaxColoredTextDocument.zip/UKSyntaxColoredTextDocument/UKMultiSyntaxColoredTextDocument.m


//
//  UKMultiSyntaxColoredTextDocument.m
//  UKSyntaxColoredDocument
//
//  Created by Uli Kusterer on Mon May 17 2004.
//  Copyright (c) 2004 M. Uli Kusterer. All rights reserved.
//
 
// -----------------------------------------------------------------------------
//  Headers:
// -----------------------------------------------------------------------------
 
#import "UKMultiSyntaxColoredTextDocument.h"
#import "NSMenu+DeepSearch.h"
 
 
// -----------------------------------------------------------------------------
//  Globals:
// -----------------------------------------------------------------------------
// Array of syntax definition file paths in NSStrings.
"UKMultiSyntaxColoredTextDocumentSyntaxDefinitionChanged"// -----------------------------------------------------------------------------
//	syntaxDefinitionFiles:
//		Return and, if needed, lazily allocate the array of available syntax
//		definition files. This also updates the syntax definition menu by
//		writing the file names without suffixes of the syntax definition files
//		into the menu as menu items, whose tags are the indices into the array
//		corresponding to them.
//
//	REVISIONS:
//		2004-05-18	witness	Documented.
//		2004-05-17	witness	Created.
// -----------------------------------------------------------------------------
// Load from User's Application support:
"%@/Library/Application Support/%@/Syntax Definitions/"// Load from global application support:
"/Library/Application Support/%@/Syntax Definitions/"// Load from folder in app bundle:
"Syntax Definitions" ofType: @""// Now make the menu match:
// -----------------------------------------------------------------------------
//	rebuildSyntaxMenu:
//		Remove the old items from the syntax definition menu and add new menu
//		items for them based on the syntax definition files array.
//
//	REVISIONS:
//		2004-05-18	witness	Extracted from syntaxDefinitionFiles.
// -----------------------------------------------------------------------------
// Find menu with menu items for syntax definitions:
// If we have a menu in our outlet, use that instead:
	{
		syntaxMenu = syntaxDefinitionMenu;
		foundItem = [syntaxDefinitionMenu itemAtIndex: 0];  // Assume we own the popup.
	}
	
	// Remove all old menu items from our menu:
/* Warning! This croaks if the code below doesn't find any syntax
			definition files, because then all menu items have been removed
			and it won't find the menu the next time! */""];
		[currItem setTag: x++]; // Remember array index of this one.
"FileNameSuffixes"// -----------------------------------------------------------------------------
//	addSyntaxFilesFromFolder:
//		Scan the specified folder for files and add all files (except the ones
//		starting with a period) to our array of syntax definition file paths,
//		as well as adding menu items for them.
//
//		This appends to the array, so can be called several times in a row to
//		scan several folders.
//
//	REVISIONS:
//		2004-05-18	witness	Documented.
//		2004-05-17	witness	Created.
// -----------------------------------------------------------------------------
'.'// -----------------------------------------------------------------------------
//	reloadSyntaxDefinitionFiles:
//		Kill and recreate the list of syntax definition files.
//
//	REVISIONS:
//		2004-05-18	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	* CONSTRUCTOR:
//		Lazily instantiate our array of syntax definition file paths and also
//		init the syntax coloring scheme to use to the first item from that list.
//
//	REVISIONS:
//		2004-05-18	witness	Documented.
//		2004-05-17	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	* DESTRUCTOR:
//
//	REVISIONS:
//		2004-05-18	witness	Documented.
//		2004-05-17	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	windowControllerDidLoadNib:
//		If we're using a popup, reload the syntax definition list now that the
//		NIB's been loaded and in the process populate the menu.
//
//	REVISIONS:
//		2004-05-18	witness	Created.
// -----------------------------------------------------------------------------
// Connected to a popup in our NIB?
// -----------------------------------------------------------------------------
//	syntaxDefinitionDictionary:
//		Return the syntax definition dictionary to use for colorizing. This
//		overrides a method in UKSyntaxColoredTextDocument since UKSCTD only
//		looks for its files in the application bundle.
//
//	REVISIONS:
//		2004-05-18	witness	Documented.
//		2004-05-17	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	syntaxDefinitionFilename:
//		Return the full pathname of the syntax definition file to use for
//		syntax coloring.
//
//	REVISIONS:
//		2004-05-18	witness	Documented.
//		2004-05-17	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	setSyntaxDefinitionFilename:
//		Select a different syntax definition file name to be used for coloring.
//		This also causes a recoloring of the text using the new coloring scheme.
//
//	REVISIONS:
//		2004-05-18	witness	Documented.
//		2004-05-17	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	takeSyntaxDefinitionFilenameFromTagOf:
//		Menu action for our menu items that allow changing the syntax definition
//		to use.
//
//	REVISIONS:
//		2004-05-18	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	validateMenuItem:
//		Make sure the menu item for the syntax coloring scheme this file uses
//		is selectable and checked.
//
//	REVISIONS:
//		2004-05-18	witness	Created.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//	windowNibName:
//		By default, UKMultiSyntaxColoredTextDocument uses a different NIB which
//		includes a popup menu in the status bar. If you want the menu in the
//		main menu bar instead, just subclass this and override this method to
//		return [super windowNibName], which gets you the regular NIB from the
//		superclass without the popup, and it'll cause the code in here to look
//		for its menu in the menu bar because the syntaxDefinitionMenu outlet
//		won't be set. Of course you can also return any other NIB you create
//		here, though then it'll be your duty to keep it in sync with the
//		"official" ones from me.
//
//	REVISIONS:
//		2004-05-18	witness	Created.
// -----------------------------------------------------------------------------
"UKMultiSyntaxColoredTextDocument"

This code uses the PclZip Zip File reading code, which is subject to the GNU LGPL. It also uses the GeSHi syntax highlighter, subject to the GPL. Ask if you want this for your own web site, it's free.