ResKnife/Cocoa/Classes/ApplicationDelegate.m

152 lines
4.5 KiB
Mathematica
Raw Normal View History

2001-10-19 19:41:13 +00:00
#import "ApplicationDelegate.h"
#import "InfoWindowController.h"
#import "PrefsWindowController.h"
#import "CreateResourceSheetController.h"
2002-02-02 11:31:28 +00:00
#import "ResourceDocument.h"
#import "ResourceDataSource.h"
#import "ResknifePluginProtocol.h"
2001-10-19 19:41:13 +00:00
@implementation ApplicationDelegate
- (id)init
{
self = [super init];
2002-02-11 01:22:17 +00:00
[NSApp registerServicesMenuSendTypes:[NSArray arrayWithObject:NSStringPboardType] returnTypes:[NSArray arrayWithObject:NSStringPboardType]];
2001-10-19 19:41:13 +00:00
return self;
}
- (void)awakeFromNib
{
// Part of my EvilPlan<EFBFBD> to find out how many people use ResKnife and how often!
int launchCount = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"];
[[NSUserDefaults standardUserDefaults] setInteger:launchCount + 1 forKey:@"LaunchCount"];
2002-04-27 18:17:47 +00:00
// save a number of icons
icons = [[NSMutableDictionary alloc] init];
2002-05-31 00:17:53 +00:00
[icons setObject:[[NSWorkspace sharedWorkspace] iconForFileType:@"TEXT"] forKey:@"TEXT"];
2002-04-27 18:17:47 +00:00
[icons setObject:[[NSWorkspace sharedWorkspace] iconForFileType:@"PICT"] forKey:@"PICT"];
[icons setObject:[[NSWorkspace sharedWorkspace] iconForFileType:@"icns"] forKey:@"icns"];
2001-10-19 19:41:13 +00:00
[self initUserDefaults];
2002-04-27 18:17:47 +00:00
}
- (void)dealloc
{
[icons release];
[super dealloc];
}
2001-10-19 19:41:13 +00:00
2002-02-11 01:22:17 +00:00
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
{
2002-03-21 04:02:26 +00:00
#pragma unused( sender )
2002-02-23 03:40:24 +00:00
NSString *launchAction = [[NSUserDefaults standardUserDefaults] stringForKey:@"LaunchAction"];
if( [launchAction isEqualToString:@"OpenUntitledFile"] )
return YES;
else if( [launchAction isEqualToString:@"DisplayOpenPanel"] )
{
[[NSDocumentController sharedDocumentController] openDocument:sender];
return NO;
}
else return NO; // should be @"None", but we shall return NO for any other value
2002-02-11 01:22:17 +00:00
}
2002-05-31 00:17:53 +00:00
- (BOOL)application:(NSApplication *)application openFile:(NSString *)file
{
#pragma unused( application )
// bug: check if application was an external editor (e.g. Iconographer) and update existing open file instead
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfFile:file display:YES];
}
2002-03-21 04:02:26 +00:00
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
{
#pragma unused( sender )
return !flag;
}
2002-02-02 11:31:28 +00:00
- (IBAction)showAbout:(id)sender
{
[NSApp orderFrontStandardAboutPanel:sender];
// get about box code from http://cocoadevcentral.com/tutorials/showpage.php?show=00000041.php
}
2002-02-23 03:40:24 +00:00
- (IBAction)visitWebsite:(id)sender
{
2002-05-31 00:17:53 +00:00
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://web.nickshanks.com/resknife/"]];
2002-02-23 03:40:24 +00:00
}
- (IBAction)visitSourceforge:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://resknife.sourceforge.net/"]];
}
- (IBAction)emailDeveloper:(id)sender
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"mailto:resknife@nickshanks.com?Subject=Comments,%20Suggestions%20and%20Bug%20Reports"]];
}
2001-10-19 19:41:13 +00:00
- (IBAction)showInfo:(id)sender
{
[[InfoWindowController sharedInfoWindowController] showWindow:sender];
}
- (IBAction)showPrefs:(id)sender
{
[[PrefsWindowController sharedPrefsWindowController] showWindow:sender];
}
- (void)initUserDefaults
{
// This should probably be added to NSUserDefaults as a category,
// since its universally useful. It loads a defaults.plist file
// from the app wrapper, and then sets the defaults if they don't
// already exist.
NSUserDefaults *defaults;
NSDictionary *defaultsPlist;
NSEnumerator *overDefaults;
id eachDefault;
// this isn't required, but saves us a few method calls
defaults = [NSUserDefaults standardUserDefaults];
// load the defaults.plist from the app wrapper. This makes it
// easy to add new defaults just using a text editor instead of
// hard-coding them into the application
defaultsPlist = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"defaults" ofType:@"plist"]];
// enumerate over all the keys in the dictionary
overDefaults = [[defaultsPlist allKeys] objectEnumerator];
while( eachDefault = [overDefaults nextObject] )
{
// for each key in the dictionary
// check if there is a value already registered for it
// and if there isn't, then register the value that was in the file
if( ![defaults stringForKey:eachDefault] )
{
[defaults setObject:[defaultsPlist objectForKey:eachDefault] forKey:eachDefault];
}
}
// force the defaults to save to the disk
[defaults synchronize];
}
2002-04-27 18:17:47 +00:00
- (NSDictionary *)icons
{
return icons;
}
2001-10-19 19:41:13 +00:00
@end
2002-02-23 03:40:24 +00:00
@implementation NSSavePanel (PackageBrowser)
/* Don't tell anyone I did this... */
- (void)setTreatsFilePackagesAsDirectories:(BOOL)flag
{
#pragma unused( flag )
_spFlags.treatsFilePackagesAsDirectories = YES;
}
@end