• 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
NSDocumentController singleton problem, part 2
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDocumentController singleton problem, part 2


  • Subject: NSDocumentController singleton problem, part 2
  • From: Brad Oliver <email@hidden>
  • Date: Mon, 16 Dec 2002 00:42:33 -0600

I've got an app for which I need to have at most one document open at a
time. Per some prior suggestions, I've tried variations on hacking my
NSDocument subclass and also an NSDocumentController subclass.

In a nutshell, I can't get it to work 100%. By overriding
NSDocumentController, I can get my app to Do The Right Thing, but with one
major caveat: it puts up an error message (spawned somewhere in AppKit)
about how it can't create a new document, due most likely to the fact that I
return NULL in my openUntitledDocumentOfType, etc methods.

Can someone suggest a better way to do this? I'm guessing that I have to
give up those nice sheet dialogs that AppKit provides automagically and
implement my own "save" dialogs that run modally, but that seems nasty.

Surely someone has run into this before? :-)

@interface NSDocumentController_Single : NSDocumentController
{
BOOL m_secondPass;
}

- (void)documentController:(NSDocumentController *)docController
didCloseAll:(BOOL)didCloseAll contextInfo:(void *)contextInfo;
- (void)openUntitled:(NSDocumentController *)docController
didCloseAll:(BOOL)didCloseAll contextInfo:(void *)contextInfo;

@end

...

@implementation NSDocumentController_Single

- (id)openDocumentWithContentsOfFile:(NSString *)fileName display:(BOOL)flag
{
if (m_secondPass == NO)
{
[super closeAllDocumentsWithDelegate: self
didCloseAllSelector: @selector(documentController: didCloseAll:
contextInfo:)
contextInfo: fileName];
return NULL;
}

m_secondPass = NO;
return [super openDocumentWithContentsOfFile: fileName display: flag];
}

- (id)openUntitledDocumentOfType:(NSString *)docType display:(BOOL)flag
{
if (m_secondPass == NO)
{
[self closeAllDocumentsWithDelegate: self
didCloseAllSelector: @selector(openUntitled: didCloseAll:
contextInfo:)
contextInfo: docType];
return NULL;
}

m_secondPass = NO;
return [super openUntitledDocumentOfType: docType display: flag];
}

- (void)documentController:(NSDocumentController *)docController
didCloseAll:(BOOL)didCloseAll contextInfo:(void *)contextInfo
{
if (didCloseAll)
{
m_secondPass = YES;
[[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfFile: (NSString *) contextInfo display: YES];
}
else
m_secondPass = NO;
}

- (void)openUntitled:(NSDocumentController *)docController
didCloseAll:(BOOL)didCloseAll contextInfo:(void *)contextInfo
{
if (didCloseAll)
{
m_secondPass = YES;
[[NSDocumentController sharedDocumentController]
openUntitledDocumentOfType: (NSString *) contextInfo display: YES];
}
else
m_secondPass = NO;
}

--
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.

  • Prev by Date: Symbol and dingbats in RTF
  • Next by Date: Re: Help me please to find a job in Cocoa
  • Previous by thread: RE: Symbol and dingbats in RTF
  • Next by thread: Re: NSDocumentController singleton problem, part 2
  • Index(es):
    • Date
    • Thread