forked from KosmicTask/Fragaria
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MyDocument.m
228 lines (159 loc) · 5.01 KB
/
MyDocument.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
//
// MyDocument.m
// Fragaria Document
//
// Created by Jonathan on 24/07/2010.
// Copyright 2010 mugginsoft.com. All rights reserved.
//
#import "MyDocument.h"
#import <MGSFragaria/MGSFragaria.h>
@implementation MyDocument
/*
- init
*/
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
}
return self;
}
#pragma mark -
#pragma mark Nib loading
/*
- windowNibName
*/
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"MyDocument";
}
/*
- windowControllerDidLoadNib:
*/
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// create an instance
fragaria = [[MGSFragaria alloc] init];
[fragaria setObject:self forKey:MGSFODelegate];
// define our syntax definition
[self setSyntaxDefinition:@"Objective-C"];
// embed editor in editView
[fragaria embedInView:editView];
//
// assign user defaults.
// a number of properties are derived from the user defaults system rather than the doc spec.
//
// see MGSFragariaPreferences.h for details
//
if (NO) {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsAutocompleteSuggestAutomatically];
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsLineWrapNewDocuments];
}
// define initial document configuration
//
// see MGSFragaria.h for details
//
if (YES) {
[fragaria setObject:[NSNumber numberWithBool:YES] forKey:MGSFOIsSyntaxColoured];
[fragaria setObject:[NSNumber numberWithBool:YES] forKey:MGSFOShowLineNumberGutter];
}
// set text
[fragaria setString:@"// We Don't need the future"];
// access the NSTextView
NSTextView *textView = [fragaria objectForKey:ro_MGSFOTextView];
#pragma unused(textView)
}
#pragma mark -
#pragma mark NSDocument data
/*
- dataOfType:error:
*/
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
#pragma unused(typeName)
// Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
// You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
// For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return nil;
}
/*
readFromData:ofType:error:
*/
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
#pragma unused(data)
#pragma unused(typeName)
// Insert code here to read your document from the given data of the specified type. If the given outError != NULL, ensure that you set *outError when returning NO.
// You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
// For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
}
return YES;
}
#pragma mark -
#pragma mark Syntax definition handling
/*
- setSyntaxDefinition:
*/
- (void)setSyntaxDefinition:(NSString *)name
{
[fragaria setObject:name forKey:MGSFOSyntaxDefinitionName];
}
/*
- syntaxDefinition
*/
- (NSString *)syntaxDefinition
{
return [fragaria objectForKey:MGSFOSyntaxDefinitionName];
}
#pragma mark -
#pragma mark NSTextDelegate
/*
- textDidChange:
fragaria delegate method
*/
- (void)textDidChange:(NSNotification *)notification
{
#pragma unused(notification)
NSWindow *window = [[self windowControllers] objectAtIndex:0];
[window setDocumentEdited:YES];
}
/*
- textDidBeginEditing:
*/
- (void)textDidBeginEditing:(NSNotification *)aNotification
{
NSLog(@"notification : %@", [aNotification name]);
}
/*
- textDidEndEditing:
*/
- (void)textDidEndEditing:(NSNotification *)aNotification
{
NSLog(@"notification : %@", [aNotification name]);
}
/*
- textShouldBeginEditing:
*/
- (BOOL)textShouldBeginEditing:(NSText *)aTextObject
{
#pragma unused(aTextObject)
return YES;
}
/*
- textShouldEndEditing:
*/
- (BOOL)textShouldEndEditing:(NSText *)aTextObject
{
#pragma unused(aTextObject)
return YES;
}
@end