Unexpected quit on closing last document


#1

It seems that when you close the last open document the Subform application quits. I'm not sure if this is intentional, but for a document-based application that can have multiple open documents this is unexpected behavior to me (at least on Mac?) and it feels like it crashes. Instead, if the user closes the last open document the application should remain open with just the menu bar, letting the user open a new document or create a new one.


#2

I agree, although Apple themselves are now maddeningly inconsistent about following their former human interface guidelines... I just checked and iTunes, iBooks, Mail, Keynote, Activity Monitor, and TextEdit stay open after the last window closes, while Notes, Calendar, FaceTime, Maps, Disk Utility, and Photos quit. Xcode stays open until it is backgrounded, then quits. :confused:

Looks like the more recently designed/redesigned apps mostly favor the quit-on-last-window-closed behavior, as of El Capitan. But it's far from being standardized.


#3

As @eliotlash noted, the behavior is inconsistent between different applications, so it wasn't clear to me what the "right" behavior was when I originally implemented the window behavior.

The reason I went with quitting Subform after closing the last window is because many of the menu items only make sense in the context of an active document (e.g., save) so it was less work for me to simply quit everything than it was to think through all of the menu items and gray out or remove the ones that don't make sense.

Open to changing it at some point, but if the only argument right now is "it's consistent...kind of" then it'll be low priority.
If there are other reasons to change the behavior, I'd love to hear 'em!


#4

Well, yes, it's inconsistent between applications, but not among document-based applications. The applications that quit are single-window applications (like Calendar or Photos), and they quit when you close their only/main window. Applications where you edit and maintain documents in multiple windows at once (like TextEdit, the Adobe Apps or Subform) do not. I was surprised to hear XCode now does it, and when I tired it now it doesn't for me.

This is also the way a document-based application works if you create a new one in XCode (Just create a new project and check the little "Document based application" checkbox). That also sets up all the enabling/disabling of menu items you mention, like Save/Save as/Close, Undo/Redo, maintaining a list of open documents in the Window menu etc for you. All you need to do is set up your NSDocument subclass properly to let the NSDocumentController know when the document has unsaved changes. It even handles the prompts for saving changes if you close documents, so you don't have to handle that yourself.

You can read more on how it works here.
https://developer.apple.com/library/content/documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/KeyObjects/KeyObjects.html#//apple_ref/doc/uid/TP40011179-CH3-SW2


#5

Ah, that makes a bit more sense. It's still not 100% consistent though vis a vis Xcode. On El Capitan, I observed Automator and Pages to also have the "close on background with no windows" behavior.


#6

I'm also on El Capitan and I can report that Pages, XCode, and Automator all stay open with no windows, so I'm not sure what you're seeing.


#7

You're right, I no longer see this behavior. Must have been a glitch. I guess Subform should probably stay open after the last window is closed then as it is a multi-document editor.