Quit menu notification with SWT on Mac OS X ?


P

Patrick Stadelmann

Hi,

I have a GUI java application built with SWT that has a single shell. On
Mac OS X, it is packaged as an application bundle, using the Eclipse
export module "Mac OS X application bundle".

I need to perform some actions before the shell is disposed. I found how
to install a handler for the "close" event, sent when the user's click
on the window's close box. However, if he use the Quit menu in the
standard Mac OS X application menu, I don't get notified.

How can I get notified either when the shell is about to be disposed
(whether is due to the Quit menu or to the window's close box), or when
the Quit menu is invoked ?

Thanks,

Patrick
 
Ad

Advertisements

J

John B. Matthews

Patrick Stadelmann said:
Hi,

I have a GUI java application built with SWT that has a single shell. On
Mac OS X, it is packaged as an application bundle, using the Eclipse
export module "Mac OS X application bundle".

I need to perform some actions before the shell is disposed. I found how
to install a handler for the "close" event, sent when the user's click
on the window's close box. However, if he use the Quit menu in the
standard Mac OS X application menu, I don't get notified.

How can I get notified either when the shell is about to be disposed
(whether is due to the Quit menu or to the window's close box), or when
the Quit menu is invoked ?

Thanks,

Patrick

What version of Eclipse?

You'll need to implement java.awt.event.WindowListener and possibly
com.apple.eawt.ApplicationListener.

The platform will handle Preferences flush().

John
 
P

Patrick Stadelmann

"John B. Matthews said:
What version of Eclipse?

I'm using version 3.1.2 / J2SE 1.4.2.
You'll need to implement java.awt.event.WindowListener and possibly
com.apple.eawt.ApplicationListener.

Isn't this for use with AWT ? I didn't find equivalents for SWT...

Thanks for your reply,

Patrick
 
J

John B. Matthews

Patrick Stadelmann said:
I'm using version 3.1.2 / J2SE 1.4.2.


Isn't this for use with AWT ? I didn't find equivalents for SWT...

Thanks for your reply,

Patrick

Oops, misread the question! My principal contribution to an SWT project
was the command-line interface:) I was intrigued to hear that there's
support for building Mac application bundles; I'm still using make...

John
 
P

Patrick Stadelmann

"Peter Duniho said:
Or put
another way, if you have something in your Shell that's still useful when
the application is exiting, that may suggest that whatever that
"something" is, it belongs elsewhere and/or ought not to be interacting
with the Shell.

Thanks for your reply. In my case, it holds controls providing status
from a device. Before the application exits, some commands are sent to
the device, and I'd like the Shell to stay around to show the device
status in case an error occurs at this time.

But the Shell could simply be e.g. a text editor window. If the user
quits before saving the modifications, he needs to be notified before
the Shell disappears...

Patric
 
P

Patrick Stadelmann

Patrick Stadelmann said:
But the Shell could simply be e.g. a text editor window. If the user
quits before saving the modifications, he needs to be notified before
the Shell disappears...

BTW, on Windows the listener the for SWT.Close is called when the user
quits the application using Alt-F4.

Patrick
 
Ad

Advertisements

P

Philipp

Peter said:
An alternative would be to revisit the question of whether you really
need to perform these actions before the Shell instance has been
disposed.

Note that eclipse itself does it that way (saving workspace on exit). So
it's probably not a blatant antipattern.

Phil
 
Ad

Advertisements

P

Patrick Stadelmann

"Peter Duniho said:
However, it's possible that reviewing the Eclipse code would be a way for
the OP to find some direction with respect to his specific goals.

Indeed, the answer is in the Eclipse source code.
At the
very least, it should provide better insight into what exactly happens
when a user on the Mac chooses "Quit" from the application menu, and what
sorts of things one can have their code safely do.

Native applications receive a "quit" handler, before any action is
taken, whatever the cause is (system shutting down, quit menu item
selected in the menu bar or in the Dock, AppleEvent received from
another application or from an AppleScript, etc...

Thank you all for your help,

Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top