Using FileType Set

I love to use FileType Set as in:

Var FTS_SQL    As New FileType

FTS_SQL.Extensions = ".sqlite"
FTS_SQL.Name       = "sql/database"
FTS_SQL.UTI        = "public.database, public.data"

but the above allows the user to choose text files (and certainly not only)…

The difference with a FileTypeGroup is:
Identifier = “com.xojo.database.sqlite”

How do you access to your db file ?

Using a path as most of the examples in the documentation uses ?

FileType and FileTypeGroups define types of files that an application may wish to open or save. They are not for individual files on disk. You can use them in File Open and Save dialogs to filter the types of file it will allow you to work with.

The FileTypeGroup editor allows more properties than you specify. Including making drag and drop file opening possibilities on macOS.

I haven’t seen a UTI being required for the Filter of an Open or Save dialog. I only ever define a Name and Extensions. You may see success omitting the UTI?

UTI is the preferred method on macOS. I would include it if you know it.

If you have a file of that type on your Mac, just drop it into the FileTypes editor and it will fill in all the right fields for you.

5 Likes

Wow, this is a great tip Greg that I was unaware of. I guess you learn something new everyday.

I’ve never seen this anywhere in the documentation but maybe I missed it. Anyone aware of this being documented somewhere? If not, I’ll place a ticket to get things updated.

I didn’t know this tops neither.

Great some can learn something, but since Greg already disclosed it some times ago, this is how I get the data I used in the Filer Type Set.

And, yes, there is a FileType Set (local) and a File Type Group (global).

For the record, here’s the entry for File Type Set.

That does not answer to my question.

How do you choose an sqlite file using a FileType ?

Code to help:


Var dlg As New OpenFileDialog
Var f As FolderItem

dlg.InitialFolder = SpecialFolder.home
dlg.Filter = "put the filter here"
f = dlg.ShowModal

Add the FileType definition (VAR … As FileType) )and replace “put the filter here” with the correct sentence.

I’m sorry I can’t find a way to do this with FileType or using OpenFileDialog.

If you want to use a FileTypeGroup, you can do this:

For the FileTypeGroup

Code:

Var f As FolderItem 
f = f.ShowOpenFileDialog(DatabaseGroup.SQLiteDatabase)

Sample code:
OpenSqliteExtension.xojo_binary_project.zip (4.8 KB)

Running screenshot. Only .sqlite files and folders are not grayed out:

I just filed a ticket to add the drag and drop tip that @Greg_O provided, to the Xojo documentation:

77881 - Add File Drag and Drop to the File Type Group Editor Documentation Page

1 Like

Just assign the FileType to the Filter. For example:

Var oFileType as FileType
oFileType...
dlg.Filter = oFileType

If you are using a FileTypeGroup you can use:

dlg.Filter = FileTypeGroup.FileTypeName
// or more than one:
dlg.Filter = FileTypeGroup.FileTypeName1 + FileTypeGroup.FileTypeName2

I tried that and was not able to make it work. Do you have an example of it working?

Add a FileTypeGroup to your project. Click on it and open the editor. Drag and drop an existing file to the editor, it will fill in the data required. Then use the GroupName and FileType name, as shown above. It should work.

Var oFileDialog As New SaveFileDialog
oFileDialog.InitialFolder = oFile.Parent
oFileDialog.Filter = ExternalFileTypes.ExcelXLSX + ExternalFileTypes.TXTFile + ExternalFileTypes.CSVFile + ExternalFileTypes.DBFFile + ExternalFileTypes.OXDFile + ExternalFileTypes.DIFFile
oFileDialog.SuggestedFileName = DatasetName
oFileDialog.ActionButtonCaption = kButton_Export
oFile = oFileDialog.ShowModal( Me )

Thanks.
So I guess that is not possible if just defining a FileType (as Emile asked).
I posted about adding a FileTypeGroup above.

Yes, it is, but you need the correct information in there. On Mac it relies on the UTI system, on Windows it’s more the extension. Drag and drop will get you the information you require.

On Mac the FileTypeGroup editor does more than just allows the dialog to work. For example it adds entries to the Info.plist file defining the types of file the app opens, saves etc. It also adds icons to those file types.

UTIs can be tricky, there is a whole tree of them. By declaring ones high in the tree you are including ones below that point. It could be why text files are showing up. There should be a more specific UTI for SQLite files than just “public.database”.

It is important to only put the specific UTI in the Identifier property, the other elements should go in the ConformsTo property.

This explains the structure a little:

There’s a list somewhere with lots of types in it, but I can’t find it.

A couple of links with a list of UTIs:

It is also important to declare yourself as an Editor of the file (specifically for SQLite) and a rank of Alternate.

I think we are missing the point and Emile’s question is not being answered.
Emile is following the documentation (that has several bugs). For example:
https://documentation.xojo.com/api/user_interface/desktop/openfiledialog.html#openfiledialog-filter

It says the Filter is a String but the example code doesn’t work:

dlg.Filter = FileTypes1.VideoMp4.Extensions ' defined in the File Types Editor...

this works if we set the FileTypeGroup1 by dragging an mp4 to the File Type Group editor:

dlg.Filter = FileTypeGroup1.VideoMp4 //without extensions

the documentation inside Filter also points to FileType documentation:
https://documentation.xojo.com/api/files/filetype.html

making us think that if we do something like:

Var jpegType As New FileType
jpegType.Name = "image/jpeg"
jpegType.Extensions = "jpg;jpeg"

Var dlg As New OpenFileDialog
dlg.Title = "Select a jpeg file"
dlg.Filter = jpegType.Extensions

Var f As FolderItem = dlg.ShowModal

should limit the Open Dialog to only allow Jpeg file extensions, but if you try it, it won’t work.

That is the problem that Emile is finding, by following the Documentation is not getting the wanted results.

I hope is clear now.