Search code examples
objective-cnotificationsnsnotificationsnsdocument

Closing specific NSDocument instance with notifications


I have the following issue. I am trying to reproduce an XCode-like "new project" workflow in a small IDE I build. For this I have a sheet that runs modal in the window created by the doc window controller when user selects "New project". The sheet is inited from a nib and loads several subviews (via view controllers) in a stepwise approach, to set up the project (type -> parameters ... etc) to the point of saving the new project. So far so good.

The problem I have is when I try to cancel the process BEFORE saving. I cannot figure how to close the modal sheet and the doc instance WITHOUT closing other doc instances (aka "projects") that might be opened.

My app has a delegate, a NSDocument class that is controlled via a NSWindowController and several other controllers and nibs. For now, I am thinking of implementing a notification-based approach in the application delegate, but I cannot get to a grip.

I would appreciate if you could point me in the right direction.

Warmest regards,

Tom


Solution

  • You could also call an action method when the cancel button is pressed. This way the action method manages to close the sheet and close your NSDocument subclass instance.