How do I prevent windows being restored when my app starts?

It often happens that when I launch a Xojo-made app, e.g. Arbed, that previously opened windows get re-opened as well. I suspect that’s caused by OSX recent introduction of automatically restoring open windows, so it’s not caused by my app, but by OSX.

How do I prevent that? Is there a Info.plist key for that?

This applies to all OS X apps:

System Preferences/General/Close Windows when quitting an application

I’m sorry that I don’t know how to eliminate the behavior for a particular app.

A bird told me that it probably has to do with me using Proxy Icons.

There may be two solutions:

  1. Unset the proxy icon before closing the windows or quitting the app.
  2. Filter the “odoc” AppleEvent and look for a “rsto” parameter in it, which signals that it’s a “document restore”, see http://lists.apple.com/archives/carbon-dev/2011/Aug/msg00040.html

[quote=41163:@Thomas Tempelmann]It often happens that when I launch a Xojo-made app, e.g. Arbed, that previously opened windows get re-opened as well. I suspect that’s caused by OSX recent introduction of automatically restoring open windows, so it’s not caused by my app, but by OSX.

How do I prevent that? Is there a Info.plist key for that?[/quote]

I found a way which works : set non default windows with visible as off in the IDE. In my code, window.show will render them visible, but on launch, OSX does not.

Is this a Carbon or Cocoa app?

AFAIK, Carbon did this automatically, where as Cocoa actually requires more work if you want this function! There is a ‘Defaults’ key (not a plist key), that you can fire in app to disable it per application.

NSQuitAlwaysKeepsWindows

If you set this globally, it will disable the entire system, however if you set this to your apps preferences (via CFPrefs or NSUserDefaults) it should disable it for that app.

I’ve not actually tried it myself…

I forgot to say, set it’s value to NO or False.

Sam, it’s on Carbon, and the global key was already set accordingly.

Ah… Then the only two other things I can think about are:

#1 Remove the document icon from the window, as this is what Resume uses to restore the documents.
#2 In the cancel close event of the app, close all the windows, so that when the app finally exits, there are no windows open for Resume to collect.

On the flip side, if you want Resume on Cocoa, you must associate the document with the Window and you must terminate the app before the Xojo runtime releases all the Windows (there’s other things you must do, but just to illustrate).

For the record, here’s my code for handling this by checking for the “rsto” parameter in the “odoc” event. This code also collects multiple dropped files into one array so that one can tell whether a drop of file(s) was one atomic event (if you implement the OpenDocument event, you cannot tell a single multi-file drop from several individual drops, but this code can).

[code]
// Put this code into App.HandleAppleEvent

const kCoreEventClass = “aevt”
const kAEOpenDocuments = “odoc”
const keyDirectObject = “----”

select case eventClass
case kCoreEventClass
select case eventID
case kAEOpenDocuments
dim rsto as String = theEvent.MacTypeParam(“rsto”)
if rsto = “rdoc” then
// this is a “restore documents” event - ignore it
handleNewDoc // -> handle this like a NewDocument event
return true
end
dim descList as AppleEventDescList = theEvent.DescListParam(keyDirectObject)
if descList <> nil then
dim items() as FolderItem
for i as Integer = 1 to descList.Count
dim f as FolderItem = descList.FolderItemItem(i)
if f <> nil then items.Append f
next
handleOpenDocs items // -> handle the array of files like you’d do in the OpenDocument event
return true
end if
end select
end select[/code]