• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Open new document in first (empty) window
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open new document in first (empty) window


  • Subject: Re: Open new document in first (empty) window
  • From: Ari Benzane <email@hidden>
  • Date: Wed, 6 Jun 2007 21:57:01 +0100

How do you determine isFirstDocument?

On 5 Jun 2007, at 21:56, PGM wrote:

Hey guys. My app is of the standard document type and it opens a new, empty document on launch. My users have requested that the when they open a saved document at this point, it should open in that blank window, instead of creating a new one. The only other app I've seen do this is Apple's TextEdit.

Is there a supported way to do this? I've googled and searched but I can't find anything and I'd rather not hack my own solution if there's a better way.


There is a page on cocodev on this subject, though it is not very extensive (you would have to do a search for the exact page). I took another route as outlined there as I thought that approach required too much rewriting of my existing code. My own approach seems very hackish though.


At the end of my NSDocument subclass awakeFromNib method I have the following code.

MyDocument *firstDoc = [[[NSDocumentController sharedDocumentController] documents] objectAtIndex:0];
if([firstDoc isFirstDocument]){
[self performSelector:@selector(closeFirstWindow:) withObject:firstDoc afterDelay:0.001];
NSDisableScreenUpdates();
}


The isFirstDocument method checks whether there is only one window open and whether that document was the first untitled document and has never been changed. This code is specific for my app, so not much use to show here.

the closeFirstWindow: method is as follows:

-(void)closeFirstWindow:(MyDocument *)firstDoc
{
	[[self window] setFrame:[[firstDoc window] frame] display:YES];
	[firstDoc close];
	NSEnableScreenUpdates();
}

So basically what I do is draw the new document at exactly the same position and size as the empty one and then close the empty one in the background. The delay and disabling of screen updates is necessary to avoid ugly flashes of the saved document at its original position.

Good luck, Patrick



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Open new document in first (empty) window
      • From: arri <email@hidden>
References: 
 >Open new document in first (empty) window (From: Ari Benzane <email@hidden>)
 >Re: Open new document in first (empty) window (From: PGM <email@hidden>)

  • Prev by Date: NSTextFieldCell and -stopTracking::
  • Next by Date: NSTable - intercept item name before user editing
  • Previous by thread: Re: Open new document in first (empty) window
  • Next by thread: Re: Open new document in first (empty) window
  • Index(es):
    • Date
    • Thread