Closing main stack and reopening from dock

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Closing main stack and reopening from dock

Post by nower » Wed May 22, 2013 11:13 pm

I am working on my first LiveCode application and it is intended to be cross-platform.
My primary platform is Windows, and there is one behavior on Mac OS X that I haven't figured out how to handle.

When I close the main stack on Windows, for example by clicking the "X" on the main stack window, the application is terminated completely.
When I close the main stack on OS X by clicking the red little circle on the main stack window, the stack window is closed, but the app is not terminated. It just seems to be suspended, or whatever state it is in. And the app icon is still on the dock and shows that the app is active.

How can I reopen the stack window when the user clicks the app icon on the dock while the app is in this state? That's what native OS X apps seems to do, but I haven't been able to figure out what message I might need to trap or what else I might need to do to accomplish that.

Thanks for any insights!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Closing main stack and reopening from dock

Post by Mark » Sat May 25, 2013 12:41 am

Hi,

For example:

Code: Select all

on closeStackRequest
  quit
end closeStackRequest
but this is a bit rigorous. You should read up on closeStackRequest and shutDownRequest in the dictionary. Later you might also try to learn more about Apple events (search for appleEvent in the dictionary).

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: Closing main stack and reopening from dock (appleEvent)

Post by nower » Sat May 25, 2013 4:00 pm

Hi Mark, thank you very much, your pointers allowed me to solve the issue the right way!

I added a handler for appleEvents to the app, and now it works as it should. In this case I am only handling the "rapp" event that is sent when an app is reopened, as the events for open and quit seem to be handled by LiveCode automatically.

Code: Select all

on appleEvent theClass,theID  
   switch
      case theClass is "aevt" and theID is "rapp"
         go to card "MyCard" of stack "MyStack"
      default
         pass appleEvent
   end switch
end appleEvent

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Closing main stack and reopening from dock

Post by Mark » Sat May 25, 2013 4:35 pm

Hi,

You solved it very nicely, but a simplel if statement instead of a switch structure would have been sufficient.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: Closing main stack and reopening from dock

Post by nower » Sat May 25, 2013 4:35 pm

By the way, the MacTech Journal has a book online: "MACINTOSH C: A Hobbyist's Guide To Programming the Mac OS in C".
Chapter 10 of it explains appleEvents.
Even though the book is already pretty old, I found it very helpful in getting a basic understanding of the topic.

It seems I am not allowed to post links here, but you should be able to find it pretty easily if you want to take a look.

nower
Posts: 47
Joined: Wed May 22, 2013 11:02 pm

Re: Closing main stack and reopening from dock

Post by nower » Sat May 25, 2013 7:51 pm

Yeah, when I started writing the handler, I expected to handle more than one appleEvent, hence the switch statement.
I left it in place even though at this time I actually only needed to handle the rapp.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Closing main stack and reopening from dock

Post by Mark » Sat May 25, 2013 8:03 pm

Hi,

Don't worry, both ways work fine :-)

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Mac OS”