Question

I'm trying to get SWT's DirectoryDialog to open without the "Make new folder" button showing on Windows. Windows' API supports this but unfortunately SWT doesn't.

You can see SWT's Windows implementation here: http://kickjava.com/src/org/eclipse/swt/widgets/DirectoryDialog.java.htm

Line 193 is where the magic happens.

 lpbi.ulFlags = OS.BIF_NEWDIALOGSTYLE | OS.BIF_RETURNONLYFSDIRS | OS.BIF_EDITBOX | OS.BIF_VALIDATE;

I would like to add BIF_NONEWFOLDERBUTTON to the flags (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb773205(v=vs.85).aspx).

I've tried achieving this through an ugly reflection hack where I added BIF_NONEWFOLDERBUTTON to OS.BIF_NEWDIALOGSTYLE by doing a bitwise OR to the static field.

Unfortunately that had no effect. I'm assuming it's because Java inlines it (since it's compile time constant).

My question is therefore: how do I modify line 193 at runtime so that it includes this constant?

Was it helpful?

Solution 2

I think the only way you could do this is to make your own copy of DirectoryDialog and modify that. I have not tried this on Windows but similar code works on Mac OS X.

Since this class uses internal classes (especially the OS class) this would be breaking the Eclipse API Rules of Engagement. Your code might be broken by changes to the internal classes in new releases.

The class would also be specific to a particular OS and architecture (Windows 32 bit or Windows 64 bit). This can be managed by using plugins or fragments specific to the OS and architecture.

OTHER TIPS

I don't think it's possible. If you could access lpbi somehow (e.g. if it was a field instead of a local variable), you could do it. If you have a separate application and not an Eclipse plugin, you could "just" patch SWT and include your patched version in the application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top