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

Can't detect which filter is selected #14

Open
drahoslove opened this issue Mar 18, 2018 · 1 comment
Open

Can't detect which filter is selected #14

drahoslove opened this issue Mar 18, 2018 · 1 comment

Comments

@drahoslove
Copy link

drahoslove commented Mar 18, 2018

Hi,
it would be great to be able to tell which filter in save dialog user selected.

Imagine an application where user wants to export an image in one of possible graphic formats.

dial := dialog.File().Title("Export as image")
dial.Filter("SVG (*.svg)", "svg")
dial.Filter("PNG (*.png)", "png")
dial.Filter("PDF (*.pdf)", "pdf")
filename, err := dialog.Save()

User opens a dialog, selects png as type, and fill in just myimage as name, believing will create file myimage.png - which is common behavior and users are used to it - but it would not.

Problem is that value of variable filename is just "myimage".

It would be great if either:

  1. there would be a way to detect which which filter is selected
    from nFilterIndex field of OPENFILENAME structure in win api
    and from dialog.GetFilter() in gtk lib on linux
    it might by returned as additional value from .Save() method.

  2. or it could automatically append first extension from extensions of a selected filter to filename without extension

I'd be happy to help make an implementation for windows and linux platform.

@drahoslove drahoslove changed the title Can't detect whcih filter is selected Can't detect which filter is selected Mar 18, 2018
@sqweek
Copy link
Owner

sqweek commented Mar 21, 2018

Tbh it always annoyed me how notepad auto appended .txt to the filename seemingly no matter what, and I did think that was the default behaviour of the windows' dialog.

But you're right this is a totally reasonable expectation, and also that the filter selected by the user is important information (especially in the save case).

The only caveat is that the load/save dialog on OSX doesn't present the list of filters to the user, so any solution which relies on selected filter is non-portable. However, the osx implementation at present does automatically append an extension if the user doesn't specify one.

I think your second suggestion is a good one.

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

2 participants