forked from KosmicTask/Fragaria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MGSFragaria.m
718 lines (531 loc) · 19.4 KB
/
MGSFragaria.m
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
//
// MGSFragaria.m
// Fragaria
//
// Created by Jonathan on 05/05/2010.
// Copyright 2010 mugginsoft.com. All rights reserved.
//
#import "MGSFragaria.h"
#import "MGSFragariaFramework.h"
#import "FRAFontTransformer.h"
// valid keys for
// - (void)setObject:(id)object forKey:(id)key;
// - (id)objectForKey:(id)key;
// BOOL
NSString * const MGSFOIsSyntaxColoured = @"isSyntaxColoured";
NSString * const MGSFOShowLineNumberGutter = @"showLineNumberGutter";
NSString * const MGSFOIsEdited = @"isEdited";
// string
NSString * const MGSFOSyntaxDefinitionName = @"syntaxDefinition";
NSString * const MGSFODocumentName = @"name";
// class name strings
// TODO: expose these to allow subclass name definition
NSString * const MGSFOEditorTextViewClassName = @"editorTextViewClassName";
NSString * const MGSFOLineNumbersClassName = @"lineNumbersClassName";
NSString * const MGSFOGutterTextViewClassName = @"gutterTextViewClassName";
NSString * const MGSFOSyntaxColouringClassName = @"syntaxColouringClassName";
// integer
NSString * const MGSFOGutterWidth = @"gutterWidth";
// NSView *
NSString * const ro_MGSFOTextView = @"firstTextView"; // readonly
NSString * const ro_MGSFOScrollView = @"firstTextScrollView"; // readonly
NSString * const ro_MGSFOGutterScrollView = @"firstGutterScrollView"; // readonly
// NSObject
NSString * const MGSFODelegate = @"delegate";
NSString * const MGSFOBreakpointDelegate = @"breakpointDelegate";
NSString * const MGSFOAutoCompleteDelegate = @"autoCompleteDelegate";
NSString * const MGSFOSyntaxColouringDelegate = @"syntaxColouringDelegate";
NSString * const ro_MGSFOLineNumbers = @"lineNumbers"; // readonly
NSString * const ro_MGSFOSyntaxColouring = @"syntaxColouring"; // readonly
static MGSFragaria *_currentInstance;
// KVO context constants
char kcGutterWidthPrefChanged;
char kcSyntaxColourPrefChanged;
char kcSpellCheckPrefChanged;
char kcLineNumberPrefChanged;
char kcLineWrapPrefChanged;
// class extension
@interface MGSFragaria()
@property (nonatomic, readwrite) MGSExtraInterfaceController *extraInterfaceController;
- (void)updateGutterView;
@property (nonatomic,strong) NSSet* objectGetterKeys;
@property (nonatomic,strong) NSSet* objectSetterKeys;
@end
@implementation MGSFragaria
@synthesize extraInterfaceController;
@synthesize docSpec;
@synthesize objectSetterKeys;
@synthesize objectGetterKeys;
#pragma mark -
#pragma mark Class methods
/*
+ currentInstance;
*/
+ (id)currentInstance
{
/*
We need to have access to the current instance.
This is used by the various singleton controllers to provide a target for their actions.
The instance in the key window will automatically be assigned as the current instance.
*/
return _currentInstance;
}
/*
+ currentInstance;
*/
+ (void)setCurrentInstance:(MGSFragaria *)anInstance
{
NSAssert([anInstance isKindOfClass:[self class]], @"bad class");
_currentInstance = anInstance;
}
/*
+ initialize
*/
+ (void)initialize
{
[MGSFragariaPreferences initializeValues];
}
/*
+ initializeFramework
*/
+ (void)initializeFramework
{
// + initialize does the work
}
/*
+ createDocSpec
*/
+ (id)createDocSpec
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// initialise document spec from user defaults
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
[defaults objectForKey:MGSFragariaPrefsSyntaxColourNewDocuments], MGSFOIsSyntaxColoured,
[defaults objectForKey:MGSFragariaPrefsShowLineNumberGutter], MGSFOShowLineNumberGutter,
[defaults objectForKey:MGSFragariaPrefsGutterWidth], MGSFOGutterWidth,
@"Standard", MGSFOSyntaxDefinitionName,
nil];
}
/*
+ docSpec:setString:
*/
+ (void)docSpec:(id)docSpec setString:(NSString *)string
{
// set text view string
[[docSpec valueForKey:ro_MGSFOTextView] setString:string];
}
/*
+ docSpec:setString:options:
*/
+ (void)docSpec:(id)docSpec setString:(NSString *)string options:(NSDictionary *)options
{
// set text view string
[(SMLTextView *)[docSpec valueForKey:ro_MGSFOTextView] setString:string options:options];
}
/*
+ docSpec:setAttributedString
*/
+ (void)docSpec:(id)docSpec setAttributedString:(NSAttributedString *)string
{
// set text view string
[(SMLTextView *)[docSpec valueForKey:ro_MGSFOTextView] setAttributedString:string];
}
/*
+ docSpec:setAttributedString:options:
*/
+ (void)docSpec:(id)docSpec setAttributedString:(NSAttributedString *)string options:(NSDictionary *)options
{
// set text view string
[(SMLTextView *)[docSpec valueForKey:ro_MGSFOTextView] setAttributedString:string options:options];
}
/*
+ stringForDocSpec:
*/
+ (NSString *)stringForDocSpec:(id)docSpec
{
return [[docSpec valueForKey:ro_MGSFOTextView] string];
}
/*
+ attributedStringForDocSpec:
*/
+ (NSAttributedString *)attributedStringForDocSpec:(id)docSpec
{
return [[[docSpec valueForKey:ro_MGSFOTextView] layoutManager] attributedString];
}
/*
+ attributedStringWithTemporaryAttributesAppliedForDocSpec:
*/
+ (NSAttributedString *)attributedStringWithTemporaryAttributesAppliedForDocSpec:(id)docSpec
{
// recolour the entire textview content
SMLTextView *textView = [docSpec valueForKey:ro_MGSFOTextView];
SMLSyntaxColouring *syntaxColouring = [docSpec valueForKey:ro_MGSFOSyntaxColouring];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], @"colourAll", nil];
[syntaxColouring pageRecolourTextView:textView options: options];
// get content with layout manager temporary attributes persisted
SMLLayoutManager *layoutManager = (SMLLayoutManager *)[textView layoutManager];
return [layoutManager attributedStringWithTemporaryAttributesApplied];
}
#pragma mark -
#pragma mark Instance methods
/*
- initWithObject
Designated initializer
Calling this method enables us to use a predefined object
for our doc spec.
eg: Smultron used a CoreData object.
*/
- (id)initWithObject:(id)object
{
if ((self = [super init])) {
_currentInstance = self;
// a doc spec is mandatory
if (object) {
self.docSpec = object;
} else {
self.docSpec = [[self class] createDocSpec];
}
// register the font transformer
FRAFontTransformer *fontTransformer = [[FRAFontTransformer alloc] init];
[NSValueTransformer setValueTransformer:fontTransformer forName:@"FontTransformer"];
// observe defaults that affect rendering
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
[defaultsController addObserver:self forKeyPath:@"values.FragariaGutterWidth" options:NSKeyValueObservingOptionNew context:&kcGutterWidthPrefChanged];
[defaultsController addObserver:self forKeyPath:@"values.FragariaSyntaxColourNewDocuments" options:NSKeyValueObservingOptionNew context:&kcSyntaxColourPrefChanged];
[defaultsController addObserver:self forKeyPath:@"values.FragariaAutoSpellCheck" options:NSKeyValueObservingOptionNew context:&kcSpellCheckPrefChanged];
[defaultsController addObserver:self forKeyPath:@"values.FragariaShowLineNumberGutter" options:NSKeyValueObservingOptionNew context:&kcLineNumberPrefChanged];
[defaultsController addObserver:self forKeyPath:@"values.FragariaLineWrapNewDocuments" options:NSKeyValueObservingOptionNew context:&kcLineWrapPrefChanged];
// Create the Sets containing the valid setter/getter combinations for the Docspec
// Define read/write keys
self.objectSetterKeys = [NSSet setWithObjects:MGSFOIsSyntaxColoured, MGSFOShowLineNumberGutter, MGSFOIsEdited,
MGSFOSyntaxDefinitionName, MGSFODelegate, MGSFOBreakpointDelegate, MGSFOAutoCompleteDelegate, MGSFOSyntaxColouringDelegate,
nil];
// Define read only keys
self.objectGetterKeys = [NSMutableSet setWithObjects:ro_MGSFOTextView, ro_MGSFOScrollView, ro_MGSFOGutterScrollView,
ro_MGSFOLineNumbers, ro_MGSFOSyntaxColouring,
nil];
// Merge both to get all getters
[(NSMutableSet *)self.objectGetterKeys unionSet:self.objectSetterKeys];
}
return self;
}
/*
- init
*/
- (id)init
{
return [self initWithObject:nil];
}
#pragma mark View handling
/*
- embedInView:
*/
- (void)embedInView:(NSView *)contentView
{
NSAssert(contentView != nil, @"A content view must be provided.");
NSInteger gutterWidth = [[SMLDefaults valueForKey:MGSFragariaPrefsGutterWidth] integerValue];
// TODO: allow user to pass in custom class name in doc spec. This will likely entail refactoring
// the relevant clas headers to exposure sufficient information to make subclassing feasible.
Class editorTextViewClass = [SMLTextView class];
Class lineNumberClass = [SMLLineNumbers class];
Class gutterTextViewClass = [SMLGutterTextView class];
Class syntaxColouringClass = [SMLSyntaxColouring class];
// create text scrollview
NSScrollView *textScrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, [contentView bounds].size.width, [contentView bounds].size.height)];
NSSize contentSize = [textScrollView contentSize];
[textScrollView setBorderType:NSNoBorder];
[textScrollView setHasVerticalScroller:YES];
[textScrollView setAutohidesScrollers:YES];
[textScrollView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
[[textScrollView contentView] setAutoresizesSubviews:YES];
[textScrollView setPostsFrameChangedNotifications:YES];
// create textview
SMLTextView *textView = [[editorTextViewClass alloc] initWithFrame:NSMakeRect(0, 0, contentSize.width, contentSize.height)];
[textView setFragaria:self];
[textScrollView setDocumentView:textView];
// create line numbers
SMLLineNumbers *lineNumbers = [[lineNumberClass alloc] initWithDocument:self.docSpec];
[self.docSpec setValue:lineNumbers forKey:ro_MGSFOLineNumbers];
// SMLLineNumbers will be notified of changes to the text scroll view content view due to scrolling
[[NSNotificationCenter defaultCenter] addObserver:lineNumbers selector:@selector(viewBoundsDidChange:) name:NSViewBoundsDidChangeNotification object:[textScrollView contentView]];
[[NSNotificationCenter defaultCenter] addObserver:lineNumbers selector:@selector(viewBoundsDidChange:) name:NSViewFrameDidChangeNotification object:[textScrollView contentView]];
// create gutter scrollview
NSScrollView *gutterScrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, gutterWidth, contentSize.height)];
[gutterScrollView setBorderType:NSNoBorder];
[gutterScrollView setHasVerticalScroller:NO];
[gutterScrollView setHasHorizontalScroller:NO];
[gutterScrollView setAutoresizingMask:NSViewHeightSizable];
[[gutterScrollView contentView] setAutoresizesSubviews:YES];
// create gutter textview
SMLGutterTextView *gutterTextView = [[gutterTextViewClass alloc] initWithFrame:NSMakeRect(0, 0, gutterWidth, contentSize.height - 50)];
[gutterScrollView setDocumentView:gutterTextView];
// update the docSpec
[self.docSpec setValue:textView forKey:ro_MGSFOTextView];
[self.docSpec setValue:textScrollView forKey:ro_MGSFOScrollView];
[self.docSpec setValue:gutterScrollView forKey:ro_MGSFOGutterScrollView];
// add syntax colouring
SMLSyntaxColouring *syntaxColouring = [[syntaxColouringClass alloc] initWithDocument:self.docSpec];
[self.docSpec setValue:syntaxColouring forKey:ro_MGSFOSyntaxColouring];
[self.docSpec setValue:syntaxColouring forKey:MGSFOAutoCompleteDelegate];
// add scroll view to content view
[contentView addSubview:[self.docSpec valueForKey:ro_MGSFOScrollView]];
// update line numbers
[[self.docSpec valueForKey:ro_MGSFOLineNumbers] updateLineNumbersForClipView:[[self.docSpec valueForKey:ro_MGSFOScrollView] contentView] checkWidth:NO recolour:YES];
// update the gutter view
[self updateGutterView];
// apply default line wrapping
[textView updateLineWrap];
[textView setLineWrap:[[SMLDefaults valueForKey:MGSFragariaPrefsLineWrapNewDocuments] boolValue]];
}
#pragma mark -
#pragma mark Document specification
/*
- setObject:forKey:
*/
- (void)setObject:(id)object forKey:(id)key
{
if ([self.objectSetterKeys containsObject:key]) {
[(id)self.docSpec setValue:object forKey:key];
}
}
/*
- objectForKey:
*/
- (id)objectForKey:(id)key
{
if ([self.objectGetterKeys containsObject:key]) {
return [self.docSpec valueForKey:key];
}
return nil;
}
#pragma mark -
#pragma mark Accessors
/*
- setString:
*/
- (void)setString:(NSString *)aString
{
[[self class] docSpec:self.docSpec setString:aString];
}
/*
- setString:options:
*/
- (void)setString:(NSString *)aString options:(NSDictionary *)options
{
[[self class] docSpec:self.docSpec setString:aString options:options];
}
/*
- string
*/
- (NSString *)string
{
return [[self class] stringForDocSpec:self.docSpec];
}
/*
- setAttributedString:
*/
- (void)setAttributedString:(NSAttributedString *)aString
{
[[self class] docSpec:self.docSpec setAttributedString:aString];
}
/*
- setAttributedString:options:
*/
- (void)setAttributedString:(NSAttributedString *)aString options:(NSDictionary *)options
{
[[self class] docSpec:self.docSpec setAttributedString:aString options:options];
}
/*
- attributedString
*/
- (NSAttributedString *)attributedString
{
return [[self class] attributedStringForDocSpec:self.docSpec];
}
/*
- attributedStringWithTemporaryAttributesApplied
*/
- (NSAttributedString *)attributedStringWithTemporaryAttributesApplied
{
return [[self class] attributedStringWithTemporaryAttributesAppliedForDocSpec:self.docSpec];
}
/*
- textView
*/
- (NSTextView *)textView
{
return [self objectForKey:ro_MGSFOTextView];
}
/*
- setShowsLineNumbers:
*/
- (void)setShowsLineNumbers:(BOOL)value
{
[self setObject:[NSNumber numberWithBool:value] forKey:MGSFOShowLineNumberGutter];
[self updateGutterView];
}
/*
- showsLineNumbers
*/
- (BOOL)showsLineNumbers
{
NSNumber *value = [self objectForKey:MGSFOShowLineNumberGutter];
return [value boolValue];
}
/*
- setSyntaxColoured
*/
- (void)setSyntaxColoured:(BOOL)value
{
[self setObject:[NSNumber numberWithBool:value] forKey:MGSFOIsSyntaxColoured];
[self reloadString];
}
/*
- isSyntaxColoured
*/
- (BOOL)isSyntaxColoured
{
NSNumber *value = [self objectForKey:MGSFOIsSyntaxColoured];
return [value boolValue];
}
/*
- reloadString
*/
- (void)reloadString
{
[self setString:[self string]];
}
/*
- setSyntaxErrors:
*/
- (void)setSyntaxErrors:(NSArray *)errors
{
SMLSyntaxColouring *syntaxColouring = [docSpec valueForKey:ro_MGSFOSyntaxColouring];
syntaxColouring.syntaxErrors = errors;
[syntaxColouring pageRecolour];
}
/*
- syntaxErrors
*/
- (NSArray *)syntaxErrors
{
SMLSyntaxColouring *syntaxColouring = [docSpec valueForKey:ro_MGSFOSyntaxColouring];
return syntaxColouring.syntaxErrors;
}
#pragma mark -
#pragma mark String updating
/*
- replaceCharactersInRange:withString:options
*/
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)text options:(NSDictionary *)options
{
SMLTextView *textView = (SMLTextView *)[self textView];
[textView replaceCharactersInRange:range withString:text options:options];
}
#pragma mark -
#pragma mark Controllers
/*
- textMenuController
*/
- (MGSTextMenuController *)textMenuController
{
return [MGSTextMenuController sharedInstance];
}
/*
- extraInterfaceController
*/
- (MGSExtraInterfaceController *)extraInterfaceController
{
if (!extraInterfaceController) {
extraInterfaceController = [[MGSExtraInterfaceController alloc] init];
}
return extraInterfaceController;
}
#pragma mark -
#pragma mark KVO
/*
- observeValueForKeyPath:ofObject:change:context:
*/
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
BOOL boolValue = NO;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (context == &kcGutterWidthPrefChanged) {
[self updateGutterView];
} else if (context == &kcLineNumberPrefChanged) {
boolValue = [defaults boolForKey:MGSFragariaPrefsShowLineNumberGutter];
[self setShowsLineNumbers:boolValue];
} else if (context == &kcSyntaxColourPrefChanged) {
boolValue = [defaults boolForKey:MGSFragariaPrefsSyntaxColourNewDocuments];
[self setSyntaxColoured:boolValue];
} else if (context == &kcSpellCheckPrefChanged) {
boolValue = [defaults boolForKey:MGSFragariaPrefsAutoSpellCheck];
[[self textView] setContinuousSpellCheckingEnabled:boolValue];
} else if (context == &kcLineWrapPrefChanged) {
boolValue = [defaults boolForKey:MGSFragariaPrefsLineWrapNewDocuments];
[(SMLTextView *)[self textView] setLineWrap:boolValue];
[[self.docSpec valueForKey:ro_MGSFOLineNumbers] updateLineNumbersCheckWidth:YES recolour:YES];
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
#pragma mark -
#pragma mark Class extension
/*
- updateGutterView
*/
- (void) updateGutterView {
id document = self.docSpec;
BOOL showGutter = [[self.docSpec valueForKey:MGSFOShowLineNumberGutter] boolValue];
NSUInteger gutterWidth = [[SMLDefaults valueForKey:MGSFragariaPrefsGutterWidth] integerValue];
NSUInteger gutterOffset = (showGutter ? gutterWidth : 0);
NSRect frame, newFrame;
// Update document value first.
[document setValue:[NSNumber numberWithUnsignedInteger:gutterWidth] forKey:MGSFOGutterWidth];
// get editor views
NSScrollView *textScrollView = (NSScrollView *)[document valueForKey:ro_MGSFOScrollView];
NSScrollView *gutterScrollView = (NSScrollView *) [document valueForKey:ro_MGSFOGutterScrollView];
NSTextView *textView = (NSTextView *)[document valueForKey:ro_MGSFOTextView];
// get content view
NSView *contentView = [textScrollView superview];
CGFloat contentWidth = [contentView bounds].size.width;
// Text Scroll View
if (textScrollView != nil) {
frame = [textScrollView frame];
newFrame = NSMakeRect(gutterOffset, frame.origin.y, contentWidth - gutterOffset, frame.size.height);
[textScrollView setFrame:newFrame];
[textScrollView setNeedsDisplay:YES];
}
// Text View
else if (textView != nil) {
frame = [textScrollView frame];
newFrame = NSMakeRect(gutterOffset, frame.origin.y, contentWidth - gutterOffset, frame.size.height);
[textView setFrame:newFrame];
[textView setNeedsDisplay:YES];
}
// Gutter Scroll View
if (gutterScrollView != nil) {
frame = [gutterScrollView frame];
newFrame = NSMakeRect(frame.origin.x, frame.origin.y, gutterWidth, frame.size.height);
[gutterScrollView setFrame:newFrame];
// add or remove the gutter sub view
if (showGutter) {
[contentView addSubview:gutterScrollView];
[gutterScrollView setNeedsDisplay:YES];
} else {
[gutterScrollView removeFromSuperview];
}
}
// update the line numbers
[[document valueForKey:ro_MGSFOLineNumbers] updateLineNumbersCheckWidth:YES recolour:YES];
}
#pragma mark -
#pragma mark Resource loading
+ (NSImage *) imageNamed:(NSString *)name
{
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForImageResource:name];
return path != nil ? [[NSImage alloc]
initWithContentsOfFile:path] : nil;
}
@end