| getActiveShell() on linux-gtk [message #458157] | 
Mon, 11 July 2005 01:55   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hello, 
 
I'm having a problem with some code that works fine on the windows version  
of my rcp app but is failing on the linux-gtk version.  I'm wondering if  
it's a bug or if I'm doing something wrong.  Here's the code. 
 
System.out.println("shell: " + Display.getDefault().getActiveShell()); 
                FileDialog dialog = new FileDialog  
(Display.getDefault().getActiveShell(), SWT.SAVE); 
                String fileName = dialog.open(); 
                System.out.println("shell: " +  
Display.getDefault().getActiveShell()); 
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(),  
                SWT.ICON_INFORMATION); 
 
On windows, getActiveShell() returns the shell before and after the  
FileDialog is opened.  On linux, getActiveShell() returns the shell  
before, but returns null after.  Therefor my MessageBox throws an  
exception. 
 
Any ideas?  Thanks. 
 
Chris
 |  
 |  
  | 
| Re: getActiveShell() on linux-gtk [message #458170 is a reply to message #458157] | 
Mon, 11 July 2005 10:54    | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Chris F wrote: 
> On windows, getActiveShell() returns the shell before and after the 
> FileDialog is opened.  On linux, getActiveShell() returns the shell 
> before, but returns null after.  Therefor my MessageBox throws an 
> exception. 
 
Spin the event loop. 
 
Basically, for a shell to become active on Linux GTK+, a request is sent to 
the window manager.  When the window manager sees the request, it might (or 
might not) mark that shell as active.  For this communication to take 
place, the event loop must be making progress. 
 
Note that in some case, the dialog may never become active.  For example, 
two simultaneous requests to make different shells active may result in 
only one shell actually becoming active. 
 
 
 
cheers, 
d.
 |  
 |  
  | 
 | 
 | 
| Re: getActiveShell() on linux-gtk [message #458242 is a reply to message #458239] | 
Mon, 11 July 2005 14:07   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Chris F wrote: 
>>    I would suggest modifying the code to handle getActiveShell()  
>> returning null.  However, if you're seeing some weirdness with respect  
>> to handling FileDialog shells, please file a bug.  :) 
>  
> Would you suggest that I store a reference to the Shell after the first  
> getActiveShell() call and pass it to the MessageBox?  Or is there  
> another preferred way to do this instead of doing MessageBox mb = new  
> MessageBox(Display.getDefault().getActiveShell(), ...); 
 
   Since MessageBox creates a modal dialog, you should explicitly pass  
in the Shell for which it will be modal for.  Using getActiveShell()  
seems strange to me since, if you have multiple windows, you'll just end  
up with whichever one happens to have focus at the time :)  Presumably  
this dialog is because of an interaction with one of your application's  
windows, no? 
 
   -Billy
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.65857 seconds