Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 567754

Summary: [Big Sur] File dialog does not change file name when switching file type
Product: [Eclipse Project] Platform Reporter: Mikael Sterner <mikaels>
Component: SWTAssignee: Lakshmi P Shanmugam <lshanmug>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: alexandr.miloslavskiy, lshanmug, orionllmain, peter, thomasa, ts-swt, vicd, zefick
Version: 4.17   
Target Milestone: 4.19 M3   
Hardware: Macintosh   
OS: Mac OS X   
See Also: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176014
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=6200f83b8527d9fc8a48005cdd1b0626f1933490
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176336
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=4f290a789051663e55e48c3d6d704f1cda15bb77
Whiteboard:
Bug Depends on:    
Bug Blocks: 569361    
Attachments:
Description Flags
Reproduce snippet none

Description Mikael Sterner CLA 2020-10-09 08:30:54 EDT
Created attachment 284401 [details]
Reproduce snippet

To reproduce:

1. Run the snippet.
2. It opens a file dialog where the file edit field says "Untitled.png".
3. Select "Text File" in the file type combo box. This should change the file name to "Untitled.txt". On Big Sur this doesn't happen.
Comment 1 Lakshmi P Shanmugam CLA 2020-11-20 14:04:01 EST
This looks like a Cocoa bug on BigSur.

In FileDialog.sendSelection, (line 552) panel.setNameFieldStringValue(filename) is supposed to set the modified filename in the text field. The property nameFieldStringValue is being modified, but the text field is not updated.

Opened Apple Bug for this issue: FB8909919 (BigSur: NSSavePanel setNameFieldStringValue doesn't update the text field in the panel)
Comment 2 Andrew Thomas CLA 2021-01-12 18:20:34 EST
Should the Eclipse FileDialog implementation be setting an extension at all, in the filename field, on Mac?

If no extension is specified in the filename field, then:
* When the user commits, the extension is automatically chosen from the file format field. 
* There's no need to update it when the format changes.

Maybe Apple's TextEdit provides a useful example for how the file dialog should work?
* No extension appears automatically in filename field.
* User can add an extension by hand, but that can result in a mismatch with the format field, which on commit leads to a dialog about the contradictory instructions.
Comment 3 Thomas Wolf CLA 2021-02-02 02:34:35 EST
*** Bug 570830 has been marked as a duplicate of this bug. ***
Comment 4 Lakshmi P Shanmugam CLA 2021-02-04 13:56:17 EST
(In reply to Lakshmi P Shanmugam from comment #1)
> This looks like a Cocoa bug on BigSur.
> 
> In FileDialog.sendSelection, (line 552)
> panel.setNameFieldStringValue(filename) is supposed to set the modified
> filename in the text field. The property nameFieldStringValue is being
> modified, but the text field is not updated.
> 
> Opened Apple Bug for this issue: FB8909919 (BigSur: NSSavePanel
> setNameFieldStringValue doesn't update the text field in the panel)

Response from Apple on the ticket:

As of Catalina, all apps have the sandbox versions of the Open/Save panels even if they are not sandboxed. This means you can't setNameFieldStringValue; an unsecure app might change the filename when the user was not expecting it.

What you *are* allowed to do is return a name from panel:userEnteredFilename:confirmed: that has a different file extension, because that is a common pattern for non-sandboxed apps. This change went in Catalina 10.15.6.

You can only change the extension when the user clicks Save. We are aware that changing extensions before that point is a common use case. You could try hiding extensions so the user doesn't see the mismatch between the popup and the name field.
Comment 5 Lakshmi P Shanmugam CLA 2021-02-04 14:03:59 EST
I'm trying to fix this using setAllowedFileTypes(), but has problems when using multi-part extension like tar.gz. Will look into it.
Comment 6 Eclipse Genie CLA 2021-02-08 18:40:49 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176014
Comment 8 Lakshmi P Shanmugam CLA 2021-02-10 04:31:26 EST
Fix is available in the latest build - https://download.eclipse.org/eclipse/downloads/drops4/I20210209-1800/
Please try it out.
Comment 9 Eclipse Genie CLA 2021-02-16 07:06:06 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/176336
Comment 11 Lakshmi P Shanmugam CLA 2021-02-16 10:59:58 EST
Verified with I20210216-0600