Preventing a shell from closing [message #480109] |
Thu, 13 August 2009 16:42  |
Eclipse User |
|
|
|
Hi!
I'm trying to make a window which cannot be closed using the close button in
the title bar. According to what I can find on the web, the following should
work:
getShell().addShellListener(new ShellAdapter()
{
@Override
public void shellClosed(ShellEvent e)
{
e.doit = false;
}
});
However, at least in GTK, the method is called only *after* the shell has
already been disposed (verified through e.widget.isDisposed()). I haven't
yet had a chance to try in Windows.
Also, GTK always displays a close button, regardless of whether the shell's
style includes one or not. This may be correct behaviour, however I really
need a working way to prevent the shell from closing when it is clicked.
Thanks,
Marian.
--
Hofstadter's law: "It always takes longer than you think,
even when you take account of Hofstadter's law".
|
|
|
|
Re: Preventing a shell from closing [message #480188 is a reply to message #480112] |
Fri, 14 August 2009 06:18  |
Eclipse User |
|
|
|
Phillipus wrote:
> Marian Schedenig wrote:
>> getShell().addShellListener(new ShellAdapter()
>> {
>> @Override
>> public void shellClosed(ShellEvent e)
>> {
>> e.doit = false;
>> }
>> });
>
> I tested on Windows 7. It works as expected. Could be Linux bug. Make a
> test snippet and post it here.
My mistake. I wrote an SWT test snippet and it worked. Turns out this is a
JFace feature: The Window#canHandleShellCloseEvent()
Window#handleShellCloseEvent() are provided for dealing with the close
button. Apparently, Window registers a shell listener itself for handling
the close event, so regardless of my own listener, JFace's own listener got
called - and the default behaviour of handleShellCloseEvent() is to close
the window.
Two possible solutions:
1) Override canHandleShellCloseEvent() to return false, then implement
custom behaviour in a standard SWT shell listener.
2) Override handleShellCloseEvent() and put your own custom behaviour right
there.
Sorry for the alarm. :)
Marian.
--
Hofstadter's law: "It always takes longer than you think,
even when you take account of Hofstadter's law".
|
|
|
Powered by
FUDForum. Page generated in 0.03258 seconds