Answer file with multiple types [SOLVED]

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Answer file with multiple types [SOLVED]

Post by stam » Tue Dec 07, 2021 12:05 pm

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
Last edited by stam on Tue Jul 12, 2022 10:24 am, edited 1 time in total.

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Answer file with multiple types

Post by Klaus » Tue Dec 07, 2021 12:19 pm

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

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Answer file with multiple types

Post by stam » Tue Dec 07, 2021 12:23 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9358
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Answer file with multiple types

Post by richmond62 » Tue Dec 07, 2021 12:42 pm

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

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Answer file with multiple types

Post by stam » Mon Jul 11, 2022 2:15 pm

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...

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Answer file with multiple types

Post by marksmithhfx » Mon Apr 03, 2023 3:04 pm

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
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Answer file with multiple types

Post by stam » Wed Apr 05, 2023 7:02 pm

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.

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am
Location: London, UK

Re: Answer file with multiple types

Post by marksmithhfx » Thu Apr 06, 2023 11:39 am

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
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”