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

Unable to set default filter to 'All Files (*.*)' in Windows save file dialog #19492

Open
3 tasks done
rmobis opened this issue Jul 28, 2019 · 3 comments
Open
3 tasks done

Comments

@rmobis
Copy link

rmobis commented Jul 28, 2019

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for a feature request that matches the one I want to file, without success.

Problem Description

It is not possible to set the default filter on a save file dialog in Windows to All Files (*.*). This is a nuisance because often when you want to save a file with no/unknown extension, such as .babelrc, it appends the first filter's extension. Example: microsoft/vscode#28425

image

Now, I know this is intentionally not allowed, as can be seen in shell/browser/ui/file_dialog_win#L206:

// By default, *.* will be added to the file name if file type is "*.*". In
// Electron, we disable it to make a better experience.
// ...
for (size_t i = 0; i < filterspec.size(); ++i) {
	if (std::wstring(filterspec[i].pszSpec) != L"*.*") {
		// SetFileTypeIndex is regarded as one-based index.
		dialog->SetFileTypeIndex(i + 1);
		dialog->SetDefaultExtension(filterspec[i].pszSpec);
		break;
	}
}

It basically picks the first filter as the default, except for the All Files one because of a supposed issue where it appends *.* to the file name. However, there has to be a way to do this, because other programs do (unfortunately I couldn't think of any open source one so we could look at the sources).

Proposed Solution

No real ready solution in mind. Just gotta figure out how to allow it and avoid the issue. Maybe if instead of setting the default extension to "*.*" we set it "" when the All Files filter is used, we could get both things to work.

Alternatives Considered

Verify whether the appending *.* to filename issue actually happens. If it doesn't, we can just cut the code out.

Additional Information

Fiddle: https://gist.github.com/e9cf0de5417180669245e79b10c2f898

@rmobis rmobis changed the title Unable to set default filter to 'All Files' (*.*) in Windows save file dialog Unable to set default filter to 'All Files (*.*)' in Windows save file dialog Jul 28, 2019
@TongDaDa
Copy link

TongDaDa commented Aug 2, 2019

Same problem here.

@TongDaDa
Copy link

TongDaDa commented Aug 2, 2019

On Mac, it works fine, and on the windows, It always appears "All files *".

For this demo, I used the URL(https://codepen.io/tongdada-the-sans/pen/OKjxgJ) in my electron.

And the images:

企业微信截图_15647151318763

屏幕快照 2019-08-02 上午11 01 31

As for how to resolve this situation, I just found a solution as far that appending a suffix on the filename, although It already has a .ext on its name. see below.

企业微信截图_15647266618763

On windows10, we can add two ext on the filename, but the selection of the saveFiledialog of the system always show an All type(*).

I don't know how to resolve it.

@cunlic
Copy link

cunlic commented Oct 27, 2023

This is a huge issue specifically in VS Code. With it defaulting to "Plain Text (*.txt)" as the filetype for unknown new files, the user can't see ANY files in the existing directory when saving to look for duplicates, naming patterns to follow, or single-click an existing file to use as a template and rename etc.

(I came here from this VS Code bug report from 6 years ago) microsoft/vscode#28425

Surely this can be fixed within Electron, but if it can't, this feels like another desperate need for an AHK script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants