Bug 577190 - FileDialog.setFilterPath doesn't work as expected on Windows
Summary: FileDialog.setFilterPath doesn't work as expected on Windows
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.21   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 4.23 M2   Edit
Assignee: Nikita Nemkin CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
: 578045 578415 (view as bug list)
Depends on:
Blocks: 579359
  Show dependency tree
 
Reported: 2021-11-10 09:42 EST by Dennis Hendriks CLA
Modified: 2022-12-02 04:14 EST (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dennis Hendriks CLA 2021-11-10 09:42:30 EST
If I create a FileDialog and use setFilterPath to set a directory, I expect the file dialog to open with that directory shown. If I use the dialog to determine a filename to save a file, that works the first time.

If I try a second time, and since I didn't change directories the first time, it works again. This second time I choose a different folder.

I try a 3rd time. It unexpectedly shows the folder where I last saved the file, not the path set via setFilterPath.

If I terminate my Eclipse runtime and restart it, the problem is still there. If I reboot my system and try again, still it uses the last used folder location rather than what I set via setFilterPath.

I use Windows 10.
Comment 1 Andrey Loskutov CLA 2021-11-10 09:48:39 EST
Is this a regression? If yes, it could be due bug 571571 changes in 4.20.
Comment 2 Dennis Hendriks CLA 2021-11-10 12:14:51 EST
I checked:

Eclipse ESCET v0.1 -> based on Eclipse Platform 2020-06/4.16 (issue present)
Eclipse ESCET v0.2 -> based on Eclipse Platform 2021-06/4.20 (issue present)

So it seems it does not seem to be a regression in Eclipse 2021-06/4.20.
Comment 3 Nikita Nemkin CLA 2021-11-11 08:27:01 EST
Windows dialogs remember the last used folder natively and use that remembered folder as long as you keep passing the same folder to setFilter. I'm pretty sure this behavior hasn't changed when I migrated to COM API, I'll re-check.

Whether setFilter should yield to natively remembered folder or behave like a hard override is another question.
Comment 4 Dennis Hendriks CLA 2021-11-11 08:43:44 EST
> Whether setFilter should yield to natively remembered folder or behave like a hard override is another question.

Would it technically be possible to have such a hard override?
Comment 5 Nikita Nemkin CLA 2021-11-11 09:00:24 EST
(In reply to Dennis Hendriks from comment #4)
> > Whether setFilter should yield to natively remembered folder or behave like a hard override is another question.
> 
> Would it technically be possible to have such a hard override?

Yes. But SWT only has one setFilter function. If it wasn't a hard override before, we'll need a good reason to change it.
Comment 6 Dennis Hendriks CLA 2021-11-11 09:55:36 EST
> Yes. But SWT only has one setFilter function.
> If it wasn't a hard override before, we'll need a good reason to change it.

If it wasn't a hard override before, could we change it like this:

setFilterPath(String path)
setFilterPath(String path, boolean override)

The first method stays as is, ensuring backward compatibility. It calls the second method with for the 2nd argument value 'false'. The second allows to hard override by setting the 2nd argument to 'true'.

This is backward compatible, but does allow the 'hard override'.
Comment 7 Christoph Kaser CLA 2021-12-16 02:45:38 EST
I am can confirm this behavior changed with the new COM-based API.

The following snippet can be used to reproduce the issue:

public class Snippet72 {

public static void main (String [] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);
	shell.open ();
	FileDialog dialog = new FileDialog (shell, SWT.OPEN);
	dialog.setFilterPath("C:\\windows");
	System.out.println ("Selected file: " + dialog.open ());
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}

With SWT 4.9 (from https://archive.eclipse.org/eclipse/downloads/drops4/R-4.9-201809060745/swt-4.9-win32-win32-x86_64.zip), setFilterPath works even if a file from a different directory was previously selected.
With the newest SWT version, the directory of the previously selected file overrides setFilterPath.
Comment 8 Rolf Theunissen CLA 2022-01-06 02:54:07 EST
*** Bug 578045 has been marked as a duplicate of this bug. ***
Comment 9 Rolf Theunissen CLA 2022-01-06 02:55:50 EST
(In reply to Rolf Theunissen from comment #8)
> *** Bug 578045 has been marked as a duplicate of this bug. ***

This bug contains a possible fix for the issue, i.e., clearing the persisted data of the file dialog.
Comment 10 Niraj Modi CLA 2022-01-07 03:43:41 EST
(In reply to Rolf Theunissen from comment #9)
> (In reply to Rolf Theunissen from comment #8)
> > *** Bug 578045 has been marked as a duplicate of this bug. ***
> 
> This bug contains a possible fix for the issue, i.e., clearing the persisted
> data of the file dialog.

I tried out the proposed fix in bug 578045, will be sharing a gerrit shortly.
Comment 11 Eclipse Genie CLA 2022-01-07 03:45:12 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/189371
Comment 13 Niraj Modi CLA 2022-01-10 03:17:10 EST
(In reply to Eclipse Genie from comment #12)
> Gerrit change
> https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/189371 was
> merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=5544e1405e798123adc57305ba130c14fbf6e965

Resolving now.
Comment 14 Erik Hentschke CLA 2022-01-10 10:24:12 EST
Is is possible to backport this patch in Eclipse 2021-09?
Comment 15 Niraj Modi CLA 2022-01-28 02:34:45 EST
*** Bug 578415 has been marked as a duplicate of this bug. ***
Comment 16 Niraj Modi CLA 2022-02-17 01:23:36 EST
Verified on Win10 using Eclipse Build id: I20220216-1800
Comment 17 Nikita Nemkin CLA 2022-05-13 05:14:41 EDT
I'm going to revert this, because it doesn't match the historical (non-COM) FileDialog behavior and causes Bug 579359 and Issue #95 (https://github.com/eclipse-platform/eclipse.platform.swt/issues/95)

I.e. we are going back to the system-managed remembered folder with FileDialog.setFilterPath being the default, not a hard override. Also, I was unable to confirm the claims from Bug 578415 that it used to work like a hard override before 4.20.

Niraj, what do you think?
Comment 18 Niraj Modi CLA 2022-05-13 13:20:02 EDT
(In reply to Nikita Nemkin from comment #17)
> I'm going to revert this, because it doesn't match the historical (non-COM)
> FileDialog behavior and causes Bug 579359 and Issue #95
> (https://github.com/eclipse-platform/eclipse.platform.swt/issues/95)
> 
> I.e. we are going back to the system-managed remembered folder with
> FileDialog.setFilterPath being the default, not a hard override. Also, I was
> unable to confirm the claims from Bug 578415 that it used to work like a
> hard override before 4.20.
> 
> Niraj, what do you think?

Hi Nikita,
Reopening, as below PR reverts the fix made in this bug:
https://github.com/eclipse-platform/eclipse.platform.swt/pull/142

But we should continue to look for a possible fix here.
Comment 19 Helmuth Melcher CLA 2022-08-19 04:12:50 EDT
(In reply to Nikita Nemkin from comment #17)
> I'm going to revert this, because it doesn't match the historical (non-COM)
> FileDialog behavior and causes Bug 579359 and Issue #95
> (https://github.com/eclipse-platform/eclipse.platform.swt/issues/95)
> 
> I.e. we are going back to the system-managed remembered folder with
> FileDialog.setFilterPath being the default, not a hard override. Also, I was
> unable to confirm the claims from Bug 578415 that it used to work like a
> hard override before 4.20.
> 
> Niraj, what do you think?

I tested with SWT versions 4.16 through 4.25M1 and on Windows 10 the versions prior to 4.20 work as hard override for me, so does 4.23.

Working as hard override:
4.16, 4.17, 4.18, 4.19, 4.23

Working as soft default:
4.20, 4.21, 4.22, 4.24, 4.25M1

Please provide a way to hard override again. Not being able to do a hard override breaks some very common use cases when working with multiple file types. (e.g.: When loading a config file we want to point the user to the folder where config files are saved by default. This should be possible even if the user exported some unrelated data to a different directory earlier. With the current SWT version this is not possible as far as I can tell.)

Snippet used for testing:

public static void main(String[] args) {
	Display display = new Display ();
	Shell shell = new Shell (display);		
	shell.open ();
	
	FileDialog dialog = new FileDialog (shell, SWT.OPEN);
	dialog.setFilterPath("C:\\Windows"); 
	dialog.open(); //select file C:\\Windows\\notepad.exe
	
	FileDialog dialog2 = new FileDialog (shell, SWT.OPEN);
	dialog2.setFilterPath("C:\\"); 
	dialog2.open(); //check if we land in C:\\Windows or in C:\\ 

	display.dispose ();
}
Comment 20 Matthias Mailänder CLA 2022-12-02 04:14:59 EST
RFC: https://github.com/eclipse-platform/eclipse.platform.swt/pull/466 I tried to make it configurable to please everyone.