Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4171650
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:28:11+00:00 2026-05-21T00:28:11+00:00

I have an NSDocument based app in which I want to limit the number

  • 0

I have an NSDocument based app in which I want to limit the number of documents open at the same time (for a Lite version). I just want to have n documents, and if the user tries to open more than n, show a message with a link to the full app download.

I have managed to count the number of documents using NSDocumentController and, inside readFromFileWrapper, I can return FALSE. That prevents the new doc from opening, but it shows a standard error message. I don’t know how to avoid that. I would like to open a new window from a nib.

Is there any way to prevent NSDocument showing the standard error message when returning FALSE from readFromFileWrapper? Or is there any other way to prevent the document from opening before readFromFileWrapper is called?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T00:28:12+00:00Added an answer on May 21, 2026 at 12:28 am

    Try the init method, which is called both when creating a new document and when opening a saved document. You simply return nil if the limit has been reached. However, I have not tried this, and it might cause the same error to be displayed.

    - (id)init {
        if([[NSDocumentController documents] count] >= DOCUMENT_LIMIT) {
            [self release];
            return nil;
        }
        ...
    }
    

    In case the same error is displayed, you could use a custom NSDocumentController. Your implementations would check the number of open documents, display the message at the limit, and call the normal implementation otherwise.

    - (id)openUntitledDocumentAndDisplay:(BOOL)displayDocument error:(NSError **)outError {
        if([[self documents] count] >= DOCUMENT_LIMIT) {
            // fill outError
            return nil;
        }
        return [super openUntitledDocumentAndDisplay:displayDocument error:outError];
    }
    - (id)openDocumentWithContentsOfURL:(NSURL *)absoluteURL display:(BOOL)displayDocument error:(NSError **)outError {
        NSDocument *doc = [self documentForURL:absoluteURL];
        if(doc) { // already open, just show it
            [doc showWindows];
            return doc;
        }
        if([[self documents] count] >= DOCUMENT_LIMIT) {
            // fill outError
            return nil;
        }
        return [super openDocumentWithContentsOfURL:absoluteURL display:displayDocument];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a straightforward NSDocument -based Mac OS X app in which I am
I have a NSDocument based application, which allows the user to send messages, after
I have an NSDocument which has the following structure: @interface MyDocument : NSDocument {
I have a document-based Cocoa app. During runtime, I load an additional nib from
I have a NSDocument based application with a nib that represents the visual document.
I'm using MacRuby 0.10 and XCode 4 where I have created a default NSDocument-based
I'm wondering if NSDocument is only for applications that are text/document-based. I have an
I've successfully implemented a NSDocument class in my Cocoa App which is also able
I have a menu item whose state should depend on whichever NSDocument is open.
I have a document-based application and I have sub-classed NSDocument and provided the required

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.