any tutorial for filetypes editor ???

Hi,

I “played” with the filetype editor today, trying to find the good pattern to open only binary files that ends with .DAT (on mac)
did not succeed.
it always gave me all files, with getopenfolderitem method, no matter what I changed in the parameters …

read the xojo documentation, tried to understand, no luck.

is there any visual tutorial for that editor, with example for common types of files ?
thanks.

https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

note that EVERY file isA binary file :stuck_out_tongue:

extension = .dat
conforms to = public.data

that should be all you need

The All About File Types webinar from April might be helpful.

Also see Using File Type Sets in the User Guide.

[quote=286225:@Norman Palardy]extension = .dat
conforms to = public.data

that should be all you need[/quote]
I tried this one and it gives me all files in the directory …

don’t you have to put “???” in os type even if it’s quite deprecated ?
no - I tried also with it and it still does not work - all files selectable.

That stems from a bug in Xojo. I swear there’s a bug report on it already, but I can never find it.
Define your FileType in the same method as the Open/Save dialog and it will filter properly. Something’s wrong with the FileType editor system in the IDE.

dim ftMyFile as new FileType
ftMyFile.Name = "My File"
ftMyFile.Exensions = ".myf"

dim fItem as FolderItem = GetOpenFolderItem(ftMyFile)

I could never get Cocoa to honor filters. The only way seems to filter after selection.

Code as to how you’re using them ?

Here’s a snippet of how we use them in the IDE

  Dim fTypes As String
				
  If me IsA RBPicture Then
    itemType = "picture"
    fTypes = FileTypes.AllPictures.Extensions + ";" + FileTypes.SpecialAny.Extensions
  end if

  dialog.Title = Strings.kLocate + " " + itemType + " """ + fileName + """"
  dialog.PromptText = Strings.kLocate + " " + itemType + " """ + fileName + """"
  dialog.Filter = fTypes
				
  return dialog.ShowModal

NOTE we use the EXTENSIONS not the filetypes directly

Try the fix I posted, it works for Answers.

According to the documentation for both FolderItemDialog.Filter and GetOpenFolderItem the Filter is the actual FileType. This extensions thing is news to me. Additionally, if the extensions string thing is true, why does it work when I define the FileType in the same method as GetOpenFolderItem as seen above? Something is funky somewhere.

Yes Filetypes are funky - thats not quite the words I’ve used for them but … :stuck_out_tongue:

They do have an operator_convert to return their extensions as a string and should do the right thing
However I know I have filed a few bug reports about that usage and the code I posted is directly from the IDE
slightly abbreviated since I dont think you need ALL the possible set ups that code uses but … it is a direct copy paste

[quote=286240:@Tim Parnell]That stems from a bug in Xojo. I swear there’s a bug report on it already, but I can never find it.
Define your FileType in the same method as the Open/Save dialog and it will filter properly. Something’s wrong with the FileType editor system in the IDE.

[code]
dim ftMyFile as new FileType
ftMyFile.Name = “My File”
ftMyFile.Exensions = “.myf”

dim fItem as FolderItem = GetOpenFolderItem(ftMyFile)
[/code][/quote]
I quite like this one, and will try it
but you’re saying that nobody can use the filetype editor ?
how about the webinar then ?

I’m not saying that it will always fail, it’s just quite moody.
I have a project right now that in one spot, a GetOpenFolderItem dialog uses a FileType set up in the IDE, while another spot that used to work just fine needed the in-method definition trick just recently.

[quote=286240:@Tim Parnell]That stems from a bug in Xojo. I swear there’s a bug report on it already, but I can never find it.
Define your FileType in the same method as the Open/Save dialog and it will filter properly. Something’s wrong with the FileType editor system in the IDE.

[code]
dim ftMyFile as new FileType
ftMyFile.Name = “My File”
ftMyFile.Exensions = “.myf”

dim fItem as FolderItem = GetOpenFolderItem(ftMyFile)
[/code][/quote]

Thank you.

BTW, there is another bug about FileTypes : they cannot export normally feedback://showreport?report_id=41590

The workaround being to place the FileType into a folder, then export the folder.

They do work
The ide uses no other mechanism

yes but given the snippet of code earlier, xojo ide does not use the filetype directly, but only the extension property
then it does not use getopenfolderitem method, but the opendialog and it’s filter function.

Cut & paste from the IDE
Note we DONT use extensions here in either case

		dim dlg as new OpenDialog
		
		#if TargetMacOS
				dlg.Filter = FileTypes.REALbasicProject + ";" + FileTypes.XojoProjectBinary _
				+ ";" + FileTypes.XMLProject + ";" + FileTypes.XojoProjectXML _
				+ ";" + FileTypes.REALbasicMenu + ";" + FileTypes.XojoMenu _
				+ ";" + FileTypes.REALbasicWindow + ";" + FileTypes.XojoWindow _
				+ ";" + FileTypes.REALbasicClass + ";" + FileTypes.XojoCodeBinary _
				+ ";" + FileTypes.REALbasicLocale + ";" + FileTypes.XojoLocale _
				+ ";" + FileTypes.REALbasicScript + ";" + FileTypes.XojoScript _
				+ ";" + FileTypes.PlainTextProject + ";" + FileTypes.XojoProject _
				+ ";" + FileTypes.PlainText + ";" + FileTypes.XojoCode _
				+ ";" + FileTypes.FileTypeSet + ";" + FileTypes.XojoFileTypeSet
		#else
				dlg.Filter = fileTypes.AllProjects + ";" + _
				FileTypes.AllXojoProjects + ";" + _
				FileTypes.XojoProjectBinary + ";" + _
				FileTypes.XojoProjectXML + ";" + _
				FileTypes.XojoProject + ";" + _
				FileTypes.AllREALbasicProjects + ";" + _
				FileTypes.REALbasicProject + ";" + _
				FileTypes.XMLProject + ";" + _
				FileTypes.PlainTextProject + ";" + _
				FileTypes.REALbasicScript + ";" + _
				FileTypes.XojoScript + ";" + _
				FileTypes.AllFiles
		#endif
		
		if parent = nil then
				return dlg.ShowModal
		else
				return dlg.ShowModalWithin(Parent)
		end
		// Try to get a picture from the file system
		dim f as FolderItem
		dim typeStr as String
		
		typeStr = FileTypes.AllPictures
		#if TargetWin32
				typeStr = typeStr + ";" + FileTypes.Icons
		#endif
		
		f = GetOpenFolderItem( typeStr )
		
		if f is nil then return
		
		ImportIconData(f)

And no we dont use GetOpenFolderItem much