1// 2// AppController.m 3// PRICE 4// 5// Created by Riccardo Mottola on Thu Dec 12 2002. 6// Copyright (c) 2002-2005 Carduus. All rights reserved. 7// 8// This application is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 9// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 11#import "AppController.h" 12#import "MyDocument.h" 13 14 15@implementation AppController 16 17- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)theApplication 18{ 19 return NO; 20} 21 22- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename 23{ 24 NSDocumentController *dc; 25 MyDocument *doc; 26 27 dc = [NSDocumentController sharedDocumentController]; 28#if !defined (GNUSTEP) && (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4) 29 doc = [dc openDocumentWithContentsOfFile:filename display:YES]; 30#else 31 doc = [dc openDocumentWithContentsOfURL:[NSURL fileURLWithPath:filename] display:YES error:nil]; 32#endif 33 34 return (doc != nil); 35} 36 37- (void)applicationDidFinishLaunching:(NSNotification *)notification 38{ 39 NSUserDefaults *defaults; 40 NSDictionary *defDic; 41 42 previewController = [[PRPreviewController alloc] init]; 43 44 defaults = [NSUserDefaults standardUserDefaults]; 45 46 /* we register default settings */ 47 defDic = [NSDictionary dictionaryWithObjectsAndKeys: (prefEnlargeWindowsDefault ? @"YES" : @"NO"), prefEnlargeWindowsKey, (prefClosePanelsDefault ? @"YES" : @"NO"), prefClosePanelsKey, nil]; 48 [defaults registerDefaults: defDic]; 49 50 /* we read the last recorded value in the user defaults */ 51 52 prefEnlargeWindows = [defaults boolForKey:prefEnlargeWindowsKey]; 53 prefClosePanels = [defaults boolForKey:prefClosePanelsKey]; 54} 55 56- (PRPreviewController *) previewController 57{ 58 return previewController; 59} 60 61- (IBAction)showPreferences:(id)sender 62{ 63 [prefPanel makeKeyAndOrderFront:self]; 64 65 if(prefEnlargeWindows == YES) 66 [enlargeWindowsCheck setState:NSOnState]; 67 else 68 [enlargeWindowsCheck setState:NSOffState]; 69 70 if(prefClosePanels == YES) 71 [closePanelsCheck setState:NSOnState]; 72 else 73 [closePanelsCheck setState:NSOffState]; 74} 75 76- (IBAction)savePreferences:(id)sender 77{ 78 NSUserDefaults *defaults; 79 80 defaults = [NSUserDefaults standardUserDefaults]; 81 82 prefEnlargeWindows = [enlargeWindowsCheck state]; 83 [defaults setBool:prefEnlargeWindows forKey:prefEnlargeWindowsKey]; 84 85 prefClosePanels = [closePanelsCheck state]; 86 [defaults setBool:prefClosePanels forKey:prefClosePanelsKey]; 87 88 [prefPanel performClose:nil]; 89} 90 91- (IBAction) cancelPreferences:(id)sender 92{ 93 [prefPanel performClose:nil]; 94} 95 96- (BOOL) prefClosePanels 97{ 98 return prefClosePanels; 99} 100 101- (BOOL) prefEnlargeWindows 102{ 103 return prefEnlargeWindows; 104} 105 106@end 107