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

dialog.showSaveDialog() returns file name which doesn't include the chosen extension on Linux #21935

Closed
bsivanov opened this issue Jan 28, 2020 · 3 comments

Comments

@bsivanov
Copy link

Issue Details

  • Electron Version:
    • 7.1.10
  • Operating System:
    • Ubuntu 18.04 x64
  • Last Known Working Electron version:
    • N/A

Expected Behavior

On Linux, dialog.showSaveDialog method returns file name which doesn't include the extension chosen by the user.

Actual Behavior

dialog.showSaveDialog method returns file name which include the extension chosen by the user as part of the returned file name.

To Reproduce

  1. Execute the following code:
const file = dialog.showSaveDialogSync({
          filters: [
            { name: 'Ext1', extensions: ['ext1'] },
            { name: 'Ext2', extensions: ['ext2'] },
          ],
        });
  1. When the dialog is opened, type "filename" in the name box, and choose Ext1 in the file extensions combo box.
  2. The returned filename is "filename" and and not "filename.ext1".

Additional Information

Moreover, there is no API available to get the chosen extension (#15254).

It seems this behavior was available at some point (#4634).

@codebytere
Copy link
Member

@bsivanov this was done intentionally here: #15510. The causes for its removal still stand, meaning that while i understand why you would want this, it is not something we feel is within the scope of our dialog capabilities. As such, i'm closing this out.

@MrMitch
Copy link

MrMitch commented Feb 14, 2020

Hi @codebytere and @bsivanov,

I'd like to attract your attention to a recent comment I made, reviving a proposal that would allow to get back the selected filter of a saveDialog that would remove the need for electron to manually append the extension to the filename if the end user omits it.

Taking inspiration from what was originally proposed by @mb21, the selected filter could be an extra property on the object resolved by the Promise returned by showSaveDialog.

const result = await dialog.showSaveDialog({
    filters: [
        { name: 'Filter 1', extensions: ['txt', 'rtf'] },
        { name: 'Filter 2', extensions: ['doc', 'docx'] },
        { name: 'Filter 3', extensions: ['pdf'] },
    ],
});

// result already has the `canceled`, `filePath` and `bookmark` properties 
console.log(results.canceled); // false
console.log(results.filePath); // /tmp/my-file
console.log(results.bookmark); // ''

// the proposal is to add a new property called `selectedFilter` that would contain the selected filter as provided in `options.filters`
console.log(result.selectedFilter); // { name: 'Filter 2', extensions: ['doc', 'docx'] }

Would that be feasible with the way electron handles the dialogs ?

@ppazos
Copy link

ppazos commented Mar 4, 2024

What's strange is that the extension is considered something different than the file name. At least on Linux, the file extension is just part of the file name. So if the user saves a file with a certain file name, including an extension if they want, when getting the file name back it should include the whole file name, including the extension if present.

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

No branches or pull requests

4 participants