简体   繁体   中英

Prevent NSDocument from being created when application gets active

When a document based application becomes active, and there are no open windows, a new document window is automatically created. I want to prevent this behavior and show my "Choose a Template" dialog instead of creating a blank document by default.

As you can see on the screenshot, the new document is created somewhere in NSApplicationMain .

在此处输入图片说明

How can I prevent this and show my window instead?

Found the answer myself, I was just looking in the wrong place. The creation of untitled documents is handled in the application delegate, so returning false from

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

did the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM