Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [platform-swt-dev] FileDialog/DirectoryDialog under Debian

SYSTEM_MODAL and ON_TOP don't work directly on FileDialogs, that's why I
created a parent Shell.
The weird thing is that the code I provided in my first message works well
under Windows, but as FileDialog is system dependent, it's not really
surprising to have different behaviour.
I also noticed that because I have no "global" shell for the whole
application, SWT doesn't really have an UI thread (it gets one as soon as a
Display is created). And I don't think that right. Moreover, as you said,
the UI thread needs to dispatch events (even if in this case, Windows
doesn't mind, but GTK does).
So I followed your advice and changed the application's main loop to
something like this:

final Display display = new Display();
final Shell shell = new Shell(display, SWT.NONE);
shell.setLayout(new GridLayout(1, false));
shell.setBounds(0, 0, 1, 1);

// Note that I don't open the Shell! It seems not necessary...

try {
	// Launch another thread to receive requests from other
// applications such as "open FileDialog"...
	// It can also receive a "terminate" request that disposes
	// the shell to terminate the application.
	startServiceRequestHandlerThread(shell);

	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	return EXIT_OK;
} finally {
	stopServiceRequestHandlerThread();
	display.dispose();
}

And this works quite well, except that "ON_TOP" works only for the first
FileDialog that is opened :(
And SYSTEM_MODAL always works...
On windows, nothing changes, this works as expected...

Here is the new code of the "open FileDialog" service:

display.syncExec(new Runnable() {
	@Override
	public void run() {
		// The parent shell is now the application's main Shell.
		final Shell internalShell = new Shell(getShell(),
SWT.SYSTEM_MODAL | SWT.ON_TOP);
		try {
			// Shell is not made visible.
			// We only show the file dialog.

			final FileDialog fd = new FileDialog(internalShell,
style);
			// ... Setting "fd" properties ...

			fd.open();

			final String[] selectedFiles = fd.getFileNames();

			// ... Processing selected files ...

		} finally {
			internalShell.close();
			internalShell.dispose();
		}
	}
});



-----Message d'origine-----
De : platform-swt-dev-bounces@xxxxxxxxxxx
[mailto:platform-swt-dev-bounces@xxxxxxxxxxx] De la part de Jacob
Envoyé : vendredi 30 octobre 2009 12:40
À : Eclipse Platform SWT component developers list.
Objet : Re: [platform-swt-dev] FileDialog/DirectoryDialog under Debian

If you don't want any window/shell but a FileDialog you could modify
FileDialog's super class Dialog and remove the checkParent call in the
constructor, that way you can pass in null as the parent and have a
dialog without a parent shell. You won't be needing an event loop for
this either (but you may need one anyway for other things and keeping
the application alive). I don't know how portable it is but I've
tested it with Dialog on Cocoa, GTK and Win32 and FileDialog on Cocoa.
I also don't know how this will work with system modal, if it's
possible.


/Jacob Carlborg

2009/10/29 Stéphane WASSERHARDT <stephane.wasserhardt@xxxxxxxxxxxx>
>
> Yes I know I have to close the shell: take a look at the code I provided,
I close the shell in a “finally” block (and in an useless “asyncExec
Runnable”). But note that I never open the shell before! This may be the
problem, but I don’t want to show an empty shell just to open a FileDialog.
>
> In fact, the application has no UI until I open the FileDialog, the
application is only meant to show FileDialogs (and some little other things)
when asked.
>
> And that’s why it’s “system modal”: I have another running application
which must not be active while the FileDialog is open. I know this can seem
a bit mysterious, but I cannot do it another way: I must have two
independent applications since each one is run under distinct user accounts
(but on the same computer)… If you want more details about this, I can
explain it...
>
>
>
> If there are no workarounds, I think I’ll have to open this “useless
Shell” before showing the dialog. I already tried to set its size to (0, 0)
and open it, but GTK doesn’t like to show 0-sized widgets…
>
>
>
> ________________________________
>
> De : platform-swt-dev-bounces@xxxxxxxxxxx
[mailto:platform-swt-dev-bounces@xxxxxxxxxxx] De la part de Bogdan Gheorghe
> Envoyé : jeudi 29 octobre 2009 17:25
> À : Eclipse Platform SWT component developers list.
> Objet : RE: [platform-swt-dev] FileDialog/DirectoryDialog under Debian
>
>
>
> You have to explicitly close the shell, it won't close for free - try the
attached snippet below. BTW, I'm not sure why you are parenting the dialog
on a SYSTEM_MODAL, ON_TOP shell - this seems wrong. System modal means modal
to all other windows on your desktop! A  FileDialog will be modal to all
other shells in your app (depending on which version of GTK you are running,
a shell might seem to take focus, but you shouldn't be able to click on any
other controls. If you can please open a bug).
>
>
> public static void main(String[] args) {
>
>         Display display = new Display();
>         final Shell shell = new Shell(display, SWT.ON_TOP |
SWT.SYSTEM_MODAL);
>         shell.setLayout(new GridLayout(1, false));
>         shell.setBounds(50, 50, 100, 100);
>         shell.open();
>
>         final FileDialog dialog = new FileDialog(shell, SWT.OPEN);
>         String s= dialog.open();
>         System.out.println(s);
>         if (s != null) {
>                 shell.close();
>         }
>
>         while (!shell.isDisposed()) {
>                 if (!display.readAndDispatch())
>                         display.sleep();
>         }
>         display.dispose();
> }
>
>
> From:
>
> Stéphane WASSERHARDT <stephane.wasserhardt@xxxxxxxxxxxx>
>
> To:
>
> "'Eclipse Platform SWT component developers list.'"
<platform-swt-dev@xxxxxxxxxxx>
>
> Date:
>
> 10/28/2009 10:03 AM
>
> Subject:
>
> RE: [platform-swt-dev] FileDialog/DirectoryDialog under Debian
>
> Sent by:
>
> platform-swt-dev-bounces@xxxxxxxxxxx
>
>
>
> ________________________________
>
>
> I just tried with SWT.NONE instead of SYSTEM_MODAL and ON_TOP, but this
didn’t change anything L
>
>
>
>
> ________________________________
>
> De : platform-swt-dev-bounces@xxxxxxxxxxx
[mailto:platform-swt-dev-bounces@xxxxxxxxxxx] De la part de Stéphane
WASSERHARDT
> Envoyé : mercredi 28 octobre 2009 14:50
> À : SWT
> Objet : [platform-swt-dev] FileDialog/DirectoryDialog under Debian
>
> Hello,
>
> I have a problem with both FileDialog and DirectoryDialog under Debian
Lenny (GTK2) : when such dialog is closed (either when double clicking an
item, using select or cancel button, or simply closing it), the “open”
method returns with the expected result, but the shell remains open !
> The shell is not repainted anymore, so it seems to be “disposed”, but it’s
still visible…
> Moreover, if I open another file or directory dialog, the previous one
disappears!
> Note that the parent shell is created with style “SWT.SYSTEM_MODAL |
SWT.ON_TOP” (and I’d like to keep this style…)
>
> I tried with both SWT 3.4.2 and SWT 3.5.1…
>
> Here is the code I’m using :
>
> // The following Shell is not made visible. We only show the file dialog.
> final Shell shell = new Shell(display, SWT.SYSTEM_MODAL | SWT.ON_TOP);
>             try {
>                   final FileDialog fd = new FileDialog(shell, SWT.OPEN);
>
> // ... Setting of file dialog properties : text, filterPath, etc. ...
>
>                   fd.open(); // Opens correctly, and return normally, but
the dialog remains open !
>
> // Get the correct result.
>                   final String[] selectedFiles = fd.getFileNames();
>
>                   // ... Process the result ...
>
>             } finally {
>                   // I tried to close the parent shell in a async runnable
just in case... But it doesn’t change anything.
>                   display.asyncExec(new Runnable() {
>                         @Override
>                         public void run() {
>                              shell.close();
>                              shell.dispose();
>                         }
>                   });
>             }
>
> I’m currently trying to remove “SWT.SYSTEM_MODAL | SWT.ON_TOP” just to see
if it changes something, but I really need the dialog to be displayed on top
and to block other running applications…
>
> Any help is welcome! Thanks in advance!
>
> Stephane_______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
>
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev



Back to the top