Re: Stopping the new document at launch
Re: Stopping the new document at launch
- Subject: Re: Stopping the new document at launch
- From: "Erik M. Buck" <email@hidden>
- Date: Thu, 21 Feb 2002 17:18:04 -0600
From
http://www.mactech.com/articles/mactech/Vol.15/15.05/May99Tips/
Stopping Default New Documents in Yellow Box Applications
The NSDocument and NSDocumentController classes in the Yellow Box AppKit
make it trivial to create multi-document applications on Mac OS X Server.
However the default behavior is to always open a new file on launching the
app. Fortunately there is an easy solution to prevent this behavior. In your
NSApplication object's delegate, add the following method:
- (BOOL) applicationShouldOpenUntitledFile:
(NSApplication *)sender
{
return NO;
}
Your application will no longer automatically open a blank document on
launch! A better solution might be to take that setting from the defaults
database, allowing you to control this behavior via a preference panel:
- (BOOL) applicationShouldOpenUntitledFile:
(NSApplication *)sender
{
return [[NSUserDefaults standardUserDefaults]
boolForKey:@"applicationShouldOpenUntitledFile"];
}
If the default applicationShouldOpenUntitledFile is set to YES, then a new
empty document will be created.
Scott Anguish
From
http://wodeveloper.com/omniLists/macosx-dev/2000/December/msg00027.html
AppController.h:
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject
{
}
-(BOOL)applicationShouldOpenUntitledFile:(NSApplication*)app;
@end
AppController.m:
#import "AppController.h"
@implementation AppController
-(BOOL)applicationShouldOpenUntitledFile:(NSApplication*)app
{
return NO; //<<<<< That's the trick
}
@end
from the definitive source
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/ApplicationKit/Ob
jC_classic/Classes/NSApplication.html
applicationShouldOpenUntitledFile:
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender
Invoked immediately before opening an untitled file. Return NO to prevent
the application from opening an untitled file; return YES, otherwise. Note
that applicationOpenUntitledFile: is invoked if this method returns YES.
----- Original Message -----
From: "Drew Cunningham" <email@hidden>
To: <email@hidden>
Sent: Thursday, February 21, 2002 4:29 PM
Subject: Stopping the new document at launch
>
This is probably an easy question to answer, but one I've had a hard time
>
searching for...
>
How do you stop an application from automatically opening a new document
>
when you
>
1) launch it and also
>
2) switch to it from the doc?
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.