Page 1 of 1

Why is the ShutdownRequest message called twice

Posted: Tue Nov 18, 2014 7:06 pm
by Simon Knight
Hi,

I have a splash stack that loads my main stack. The main stack uses a revbrowserObject and also has a sub stack. I wish to save the present state when the main stack closes so have added a button that issues the quit command. I have added the following handler :
on shutdownRequest
answer question "Are you sure you want to quit?" with "Yes" or "No"
if it is "Yes" then
Save stack "PDF_Rename"
pass shutdownRequest
end if
end shutdownRequest
If the handler is put in the card it works as I expect but if it is put in the stack then it is being called twice. I have created an empty stack and sub stack and the routine is only called once when it is in the stack. Can anyone explain what might be happening to the message path.

Also is the shutdown message a synonym of shutdownRequest ? The dictionary does not list synonyms for either message but they perform the same action :
ShutdownRequest : Sent to the current card of the defaultStack when the user tries to quit the application.
Shutdown : Sent to the current card of the defaultStack when the application is quitting.
Does this mean that the ShutdownRequest will generate a Shutdown message but not the other way around?

Re: Why is the ShutdownRequest message called twice

Posted: Tue Nov 18, 2014 7:53 pm
by FourthWorld
If the handler is defined in the mainstack it'll inherit all messages passed to it from substacks.

Re: Why is the ShutdownRequest message called twice

Posted: Tue Nov 18, 2014 9:42 pm
by Simon Knight
Ok, but in this case the card with the quit button is the only card of the main stack so I think that the message should be offered to the card first then the main stack and then up to the engine. I wonder if this is a feature of testing in the IDE ?

Re: Why is the ShutdownRequest message called twice

Posted: Tue Nov 18, 2014 9:59 pm
by FourthWorld
Does the behavior differ in the standalone?

Re: Why is the ShutdownRequest message called twice

Posted: Wed Nov 19, 2014 9:05 am
by Simon Knight
I have just tried it and the standalone is the same as the IDE. I will put it down to just one of those things that happen.

Re: Why is the ShutdownRequest message called twice

Posted: Wed Nov 19, 2014 11:16 am
by Simon Knight
Grrrr !

The dictionary hints that the shutdownRequest may be a little tricky and recommends placing the handler in a library stack or back script. I have tried placing the following code in many places :

Code: Select all

on shutdownRequest
   Save  stack "PDF_Rename"
   answer question "Are you sure you want to quit?" with "Yes" or "No"
   if it is "Yes" then 
      pass shutdownRequest 
   end if
end shutdownRequest
Splash stack that load the app - handler is not found by the app as the splash is closed - I expected this but include it in the process of elimination.
In Library Stack - Still called more than once
In the stack - Called more than once
In the Card - Called more than once

My latest build has the handler in the card script and it is called only once but for some reason the Save command has stopped working. I have no idea what is happening but I have a feeling that the Save command is interfering with the message path in some way.

Re: Why is the ShutdownRequest message called twice

Posted: Wed Nov 19, 2014 12:28 pm
by Simon Knight
I decided to follow the dictionary and add the handler to a library stack as I thought I had before. Now it gets called once which is good however the save stack is failing when called in the standalone.

I will post another question on the Mac OS board ref the file save problem.