Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to overrule the last file dialog location on Windows #466

Conversation

Mailaender
Copy link
Contributor

@Mailaender Mailaender commented Nov 16, 2022

As suggested in https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190 I made it configurable, so hopefully everyone is happy. The main reason is that it is inconsistent across platforms (only Windows "misbehaves") and your application may want to store the last saved location on its own per perspective / data type etc.

To test, run Snippet72 on Windows. Select a file from another folder say C:\Windows\win.ini. Run it twice to verify it uses the preset location. Remove setFilterForcePath to bring back the legacy behavior where it by default will just ignore the set filter path if you used any save dialog before.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 16, 2022

Test Results

     303 files       303 suites   7m 19s ⏱️
  4 047 tests   4 035 ✔️   8 💤 3  1 🔥
12 068 runs  11 993 ✔️ 70 💤 4  1 🔥

For more details on these failures and errors, see this check.

Results for commit f0dc0a8.

♻️ This comment has been updated with latest results.

@lshanmug
Copy link
Member

Thanks for the PR to fix the issue.

Do we need a new API here to fix the Windows behavior?
AFAICS from the comments in https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c19 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c7, setFilterPath() worked as a hard override until 4.20. I couldn't verify it myself as I don't have Windows, may you can do a quick check? If that's the case, we should directly fix setFilterPath() instead of adding a new API. Also, that will make the setFilterPath() API consistent on all platforms.

@Mailaender
Copy link
Contributor Author

When I change the default way on Windows, someone will only revert it back as in #142. That is why I added an optional switch. However, I am open to suggestions on how to change the API.

@lshanmug
Copy link
Member

When I change the default way on Windows, someone will only revert it back as in #142. That is why I added an optional switch. However, I am open to suggestions on how to change the API.

AFAICS from https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c17 the change was reverted because it caused 2 other issues as mentioned in the comment there.
We should be good to fix the default behavior of setFilterPath() on Windows, after verifying that:

@Mailaender
Copy link
Contributor Author

Is there consensus for setFilterForcePath defaulting to true?

@lshanmug
Copy link
Member

lshanmug commented Dec 4, 2022

AFAICS from https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c17 the change was reverted because it caused 2 other issues as mentioned in the comment there. We should be good to fix the default behavior of setFilterPath() on Windows, after verifying that:

* setFilterPath() worked as a hard override until 4.20 (by testing any one version < 4.20)

* The 2 issues mentioned in https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c17 don't reappear after the fix.

Can you pls verify your fix based on above points?

Is there consensus for setFilterForcePath defaulting to true?

Please see #466 (comment) above, the fix should go into setFilterPath instead of new API.

@plexiq
Copy link

plexiq commented Dec 4, 2022

If you make it configurable then I think there's a strong case for defaulting setFilterForcePath to true, that way the behavior is consistent across platforms unless specifically changed.

It would be preferable to simply revert the behavior to <4.20 (ie setFilterForcePath = true) without an API change. The sole argument I can see for making this configurable would be to reduce the possibility of this change being reverted again, the option doesn't appear to be useful beyond that.

@dhendriks
Copy link

Let me try to summarize all information, as I'm getting lost in all the spread-out information in various issue, pull requests, etc.

Background:

There may be a related or unrelated issue with root / 'This PC' / 'Computer' directory:

Potential reasons to make it always a hard override:

Potential reasons for reverting the change and keeping the current behavior, or supporting a hybrid approach as per this pull request:

Regarding whether this is a regression, there is mixed evidence:

Options for the design:

Possible implementations for hard override:

Possible defaults for a hard override option:

@plexiq
Copy link

plexiq commented Dec 4, 2022

There appears to be conflicting evidence regarding the behavior on 4.16:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c2 (@dhendriks found 4.16 to work as a soft override)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c19 (In the tests I previously posted, 4.16 was working as a hard override)

I have re-run the tests for 4.16 and additional ones for 4.13, 4.14 and 4.15. All of these versions work as a hard override for me on Windows 10, using the same snippet for testing (https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c19).

Can someone please help verify if we actually have inconsistent behavior on 4.16, or if the previous report of 4.16 working as a soft default was a mistake?

@dhendriks
Copy link

There appears to be conflicting evidence regarding the behavior on 4.16: https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c2 (@dhendriks found 4.16 to work as a soft override) https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c19 (In the tests I previously posted, 4.16 was working as a hard override)

https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c19 uses two different paths for the setFilterPath calls. According to https://bugs.eclipse.org/bugs/show_bug.cgi?id=577190#c3, Windows remembers the path only if the same path is given. What happens if you change the snippet to provide C:\\ both times as filter path, and still the first time select C:\\Windows\\notepad.exe?

@plexiq
Copy link

plexiq commented Dec 4, 2022

What happens if you change the snippet to provide C:\ both times as filter path, and still the first time select C:\Windows\notepad.exe?

I can not reproduce this behavior. Calling with C:\\ twice, selecting C:\\Windows\\notepad.exe the first time, the second dialog still opens as C:\\ (ie, hard override) using 4.16. The snippet is unchanged, except for the change to C:\\.

Tested with: https://archive.eclipse.org/eclipse/downloads/drops4/R-4.16-202006040540/

Update: I'm actually getting inconsistent results and can sometimes reproduce the behavior you describe when switching around between the JDK versions used to compile and/or run. But using SWT 4.16 and compiling and running with Java-17 results in a hard override, even when calling twice with C:\\.

@Mailaender Mailaender force-pushed the file-dialog-force-filter-path branch 3 times, most recently from 805e2d6 to 2af4f8e Compare January 11, 2023 13:04
@Mailaender
Copy link
Contributor Author

I have a hard time seeing how to proceed from all those conflicting comments. I now merged the parameter into the existing setFilterPath hoping this is what you want when asking for no API change. I can also change the defaults on Windows, but I am not sure what is preferred.

@plexiq
Copy link

plexiq commented Jan 11, 2023

I think the main priority is to get back some option to achieve "override" behavior on all systems, whether that's by default or by using an additional parameter isn't overly important imo.

From my point of view it would be preferable to have setFilterForcePath = true as default on Windows, as this would result in consistent behavior across OSX/Linux/Windows, but this isn't a big issue either way as long as an option exists.

@Mailaender
Copy link
Contributor Author

Set filterForcePath = true for consistent behavior across platforms as suggested.

@lshanmug
Copy link
Member

AFAIU the main usecase for having an API is to provide an option in FileDialog to store the last saved location. But, that should be the default behavior of FileDialog, it should remember the last opened directory see issue

So, 2 changes are required in FileDialog on Windows here:

  1. Fix setFilterPath() to set the dialog's directory path to as a hard override.
  2. Keep the default behavior of FileDialog to remember the last opened directory. This eliminates the need for an API to control this. setFilterPath(null) would have the same behavior.

This would fix the current problem with FileDialog.setFilterPath(), make it consistent across all platforms and provides a way for users to switch between the behaviors.

@Mailaender
Copy link
Contributor Author

Note: there is also a competitive #530.

@Mailaender
Copy link
Contributor Author

I am not sure if I understand your suggested changes. Added a new change set which hopefully goes into the right direction.

@lshanmug
Copy link
Member

I am not sure if I understand your suggested changes. Added a new change set which hopefully goes into the right direction.

Thanks, the change is in the right direction, but point 2 below is not covered. Let me explain.

2. Keep the default behavior of FileDialog to remember the last opened directory. This eliminates the need for an API to control this. setFilterPath(null) would have the same behavior.

With the current PR, if a FileDialog is opened without any call to setFilterPath(), the FileDialog would open at the Windows "root" directory and last opened directory will not be remembered, hence bringing back #95. For example: try the snippet in #95 (comment).
From the code, the default filter path being used in FileDialog is "" and not null (line 52). So, the else part in your PR (line 301) would not be called in the default case (when setFilterPath is not called).

@deepika-u, I don't have Windows to test the PR, can you pls give it a try?

@tmssngr
Copy link
Contributor

tmssngr commented Feb 11, 2023

IMHO the path remembering only should happening if setFilterPath not is invoked. Honestly, I don't really understand the need for this request at all, because remembering the path easily could be handled by client code in a much more flexible way, e.g. for different kind of files different paths could be remembered.

@lshanmug
Copy link
Member

IMHO the path remembering only should happening if setFilterPath not is invoked. Honestly, I don't really understand the need for this request at all, because remembering the path easily could be handled by client code in a much more flexible way, e.g. for different kind of files different paths could be remembered.

@tmssngr Not sure which request you are referring to. My comment was requesting to remember the path when setFilterPath is not invoked, otherwise it would cause #95.

@deepika-u
Copy link
Contributor

@Mailaender

I have tested your new change that fixes the original issue but when filterPath is not set, we are loosing the original behavior as conveyed by @lshanmug(it is not remembering the history of last saved path).

@lshanmug
Copy link
Member

lshanmug commented Feb 16, 2023

@Mailaender

I have tested your new change that fixes the original issue but when filterPath is not set, we are loosing the original behavior as conveyed by @lshanmug(it is not remembering the history of last saved path).

@deepika-u Thanks for testing.

Will this fix the problem?

  • In default case, when setFilterPath() is not called, filterPath == "" -> call SetDefaultFolder
  • When filterPath != null -> call SetFolder

@deepika-u
Copy link
Contributor

@Mailaender
I think i have a fix covering these 2 test cases, will test it once more and share the fix details.

deepika-u added a commit to deepika-u/eclipse.platform.swt that referenced this pull request Feb 20, 2023
@deepika-u
Copy link
Contributor

The needed changes are tested and merged with pr => #556

Thanks everyone! please let me know if that works for you.

@lshanmug
Copy link
Member

lshanmug commented Feb 20, 2023

The needed changes are tested and merged with pr => #556

Thanks everyone! please let me know if that works for you.

Thanks @deepika-u for the fix!

Can you please test with Snippet 72 with different combinations of setFilterPath() ?

setFilterPath(path)
setFilterPath(null)

Also, pls verify in Eclipse with tomorrow's I-build.

@deepika-u
Copy link
Contributor

Test cases i tried are as below ::
Via Snippet72 :

  1. Set a valid filterPath(say for example "c:\")
  2. Set an invalid filterPath(say for example "c:\@123")
  3. Set filterPath to space(filterPath = " ")
  4. Set filterPath to null(filterPath = null)
  5. filterPath not set.
  6. Set valid path then immediately set to null, then test.
  7. Set to null then immediately set to valid path, then test.

General testing :
8. Windows > Preferences > User Libraries > Import > Browse > select some jar file(by changing .), open. Now Browse again and you'll notice path is remembered now.

This issue is fixed via the pr #556 => #556

The fix is now available in RC1.

You may please test this fix and let us know your feedback.

@akurtakov
Copy link
Member

Alternative fix #556 is in.

@akurtakov akurtakov closed this Feb 22, 2023
@Mailaender Mailaender deleted the file-dialog-force-filter-path branch February 22, 2023 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants