Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 228 lines (159 sloc) 5.126 kb
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
1 //
2 // MyDocument.m
3 // Fragaria Document
4 //
5 // Created by Jonathan on 24/07/2010.
6 // Copyright 2010 mugginsoft.com. All rights reserved.
7 //
8
9 #import "MyDocument.h"
583f344c »
2012-09-27 Updated sample apps and README.
10 #import <MGSFragaria/MGSFragaria.h>
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
11
12 @implementation MyDocument
13
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
14 /*
15
16 - init
17
18 */
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
19 - (id)init
20 {
21 self = [super init];
22 if (self) {
23
24 // Add your subclass-specific initialization here.
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
25
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
26 }
27 return self;
28 }
29
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
30
31 #pragma mark -
32 #pragma mark Nib loading
33 /*
34
35 - windowNibName
36
37 */
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
38 - (NSString *)windowNibName
39 {
40 // Override returning the nib file name of the document
41 // 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.
42 return @"MyDocument";
43 }
44
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
45 /*
46
47 - windowControllerDidLoadNib:
48
49 */
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
50 - (void)windowControllerDidLoadNib:(NSWindowController *) aController
51 {
52 [super windowControllerDidLoadNib:aController];
53
54 // create an instance
55 fragaria = [[MGSFragaria alloc] init];
56
583f344c »
2012-09-27 Updated sample apps and README.
57 [fragaria setObject:self forKey:MGSFODelegate];
58
59 // define our syntax definition
60 [self setSyntaxDefinition:@"Objective-C"];
61
62 // embed editor in editView
63 [fragaria embedInView:editView];
64
65 //
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
66 // assign user defaults.
67 // a number of properties are derived from the user defaults system rather than the doc spec.
68 //
69 // see MGSFragariaPreferences.h for details
70 //
583f344c »
2012-09-27 Updated sample apps and README.
71 if (NO) {
72 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:MGSFragariaPrefsAutocompleteSuggestAutomatically];
73 [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:NO] forKey:MGSFragariaPrefsLineWrapNewDocuments];
74 }
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
75
583f344c »
2012-09-27 Updated sample apps and README.
76 // define initial document configuration
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
77 //
78 // see MGSFragaria.h for details
79 //
583f344c »
2012-09-27 Updated sample apps and README.
80 if (YES) {
81 [fragaria setObject:[NSNumber numberWithBool:YES] forKey:MGSFOIsSyntaxColoured];
82 [fragaria setObject:[NSNumber numberWithBool:YES] forKey:MGSFOShowLineNumberGutter];
83 }
84
85 // set text
86 [fragaria setString:@"// We Don't need the future"];
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
87
583f344c »
2012-09-27 Updated sample apps and README.
88
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
89 // access the NSTextView
90 NSTextView *textView = [fragaria objectForKey:ro_MGSFOTextView];
91
92 #pragma unused(textView)
93
94 }
95
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
96 #pragma mark -
97 #pragma mark NSDocument data
98 /*
99
100 - dataOfType:error:
101
102 */
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
103 - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
104 {
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
105 #pragma unused(typeName)
106
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
107 // 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.
108
109 // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
110
111 // 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.
112
113 if ( outError != NULL ) {
114 *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
115 }
116 return nil;
117 }
118
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
119 /*
120
121 readFromData:ofType:error:
122
123 */
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
124 - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
125 {
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
126 #pragma unused(data)
127 #pragma unused(typeName)
128
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
129 // 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.
130
131 // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
132
133 // 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.
134
135 if ( outError != NULL ) {
136 *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
137 }
138 return YES;
139 }
140
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
141 #pragma mark -
142 #pragma mark Syntax definition handling
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
143
144 /*
145
146 - setSyntaxDefinition:
147
148 */
149
150 - (void)setSyntaxDefinition:(NSString *)name
151 {
152 [fragaria setObject:name forKey:MGSFOSyntaxDefinitionName];
153 }
154
155 /*
156
157 - syntaxDefinition
158
159 */
160 - (NSString *)syntaxDefinition
161 {
162 return [fragaria objectForKey:MGSFOSyntaxDefinitionName];
163
164 }
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
165
166 #pragma mark -
167 #pragma mark NSTextDelegate
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
168 /*
169
170 - textDidChange:
171
172 fragaria delegate method
173
174 */
175 - (void)textDidChange:(NSNotification *)notification
176 {
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
177 #pragma unused(notification)
178
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
179 NSWindow *window = [[self windowControllers] objectAtIndex:0];
180
181 [window setDocumentEdited:YES];
182 }
183
cc1fc3fb »
2010-11-10 Added text delegate methods to sample apps. Enabled additional warnings.
184 /*
185
186 - textDidBeginEditing:
187
188 */
189 - (void)textDidBeginEditing:(NSNotification *)aNotification
190 {
191 NSLog(@"notification : %@", [aNotification name]);
192 }
193
194 /*
195
196 - textDidEndEditing:
197
198 */
199 - (void)textDidEndEditing:(NSNotification *)aNotification
200 {
201 NSLog(@"notification : %@", [aNotification name]);
202 }
203
204 /*
205
206 - textShouldBeginEditing:
207
208 */
209 - (BOOL)textShouldBeginEditing:(NSText *)aTextObject
210 {
211 #pragma unused(aTextObject)
212
213 return YES;
214 }
215
216 /*
217
218 - textShouldEndEditing:
219
220 */
221 - (BOOL)textShouldEndEditing:(NSText *)aTextObject
222 {
223 #pragma unused(aTextObject)
224
225 return YES;
226 }
227
c31d229a »
2010-07-27 Possible buffer overflow fixed. Simple NSDocument sample target added
228 @end
Something went wrong with that request. Please try again.