Page 1 of 1

Answer file with multiple types [SOLVED]

Posted: Tue Dec 07, 2021 12:05 pm
by stam
Hi all,

This really should be straightforward but i can't get it to work. Using answer file with type(s) to open a tab-separated values file is causing a slight headache, because some of these have the extension .txt and some .tab.

according to the documentation on "answer file with type" this is possible and as it states:
Each set of types is a return-delimited list of values of the form "tag|extensions|filetypes".
i presume 'filetypes' refers to the old macOS filetype 4 character code which doesn't exist anymore and multiple examples i was able to find online leave this blank. Using this format with just 1 filetype (either "tab files|tab" or "text files|txt") works fine.

However when trying to allow selection of both, the following code doesn't work:

Code: Select all

put "text files|txt|" & return & "TAB files|tab|" into tTypes
answer file "Select a TSV file to import..." with type tTypes
the files with extension .txt are selectable, but files with extension .tab are greyed out.
As i read the documentation, it should be possible to select both...
What am i doing wrong?

Many thanks
Stam

Re: Answer file with multiple types

Posted: Tue Dec 07, 2021 12:19 pm
by Klaus
Hi Stam,

I never used what the dictionary suggests, I think it is wrong!

This does the job, sepearate the types with a comma:

Code: Select all

...
put "text and TAB files|txt,tab|" into tTypes
answer file "Select a TSV file to import..." with type tTypes
...
Best

Klaus

Re: Answer file with multiple types

Posted: Tue Dec 07, 2021 12:23 pm
by stam
Klaus wrote:
Tue Dec 07, 2021 12:19 pm
I never used what the dictionary suggests, I think it is wrong!
This does the job, sepearate the types with a comma
genius! That works Klaus, thank you.
a slight gotcha is that you mustn't have spaces after the comma (doh!).

The documentation is clearly wrong on this, is it worth submitting a bug report?

many thanks once again,
Stam

------------
edit: bug report for the doucmention submitted: https://quality.livecode.com/show_bug.cgi?id=23477

Re: Answer file with multiple types

Posted: Tue Dec 07, 2021 12:42 pm
by richmond62
is it worth submitting a bug report?
Well, as what is written in the dictionary would throw quite a few people,
the answer has to be "Yes".
-
Screen Shot 2021-12-07 at 1.42.08 PM.png

Re: Answer file with multiple types

Posted: Mon Jul 11, 2022 2:15 pm
by stam
Further to this, Panos has kindly clarified.

The return-delimited version supplies the options to the 'type' drop down menu in the dialog box - only on mac, you have to click the 'options' button to show the drop down menu. Which is lame as that's the only option.
https://quality.livecode.com/show_bug.cgi?id=23477 wrote:Note that this ^^ will show EITHER tab files OR txt files - not both. You can choose which type to show by clicking on the "Options" button (in the mac file chooser dialog) and then in the dropdown choose the desired type (txt or tab)
Klaus' answer is still the correct one if you want to show multiple filetypes at the same time, but if you only want to show one type that the user chooses, the return-delimited list is the way to do it... Just FYI...

Re: Answer file with multiple types

Posted: Mon Apr 03, 2023 3:04 pm
by marksmithhfx
stam wrote:
Mon Jul 11, 2022 2:15 pm
Klaus' answer is still the correct one if you want to show multiple filetypes at the same time, but if you only want to show one type that the user chooses, the return-delimited list is the way to do it... Just FYI...
Hi Stam, wasn't exactly sure what you meant by "return-delimited list" for showing 1 file type but I tried the following (based on examples you and others presented) and it worked like a charm...

Code: Select all

   put "sqlite files|sqlite|" into tTypes
   answer file "Select the AppReg database file:" with specialfolderpath("Resources") with type tTypes
This is obviously also including a path to a directory as well. Thanks to everyone for the great discussion here. I found the docs a little tricky to sort out so the examples helped a lot.

Cheers,
Mark

Re: Answer file with multiple types

Posted: Wed Apr 05, 2023 7:02 pm
by stam
Glad this worked for you!
The documentation is good, but could do with an overhaul in places. That in itself is a massive project... and I'm sure they haver bigger fish to fry (although the importance of good documentation with lots of examples cannot be overstated...)
marksmithhfx wrote:
Mon Apr 03, 2023 3:04 pm
Hi Stam, wasn't exactly sure what you meant by "return-delimited list" for showing 1 file type but I tried the following (based on examples you and others presented) and it worked like a charm...
This refers to those dialogs that let you choose which file type to open - on macOS it's in a popup menu after you click the 'Show options' button or some such. So if you want to provide functionality that lets the user only pick text, or only pick csv, an image etc, use a return delimited list (each definition is in its own line). If you just want to see one or more filetypes without the user having to choose, the just comma delimited list is correct.

Regarding definitions, all you really need is the file extension. I think it used to be more complicated because MacOS had a creator and a filetype code built into the resource fork (which mean you could have files with the same extension opening different default applications) but that's gone by the wayside (thankfully). The list is pipe (|) delimited:

Code: Select all

<custom tag>|<.extension(s)>|<filetype(s)>
but all you need is the middle bit, so you can simply pass leave the first and 3rd pipe-delimited item blank:

Code: Select all

|<extension>, [<ext2>, <ext3>,...]|
So for your example that would be

Code: Select all

put "|sqlite, db|" into tTypes // .db is a common extension for sqlite as well
If you wanted your handler to either open an sqlite or a text file for example based on user choice, you would need to populate the popup menu in the OS's open file dialog and you'd need to also provide a tag as well extension(s), as a return-delimited list (1 definition per line):

Code: Select all

put "SQLite|sqlite, db|" & return & "Text file|txt, text, tsv, csv|" into tTypes
here I've added the tags because this populates the popup menu in the OS's open dialog with text. At least that's how I understand it ;)

That's a lot to say about a tiny feature, but hopefully other new users may find this helpful in the future!!
S.

Re: Answer file with multiple types

Posted: Thu Apr 06, 2023 11:39 am
by marksmithhfx
stam wrote:
Wed Apr 05, 2023 7:02 pm
here I've added the tags because this populates the popup menu in the OS's open dialog with text. At least that's how I understand it ;)

That's a lot to say about a tiny feature, but hopefully other new users may find this helpful in the future!!
S.
Nice to see such detailed replies Stam. Hopefully ChatGPT4 or later will find them and offer them up to searchers. I haven't tried this beyond a single file type, but when I need to I'll be back ;)

Mark