'Quit' mystery

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

'Quit' mystery

Graham Samuel-4
I have a desktop app (Mac and Windows) which has one main menu: in that menu is a conventional 'File' submenu, ending with 'Quit' (Mac) or 'Exit' (PC). I need to do some housekeeping before the actual quit, so in my menu handler for file I have code like this:

 case "Quit"
 case "Exit"

   <do stuff>

   quit
break

When I create a standalone, all the other items in the 'File' menu, such as 'Save', work as expected, but the 'Quit' just quits, and my "stuff" doesn't get done. This is true both on the Mac (where the 'Quit' menu item gets moved to another menu) and the PC (where it doesn't). I even put a statement at the beginning of the 'File' menu that makes a log entry showing that the menu has been called: again, it works for 'Save' and such, but not for 'Quit' .This log would work even if my spelling of 'Quit' were wrong, for example, so the 'Quit' is being hijacked by the engine somehow and bypassing my menu handler completely.

Thinking I had misunderstood something, I then put in a 'shutdownRequest' handler in the main library stack of my app. I understand from the LC Dictionary that this is fired by the 'quit' command, so now I have

 on shutdownRequest
   <do stuff>
 end shutDownRequest

According to the Dictionary, if I don't pass the shutdownRequest, then the app won't quit. I thought this would be good for debugging purposes. Anyway, this handler is never called, and the standalone just quits as before, so the 'quit' to which my app responds must be somehow in another path. As usual, doubtless I've made an error, but what kind of mistake can it be?

TIA for any assistance

Graham



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Martin Koob
The way I have quit set up in my application is that in the menu handler for the File menu I don't have the 'quit' command in the "quit" case of the switch statement.   I think the engine issues the quit command on its own.

I have the 'shutdownrequest' handler in the card scripts of various cards and they  are triggered when I choose 'Quit' from the File menu in the standalone.

Martin
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Graham Samuel-4
Thanks, Martin - that's helpful. I don't recall leaving 'Quit' out of the 'File' menu in previous cross-platform apps I've written. In fact, the current LC User Guide says:

> The File menu and the "Quit" menu item
>
> On OS X systems, the "Quit" menu item is normally placed in the Application menu (which is maintained by the operating system) rather than in the File menu, as is standard on other platforms. To accommodate this user-interface standard, LiveCode removes the last two menu items of the File menu when a standalone application is running on an OS X system. Therefore, the last menu item in your File menu button should be "Quit". The menu item above it should be a divider line (a dash).
>
When the Guide says "remove", it doesn't explain that this really **means** "remove" and not "move": the difference being that any script you put in the menu handler for the quit item will be lost - I can show this to be true. This certainly needs clarification in the forthcoming rewrite of the User Guide. BTW what happens in your apps on the PC, where the Quit menu item is not moved by the engine?

During this investigation I found out one other thing about this issue:

In the LC Dictionary, it says in the entry on 'shutdownRequest'

> In standalones, some care is needed to ensure you receive the shutdownRequest message if your application uses multiple stacks. The most reliable approach is to install a library stack or backscript to handle the message when your application starts up.

Well, my menu is in one stack (say A), and my shutdownRequest is in another (say B): these are separate mainstacks. However, in a preOpenStack handler in A, I make sure that I put the script of B into back. This clearly works for my own scripted handlers, as the script of B is a library containing handlers used successfully throughout the app and frequently called from A. However, in the situation described below, shutDownRequest is not invoked. I now find that if I move the shutdownRequest handler to A, where the menu is, it **does** get invoked on quit. So this is a bug, but maybe only (!) in the Dictionary. I am not looking forward to abstracting this for a bug report, but I guess I should do so.

Thanks again

Graham

On 26 Nov 2013, at 16:15, Martin Koob wrote:

> The way I have quit set up in my application is that in the menu handler for
> the File menu I don't have the 'quit' command in the "quit" case of the
> switch statement.   I think the engine issues the quit command on its own.
>
> I have the 'shutdownrequest' handler in the card scripts of various cards
> and they  are triggered when I choose 'Quit' from the File menu in the
> standalone.
>
> Martin


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Martin Koob
In reply to this post by Graham Samuel-4
Hi

It has been a long time since I set this up in my application so I don't remember exactly the logic as to why I set this up this way but it seems to work.  The main stack has several substacks which may be open when quit is selected from the menu.

Each of the substacks' scripts have a shutdownRequest handler but not a 'pass shutdownRequest' command.  This handler sends a prepareToQuit command to the main card of the main stack.

substack stack script
-------------------
on shutdownRequest
   send "preparetoquit" to card "main" of stack "mainstack"
end shutdownRequest
------------------
The main card of the main stack has the prepareToQuit handler which just has a quit command.  This triggers the shutdownRequest handler in the main card.   This shutdownRequest handler has all of the code you want implemented before quitting.  This handler has the 'pass shutdownRequest' command that allows the application to quit.

Mainstack >card "main" script
-----------------------
on preparetoquit
    quit
end preparetoquit

on shutdownRequest
    <do stuff here>

    pass shutdownRequest
end shutdownRequest
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Howard Bornstein-2
This really helped me out. Thanks Martin! I couldn't get my standalone to
quit no matter what. This did the trick.

On Tue, Nov 26, 2013 at 10:19 AM, Martin Koob <[hidden email]> wrote:

> Hi
>
> It has been a long time since I set this up in my application so I don't
> remember exactly the logic as to why I set this up this way but it seems to
> work.  The main stack has several substacks which may be open when quit is
> selected from the menu.
>
> Each of the substacks' scripts have a shutdownRequest handler but not a
> 'pass shutdownRequest' command.  This handler sends a prepareToQuit command
> to the main card of the main stack.
>
> substack stack script
> -------------------
> on shutdownRequest
>    send "preparetoquit" to card "main" of stack "mainstack"
> end shutdownRequest
> ------------------
> The main card of the main stack has the prepareToQuit handler which just
> has
> a quit command.  This triggers the shutdownRequest handler in the main
> card.
> This shutdownRequest handler has all of the code you want implemented
> before
> quitting.  This handler has the 'pass shutdownRequest' command that allows
> the application to quit.
>
> Mainstack >card "main" script
> -----------------------
> on preparetoquit
>     quit
> end preparetoquit
>
> on shutdownRequest
>     <do stuff here>
>
>     pass shutdownRequest
> end shutdownRequest
>
>
>
>
> --
> View this message in context:
> http://runtime-revolution.278305.n4.nabble.com/Quit-mystery-tp4672924p4672933.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
Regards,

Howard Bornstein
-----------------------
www.designeq.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

paolomazza
Nearly 1 year ago I posted this
http://quality.runrev.com/show_bug.cgi?id=14263  .
It was confirmed but probably it has not been fixed yet.
All the best,
Paolo

On Thu, Nov 5, 2015 at 4:47 AM, Howard Bornstein <[hidden email]> wrote:

> This really helped me out. Thanks Martin! I couldn't get my standalone to
> quit no matter what. This did the trick.
>
> On Tue, Nov 26, 2013 at 10:19 AM, Martin Koob <[hidden email]> wrote:
>
>> Hi
>>
>> It has been a long time since I set this up in my application so I don't
>> remember exactly the logic as to why I set this up this way but it seems to
>> work.  The main stack has several substacks which may be open when quit is
>> selected from the menu.
>>
>> Each of the substacks' scripts have a shutdownRequest handler but not a
>> 'pass shutdownRequest' command.  This handler sends a prepareToQuit command
>> to the main card of the main stack.
>>
>> substack stack script
>> -------------------
>> on shutdownRequest
>>    send "preparetoquit" to card "main" of stack "mainstack"
>> end shutdownRequest
>> ------------------
>> The main card of the main stack has the prepareToQuit handler which just
>> has
>> a quit command.  This triggers the shutdownRequest handler in the main
>> card.
>> This shutdownRequest handler has all of the code you want implemented
>> before
>> quitting.  This handler has the 'pass shutdownRequest' command that allows
>> the application to quit.
>>
>> Mainstack >card "main" script
>> -----------------------
>> on preparetoquit
>>     quit
>> end preparetoquit
>>
>> on shutdownRequest
>>     <do stuff here>
>>
>>     pass shutdownRequest
>> end shutdownRequest
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://runtime-revolution.278305.n4.nabble.com/Quit-mystery-tp4672924p4672933.html
>> Sent from the Revolution - User mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
>
> --
> Regards,
>
> Howard Bornstein
> -----------------------
> www.designeq.com
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Howard Bornstein-2
I've updated the bug report with Martin's solution in case anyone else runs
into this.

On Thu, Nov 5, 2015 at 5:20 AM, paolo mazza <[hidden email]>
wrote:

> Nearly 1 year ago I posted this
> http://quality.runrev.com/show_bug.cgi?id=14263  .
> It was confirmed but probably it has not been fixed yet.
> All the best,
> Paolo
>
> On Thu, Nov 5, 2015 at 4:47 AM, Howard Bornstein <[hidden email]>
> wrote:
> > This really helped me out. Thanks Martin! I couldn't get my standalone to
> > quit no matter what. This did the trick.
> >
> > On Tue, Nov 26, 2013 at 10:19 AM, Martin Koob <[hidden email]> wrote:
> >
> >> Hi
> >>
> >> It has been a long time since I set this up in my application so I don't
> >> remember exactly the logic as to why I set this up this way but it
> seems to
> >> work.  The main stack has several substacks which may be open when quit
> is
> >> selected from the menu.
> >>
> >> Each of the substacks' scripts have a shutdownRequest handler but not a
> >> 'pass shutdownRequest' command.  This handler sends a prepareToQuit
> command
> >> to the main card of the main stack.
> >>
> >> substack stack script
> >> -------------------
> >> on shutdownRequest
> >>    send "preparetoquit" to card "main" of stack "mainstack"
> >> end shutdownRequest
> >> ------------------
> >> The main card of the main stack has the prepareToQuit handler which just
> >> has
> >> a quit command.  This triggers the shutdownRequest handler in the main
> >> card.
> >> This shutdownRequest handler has all of the code you want implemented
> >> before
> >> quitting.  This handler has the 'pass shutdownRequest' command that
> allows
> >> the application to quit.
> >>
> >> Mainstack >card "main" script
> >> -----------------------
> >> on preparetoquit
> >>     quit
> >> end preparetoquit
> >>
> >> on shutdownRequest
> >>     <do stuff here>
> >>
> >>     pass shutdownRequest
> >> end shutdownRequest
> >>
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://runtime-revolution.278305.n4.nabble.com/Quit-mystery-tp4672924p4672933.html
> >> Sent from the Revolution - User mailing list archive at Nabble.com.
> >>
> >> _______________________________________________
> >> use-livecode mailing list
> >> [hidden email]
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>
> >
> >
> >
> > --
> > Regards,
> >
> > Howard Bornstein
> > -----------------------
> > www.designeq.com
> > _______________________________________________
> > use-livecode mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
Regards,

Howard Bornstein
-----------------------
www.designeq.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Mark Smith
In reply to this post by Howard Bornstein-2
I am just coming back to LC after a few months off (18 perhaps?) so I am a bit rusty but is it not the case that the message path goes from substacks to the main stack? If so, should not a "shutdownRequest" message not handled in a sub stack be passed up the message path to the main stack? In which case you don't need shutdownRequests in each sub, just in the main? I am actually at the very point where I need to implement a somewhat similar feature (pressing the "home" key on an iDevice shuts-down your application - and I need to handle that gracefully. Hoping, hoping I do not need to code a shutdown message handler in every substack)

Mark

Howard Bornstein-2 wrote
> Each of the substacks' scripts have a shutdownRequest handler but not a
> 'pass shutdownRequest' command.  This handler sends a prepareToQuit command
> to the main card of the main stack.
>
> substack stack script
> -------------------
> on shutdownRequest
>    send "preparetoquit" to card "main" of stack "mainstack"
> end shutdownRequest
> ------------------
> The main card of the main stack has the prepareToQuit handler which just
> has
> a quit command.  This triggers the shutdownRequest handler in the main
> card.
> This shutdownRequest handler has all of the code you want implemented
> before
> quitting.  This handler has the 'pass shutdownRequest' command that allows
> the application to quit.
>
> Mainstack >card "main" script
> -----------------------
> on preparetoquit
>     quit
> end preparetoquit
>
> on shutdownRequest
>     <do stuff here>
>
>     pass shutdownRequest
> end shutdownRequest
>
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

J. Landman Gay
On 11/11/2015 7:54 PM, Mark Smith wrote:
> is it not the case that the message path goes from substacks
> to the main stack? If so, should not a "shutdownRequest" message not handled
> in a sub stack be passed up the message path to the main stack? In which
> case you don't need shutdownRequests in each sub, just in the main?

Yes, that's how it should work. I've been wondering why the extra
handlers in substacks were required, I've never needed to do that and my
apps have always quit. I'd say go with the simpler solution and if that
doesn't work then we can figure out why.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Howard Bornstein-2
The dictionary says this (from LC 6.7.5):

In standalones, some care is needed to ensure you receive the
*shutdownRequest* message if your application uses multiple stacks. The
most reliable approach is to install a library stack or backscript to
handle the message when your application starts up.

I couldn't get this to work, so I went with Martin Koob's solution, which
did work. Note that this refers to multi-stack standalones.

On Wed, Nov 11, 2015 at 7:51 PM, J. Landman Gay <[hidden email]>
wrote:

> On 11/11/2015 7:54 PM, Mark Smith wrote:
>
>> is it not the case that the message path goes from substacks
>> to the main stack? If so, should not a "shutdownRequest" message not
>> handled
>> in a sub stack be passed up the message path to the main stack? In which
>> case you don't need shutdownRequests in each sub, just in the main?
>>
>
> Yes, that's how it should work. I've been wondering why the extra handlers
> in substacks were required, I've never needed to do that and my apps have
> always quit. I'd say go with the simpler solution and if that doesn't work
> then we can figure out why.
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
Regards,

Howard Bornstein
-----------------------
www.designeq.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

J. Landman Gay
That's what I suspected; the stacks aren't actually substacks. Now it
makes sense. Thanks for the clarification.

On 11/11/2015 10:59 PM, Howard Bornstein wrote:

> The dictionary says this (from LC 6.7.5):
>
> In standalones, some care is needed to ensure you receive the
> *shutdownRequest* message if your application uses multiple stacks. The
> most reliable approach is to install a library stack or backscript to
> handle the message when your application starts up.
>
> I couldn't get this to work, so I went with Martin Koob's solution, which
> did work. Note that this refers to multi-stack standalones.
>
> On Wed, Nov 11, 2015 at 7:51 PM, J. Landman Gay <[hidden email]>
> wrote:
>
>> On 11/11/2015 7:54 PM, Mark Smith wrote:
>>
>>> is it not the case that the message path goes from substacks
>>> to the main stack? If so, should not a "shutdownRequest" message not
>>> handled
>>> in a sub stack be passed up the message path to the main stack? In which
>>> case you don't need shutdownRequests in each sub, just in the main?
>>>
>>
>> Yes, that's how it should work. I've been wondering why the extra handlers
>> in substacks were required, I've never needed to do that and my apps have
>> always quit. I'd say go with the simpler solution and if that doesn't work
>> then we can figure out why.
>>
>> --
>> Jacqueline Landman Gay         |     [hidden email]
>> HyperActive Software           |     http://www.hyperactivesw.com
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
>


--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: 'Quit' mystery

Howard Bornstein-2
In my case, my second stack *was* a substack and quit still didn't work.

On Wed, Nov 11, 2015 at 9:42 PM, J. Landman Gay <[hidden email]>
wrote:

> That's what I suspected; the stacks aren't actually substacks. Now it
> makes sense. Thanks for the clarification.
>
> On 11/11/2015 10:59 PM, Howard Bornstein wrote:
>
>> The dictionary says this (from LC 6.7.5):
>>
>> In standalones, some care is needed to ensure you receive the
>> *shutdownRequest* message if your application uses multiple stacks. The
>>
>> most reliable approach is to install a library stack or backscript to
>> handle the message when your application starts up.
>>
>> I couldn't get this to work, so I went with Martin Koob's solution, which
>> did work. Note that this refers to multi-stack standalones.
>>
>> On Wed, Nov 11, 2015 at 7:51 PM, J. Landman Gay <[hidden email]
>> >
>> wrote:
>>
>> On 11/11/2015 7:54 PM, Mark Smith wrote:
>>>
>>> is it not the case that the message path goes from substacks
>>>> to the main stack? If so, should not a "shutdownRequest" message not
>>>> handled
>>>> in a sub stack be passed up the message path to the main stack? In which
>>>> case you don't need shutdownRequests in each sub, just in the main?
>>>>
>>>>
>>> Yes, that's how it should work. I've been wondering why the extra
>>> handlers
>>> in substacks were required, I've never needed to do that and my apps have
>>> always quit. I'd say go with the simpler solution and if that doesn't
>>> work
>>> then we can figure out why.
>>>
>>> --
>>> Jacqueline Landman Gay         |     [hidden email]
>>> HyperActive Software           |     http://www.hyperactivesw.com
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>>
>>
>>
>>
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
Regards,

Howard Bornstein
-----------------------
www.designeq.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode