|
16 | 16 | #import "PBNSURLPathUserDefaultsTransfomer.h"
|
17 | 17 | #import "PBGitDefaults.h"
|
18 | 18 |
|
| 19 | + |
| 20 | + |
19 | 21 | @implementation ApplicationController
|
20 | 22 |
|
21 |
| -- (ApplicationController*)init |
22 |
| -{ |
| 23 | +- (ApplicationController *)init { |
23 | 24 | #ifdef DEBUG_BUILD
|
24 | 25 | [NSApp activateIgnoringOtherApps:YES];
|
25 | 26 | #endif
|
26 | 27 |
|
27 |
| - if(!(self = [super init])) |
28 |
| - return nil; |
29 |
| - |
30 |
| - if(![[NSBundle bundleWithPath:@"/System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework"] load]) |
31 |
| - if(![[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load]) |
32 |
| - NSLog(@"Could not load QuickLook"); |
| 28 | + if (self = [super init]) { |
| 29 | + if (![[NSBundle bundleWithPath:@"/System/Library/Frameworks/Quartz.framework/Frameworks/QuickLookUI.framework"] load]) |
| 30 | + if (![[NSBundle bundleWithPath:@"/System/Library/PrivateFrameworks/QuickLookUI.framework"] load]) |
| 31 | + NSLog(@"Could not load QuickLook"); |
33 | 32 |
|
34 |
| - /* Value Transformers */ |
35 |
| - NSValueTransformer *transformer = [[PBNSURLPathUserDefaultsTransfomer alloc] init]; |
36 |
| - [NSValueTransformer setValueTransformer:transformer forName:@"PBNSURLPathUserDefaultsTransfomer"]; |
37 |
| - |
38 |
| - // Make sure the PBGitDefaults is initialized, by calling a random method |
39 |
| - [PBGitDefaults class]; |
| 33 | + [NSValueTransformer setValueTransformer:[PBNSURLPathUserDefaultsTransfomer new] forName:@"PBNSURLPathUserDefaultsTransfomer"]; |
| 34 | + |
| 35 | + [PBGitDefaults class]; // Make sure the PBGitDefaults is initialized, by calling a random method |
| 36 | + } |
40 | 37 | return self;
|
41 | 38 | }
|
42 | 39 |
|
@@ -101,9 +98,9 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification
|
101 | 98 | [[PBRepositoryDocumentController sharedDocumentController] openDocument:self];
|
102 | 99 | }
|
103 | 100 |
|
104 |
| -- (void) windowWillClose: sender |
| 101 | +- (void)windowWillClose:sender |
105 | 102 | {
|
106 |
| - [firstResponder terminate: sender]; |
| 103 | + [firstResponder terminate:sender]; |
107 | 104 | }
|
108 | 105 |
|
109 | 106 | - (IBAction)openPreferencesWindow:(id)sender
|
@@ -167,125 +164,60 @@ - (IBAction)installCliTool:(id)sender;
|
167 | 164 | }
|
168 | 165 | }
|
169 | 166 |
|
170 |
| -/** |
171 |
| - Returns the support folder for the application, used to store the Core Data |
172 |
| - store file. This code uses a folder named "GitTest" for |
173 |
| - the content, either in the NSApplicationSupportDirectory location or (if the |
174 |
| - former cannot be found), the system's temporary directory. |
175 |
| - */ |
176 |
| - |
177 | 167 | - (NSString *)applicationSupportFolder {
|
178 | 168 |
|
179 | 169 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
180 | 170 | NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
|
181 | 171 | return [basePath stringByAppendingPathComponent:@"GitTest"];
|
182 | 172 | }
|
183 | 173 |
|
184 |
| - |
185 |
| -/** |
186 |
| - Creates, retains, and returns the managed object model for the application |
187 |
| - by merging all of the models found in the application bundle. |
188 |
| - */ |
189 |
| - |
190 | 174 | - (NSManagedObjectModel *)managedObjectModel {
|
191 |
| - |
192 |
| - if (managedObjectModel != nil) { |
193 |
| - return managedObjectModel; |
194 |
| - } |
195 |
| - |
196 |
| - managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain]; |
197 |
| - return managedObjectModel; |
| 175 | + return managedObjectModel ?: (managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil]); |
198 | 176 | }
|
199 | 177 |
|
200 |
| - |
201 |
| -/** |
202 |
| - Returns the persistent store coordinator for the application. This |
203 |
| - implementation will create and return a coordinator, having added the |
204 |
| - store for the application to it. (The folder for the store is created, |
205 |
| - if necessary.) |
206 |
| - */ |
207 |
| - |
208 | 178 | - (NSPersistentStoreCoordinator *) persistentStoreCoordinator {
|
209 |
| - |
210 |
| - if (persistentStoreCoordinator != nil) { |
211 |
| - return persistentStoreCoordinator; |
212 |
| - } |
213 |
| - |
214 |
| - NSFileManager *fileManager; |
215 |
| - NSString *applicationSupportFolder = nil; |
216 |
| - NSURL *url; |
217 |
| - NSError *error; |
218 |
| - |
219 |
| - fileManager = [NSFileManager defaultManager]; |
220 |
| - applicationSupportFolder = [self applicationSupportFolder]; |
221 |
| - if ( ![fileManager fileExistsAtPath:applicationSupportFolder isDirectory:NULL] ) { |
222 |
| - [fileManager createDirectoryAtPath:applicationSupportFolder withIntermediateDirectories:YES attributes:nil error:nil]; |
| 179 | + if (!persistentStoreCoordinator) { |
| 180 | + NSFileManager *fileManager; |
| 181 | + NSString *applicationSupportFolder = nil; |
| 182 | + NSURL *url; |
| 183 | + NSError *error; |
| 184 | + |
| 185 | + fileManager = [NSFileManager defaultManager]; |
| 186 | + applicationSupportFolder = [self applicationSupportFolder]; |
| 187 | + if ( ![fileManager fileExistsAtPath:applicationSupportFolder isDirectory:NULL] ) { |
| 188 | + [fileManager createDirectoryAtPath:applicationSupportFolder withIntermediateDirectories:YES attributes:nil error:nil]; |
| 189 | + } |
| 190 | + |
| 191 | + url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"GitTest.xml"]]; |
| 192 | + persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; |
| 193 | + if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:&error]){ |
| 194 | + [[NSApplication sharedApplication] presentError:error]; |
| 195 | + } |
223 | 196 | }
|
224 |
| - |
225 |
| - url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"GitTest.xml"]]; |
226 |
| - persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; |
227 |
| - if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:&error]){ |
228 |
| - [[NSApplication sharedApplication] presentError:error]; |
229 |
| - } |
230 | 197 |
|
231 | 198 | return persistentStoreCoordinator;
|
232 | 199 | }
|
233 | 200 |
|
234 |
| - |
235 |
| -/** |
236 |
| - Returns the managed object context for the application (which is already |
237 |
| - bound to the persistent store coordinator for the application.) |
238 |
| - */ |
239 |
| - |
240 | 201 | - (NSManagedObjectContext *) managedObjectContext {
|
241 |
| - |
242 |
| - if (managedObjectContext != nil) { |
243 |
| - return managedObjectContext; |
244 |
| - } |
245 |
| - |
246 |
| - NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; |
247 |
| - if (coordinator != nil) { |
248 |
| - managedObjectContext = [[NSManagedObjectContext alloc] init]; |
249 |
| - [managedObjectContext setPersistentStoreCoordinator: coordinator]; |
| 202 | + if (!managedObjectContext) { |
| 203 | + managedObjectContext = [NSManagedObjectContext new]; |
| 204 | + managedObjectContext.persistentStoreCoordinator = self.persistentStoreCoordinator; |
250 | 205 | }
|
251 |
| - |
252 | 206 | return managedObjectContext;
|
253 | 207 | }
|
254 | 208 |
|
255 |
| - |
256 |
| -/** |
257 |
| - Returns the NSUndoManager for the application. In this case, the manager |
258 |
| - returned is that of the managed object context for the application. |
259 |
| - */ |
260 |
| - |
261 | 209 | - (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window {
|
262 |
| - return [[self managedObjectContext] undoManager]; |
| 210 | + return self.managedObjectContext.undoManager; |
263 | 211 | }
|
264 |
| - |
265 |
| - |
266 |
| -/** |
267 |
| - Performs the save action for the application, which is to send the save: |
268 |
| - message to the application's managed object context. Any encountered errors |
269 |
| - are presented to the user. |
270 |
| - */ |
271 | 212 |
|
272 | 213 | - (IBAction) saveAction:(id)sender {
|
273 |
| - |
274 |
| - NSError *error = nil; |
| 214 | + id error = nil; |
275 | 215 | if (![[self managedObjectContext] save:&error]) {
|
276 |
| - [[NSApplication sharedApplication] presentError:error]; |
| 216 | + [NSApp presentError:error]; |
277 | 217 | }
|
278 | 218 | }
|
279 | 219 |
|
280 |
| - |
281 |
| -/** |
282 |
| - Implementation of the applicationShouldTerminate: method, used here to |
283 |
| - handle the saving of changes in the application managed object context |
284 |
| - before the application terminates. |
285 |
| - */ |
286 |
| - |
287 | 220 | - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
288 |
| - |
289 | 221 | NSError *error;
|
290 | 222 | int reply = NSTerminateNow;
|
291 | 223 |
|
@@ -348,10 +280,9 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification
|
348 | 280 |
|
349 | 281 | - (void) dealloc {
|
350 | 282 |
|
351 |
| - [managedObjectContext release], managedObjectContext = nil; |
352 |
| - [persistentStoreCoordinator release], persistentStoreCoordinator = nil; |
353 |
| - [managedObjectModel release], managedObjectModel = nil; |
354 |
| - [super dealloc]; |
| 283 | + managedObjectContext = nil; |
| 284 | + persistentStoreCoordinator = nil; |
| 285 | + managedObjectModel = nil; |
355 | 286 | }
|
356 | 287 |
|
357 | 288 | #pragma mark Help menu
|
|
0 commit comments