Skip to content

In SWT save FileDialog on Mac, displayed filename not actual filename. #3211

@andrewthomas28

Description

@andrewthomas28

In the SWT save FileDialog on Mac, if the user changes the filter, the extension in the displayed filename does not change. But the actual filename reported by the dialog (and used for the overwrite check) differs - it is consistent with the chosen filter.

I'm observing this with Eclipse 4.39 rich-client platform on my Mac OS 26.3.1 (a). Don't know what other versions it affects.

For example, if the displayed filename is myfile.foo, and you change the filter to *.bar, the displayed filename remains at myfile.foo, but the actual filename reported by the dialog is myfile.bar.

May be similar to behavior of [Big Sur] File dialog does not change file name when switching file type.

Below is example code to demonstrate the issue.

package mypackage;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

/** Test the standard SWT file dialog.
 * @author thomasa
 */
public class TestFileDialog {

	public static void main(String[] args) {
		final Display display = new Display ();
		Shell shell = new Shell(display);
		shell.setLayout (new FillLayout());

		Button btn = new Button( shell, SWT.PUSH );
		btn.setText("Show File Dialog");
		btn.addSelectionListener( new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				FileDialog dlg = new FileDialog( shell, SWT.SAVE );
			
				dlg.setFilterNames("foo", "bar", "baz");
				dlg.setFilterExtensions("*.foo", "*.bar", "*.baz");
				
				dlg.setFileName("myfile.foo");
				
				String file = dlg.open();
				if ( null != file ) {
					MessageDialog.openInformation( shell, "Chosen Filename", file );
				}
			}
		});
		
		shell.open ();
		
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions