TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | BSD |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
Fragaria is an OS X Cocoa syntax colouring NSTextView implemented within a framework named MGSFragaria. It supports a wide range of programming languages and includes preference panel support.
The MGSFragaria framework now properly supports both traditional reference counting memory management and garbage collection.
You can see Fragaria used in the following projects and products:
Appium Recorder : Appium is an open source, cross-platform test automation tool for native and hybrid mobile apps. (repo).
cocoa-rest-client A native OS X cocoa application for testing HTTP endpoints.
CocosBuilder. CocosBuilder is a free tool (released under MIT-licence) for rapidly developing games and apps. (repo)
Cocoduino is an IDE for the Arduino platform written in native Cocoa.
KosmicTask is a multi (20+) language scripting environment for OS X that features script editing, network sharing, remote execution, and file processing.
nib2objc This utility converts NIB files (or XIB ones) into Objective-C code
If you use Fragaria in your app and want it added to the list just let us know or edit the README.
Most features are accessed via the framework preferences.
The best way to learn how to use the framework is to look at the sample apps.
Fragaria : a simple editor window that features language selection, a wired up text menu and a preferences panel.
Fragaria GC : a GC version of the above.
Fragaria Doc : a simple NSDocument based editor.
A Fragaria view is embedded in a content view.
#import "MGSFragaria/MGSFragaria.h"
// we need a container view to host Fragaria in
NSView *containerView = nil; // loaded from nib or otherwise created
// create our instance
MGSFragaria *fragaria = [[MGSFragaria alloc] init];
// we want to be the delegate
[fragaria setObject:self forKey:MGSFODelegate];
// Objective-C is the place to be
[self setSyntaxDefinition:@"Objective-C"];
// embed in our container - exception thrown if containerView is nil
[fragaria embedInView:containerView];
// set initial text
[fragaria setString:@"// We don't need the future."];
The initial appearance of a Fragaria view is determined by the framework preferences controller. The MGSFragaria framework supplies two preference view controllers whose views can be embedded in your preference panel.
MGSFragariaTextEditingPrefsViewController * textEditingPrefsViewController = [MGSFragariaPreferences sharedInstance].textEditingPrefsViewController;
MGSFragariaFontsAndColoursPrefsViewController *fontsAndColoursPrefsViewController = [MGSFragariaPreferences sharedInstance].fontsAndColoursPrefsViewController;
Preference strings are defined in MGSFragaria/MGSFragariaPreferences.h. Each preference name is prefixed with Fragaria for easy identification within the application preferences file.
// default to line wrap off
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsLineWrapNewDocuments];
All preferences are observed and instances of Fragaria views update immediately to reflect the new preference.
Use the MGSFOBreakpointDelegate
key to define a breakpoint delegate that responds to conforms to MGSBreakpointDelegate
[fragaria setObject:self forKey:MGSFODelegate];
The breakpoint delegate returns an NSSet
of breakpoint line numbers. The implementation of this feature is at an early stage. Feel free to improve it.
To add clickable syntax error highlights define an NSArray
of SMLSyntaxErrors.
// define a syntax error
SMLSyntaxError *syntaxError = [[SMLSyntaxError new] autorelease];
syntaxError.description = @"Syntax errors can be defined";
syntaxError.line = 1;
syntaxError.character = 1;
syntaxError.length = 10;
fragaria.syntaxErrors = @[syntaxError];
The implementation of this feature is at an early stage. Feel free to improve it.
The SMLSyntaxColouringDelegate
protocol allows a delegate to influence the syntax colouring for each of a number of syntactical groups such as numbers, attributes, comments or keywords.
Pseudo code for the protocol method flow looks something like:
// query delegate if should colour this document
doColouring = fragariaDocument:shouldColourWithBlock:string:range:info
if !doColouring quit colouring
// send *ColourGroupWithBlock methods for each group defined by SMLSyntaxGroupInteger
foreach group
// query delegate if should colour this group
doColouring = fragariaDocument:shouldColourGroupWithBlock:string:range:info
if doColouring
colour the group
// inform delegate group was coloured
fragariaDocument:didColourGroupWithBlock:string:range:info
end if
end
// inform delegate document was coloured
fragariaDocument:willDidWithBlock:string:range:info
The delegate can completely override the colouring for a given group or provide additional colouring support (you will have to provide you own scanning logic). Document level delegate messages provide an opportunity to provide colouring for custom group configurations.
For more details see SMLSyntaxColouringDelegate.h and the example code in FragariaAppDelegate.m.
Fragaria supports syntax colouring for a wide range of programming languages and configuration file formats:
actionscript, actionscript3, active4d, ada, ampl, apache (config), applescript, asm-mips, asm-x86, asp-js, asp-vb, aspdotnet-cs, aspdotnet-vb, awk
batch (shell)
C, cobol, coffeescript, coldfusion, cpp, csharp, csound, css
D, dylan
eiffel, erl, eztpl
F-script, fortran, freefem
gedcom, gnuassembler, graphviz
haskell, header, html
idl
java, javafx, javascript, jsp
latex, lilypond, lisp, logtalk, lsl, lua
matlab, mel, metapost, metaslang, mysql, nemerle,
nrnhoc
objectivec, objectivecaml, ox
pascal, pdf, perl, php, plist, postscript, prolog, python
r, rhtml, ruby
scala, sgml, shell, sml, sql, stata, supercollider
tcltk, torquescript
udo
vb, verilog, vhdl
xml
To define a new syntax definition:
Generate a plist that defines the language syntax. The plist structure is simple and browsing the existing definitions should provide some enlightenment. The plist keys are defined in SMLSyntaxDefinition.h
. For much deeper insight see SMLSyntaxColouring - recolourRange:
.
Insert a reference to the new plist into SyntaxDefinitions.plist
Take a look at the TODO list.
Fragaria started out as the vital pulp of Smultron, now called Fraise. If you want to add additional features to Fragaria then looking at the Fraise and other forked sources is a good place to start. Fraise is a GC only app so you will need to consider memory management issues when importing code into Fragaria.