Re: Single document behavior
Re: Single document behavior
- Subject: Re: Single document behavior
- From: Jeff Disher <email@hidden>
- Date: Tue, 26 Nov 2002 18:52:30 -0500
One way you could do it is to create a static pointer to an instance of
you NSDocument sub-class as one of its instance variables. Then,
override the class initialize method:
+ (void)initialize
to set the pointer to nil.
Then, override the init method to check check the value of the static.
If it is nil, then instantiate normally and set the static to self, if
not, send a message to the instance pointed at by the static to tell it
you need it to ask the user what to do. Be sure that you override the
dealloc method to set the static back to nil.
This imposes a singleton design pattern on the system which should work
in the general case.
It is pretty clean but there might be something better.
Hope that helps,
Jeff.
On Tuesday, November 26, 2002, at 05:09 PM, Brad Oliver wrote:
I've got an NSDocument based app, and I want to slightly alter the
behavior
such that a maximum of one document will be present at any given time.
That is, if a document exists and the user chooses "New" from the file
menu,
or the app gets a reopen AppleEvent, I want to prompt the user to save
the
current document if it's dirty, cancel the open, etc before continuing
through with the new document process.
What is the cleanest way to do this with AppKit?
--
Brad Oliver
email@hidden
_______________________________________________
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.
Jeff Disher
President and Lead Developer of Spectral Class
Spectral Class: Shedding Light on Innovation
http://www.spectralclass.com/
_______________________________________________
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.