Ecir Hana
Ecir Hana

Reputation: 11468

Open untitled file in Document-based app

I want my app to open new untitled document every time it starts. It worked in 10.6 but now I upgraded to 10.8 and when I close the window with Command+W and then restart the application it won't open any windows.

How do I make it open a new window every time the app starts, regardless of how it exited previously?

I tried to return YES in both applicationShouldOpenUntitledFile: and applicationOpenUntitledFile: of the app delegate without luck.

Upvotes: 1

Views: 1400

Answers (2)

Marek H
Marek H

Reputation: 5576

Reasons why document based app won't open new untitled window:

Appdelegate method returns false

  func applicationShouldOpenUntitledFile(_ sender: NSApplication) -> Bool {
        return false 
  }

Other reason might be this: No restoration window found + some code presented other window -> no newDocument window will be created. In this case call NSDocumentController.shared.newDocument(self)

Upvotes: -1

Keith Smiley
Keith Smiley

Reputation: 63954

I'm not sure exactly what changed since 10.6 but the issue is that the return value of applicationOpenUntitledFile: is suppose to be based on whether your manual open of a new window was successful.

In your implementation of applicationOpenUntitledFile: you should open a new window with an untitled document yourself. The documentation for this is under NSApplicationDelegate

Upvotes: 1

Related Questions