-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCodeFileController.j
More file actions
64 lines (55 loc) · 1.49 KB
/
CodeFileController.j
File metadata and controls
64 lines (55 loc) · 1.49 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
// (c) 2010-2011 by Anton Korenyushkin
@import "BaseFileController.j"
@implementation CodeFileController : BaseFileController
{
BOOL isReloading;
}
- (id)initWithApp:(App)anApp buffer:(Buffer)aBuffer // public
{
if (self = [super initWithApp:anApp
buffer:aBuffer
fileName:aBuffer.file.name
fileURL:[anApp URL] + "code/" + [aBuffer.file path]
readOnly:NO])
[buffer.file addObserver:self forKeyPath:"content"];
return self;
}
- (CPString)fileContent // protected
{
return buffer.file.content;
}
- (void)load // protected
{
[app loadFile:buffer.file];
}
- (void)observeValueForKeyPath:(CPString)keyPath ofObject:(id)object change:(CPDictionary)change context:(id)context // private
{
if (buffer.file.content === nil) {
if (!buffer.isModified) {
isReloading = YES;
[app loadFile:buffer.file];
}
} else if (isReloading) {
[editorView setStringValue:buffer.file.content];
} else {
[buffer setProcessing:NO];
if (!buffer.isEditable)
[self setupEditor];
}
}
- (void)controlTextDidChange:(id)sender // private
{
if (isReloading)
isReloading = NO;
else
[buffer setModified:YES];
}
- (void)save // public
{
if (!buffer.isModified)
return;
[buffer setModified:NO];
[buffer setProcessing:YES];
[app saveFile:buffer.file content:[editorView stringValue]];
}
@end