Filetype .... confusion

Making a Filetype filter in older versions of XOJO was not too difficult…
Now it seems that its a Royal PITA… The FT editor asks for more “things”, and it seems you can’t delete a “mistaken” entry.

So I figured… I’ll just do it the “old school” way, since my requirements were rather simple.

		Dim dlg As New SaveAsDialog
		Dim f As FolderItem
		Dim ext As String
		Dim filetype1 As New FileType
		//
		
		ext=".HTML"
		FileType1.name="text/html"
		FileType1.Extensions=".html;.htm"
		filetype1.MacType="TXT "
		FileType1.MacCreator="????"
		//
		dlg.InitialDirectory=SpecialFolder.Documents
		dlg.promptText="Select Destination File"
		dlg.SuggestedFileName="*"+ext
		dlg.Title="Export Data to a File"
		dlg.Filter=FileType1
		f=dlg.ShowModal
		If f <> Nil Then
				Return f
		Else
				Return Nil
		End If

The dialog DOES NOT show HTM or HTML files as being selectable…
I tried it with and without all combos of MacType/Creator (including none at all)

All I want to do is limit the selection to a specific list of extensions.

What ever am I doing incorrectly?

Here is an example for an OpenDialog:

dim theDialog as new OpenDialog if Carbon.SystemVersionAsInt >= 101100 then theDialog.PromptText = kSelectClone else theDialog.Title = kSelectClone end if Dim DBType As New FileType dbType.Name = "Database" dbType.Extensions = "vdb" theDialog.Filter = DBType theFolderitem = theDialog.showModal if theFolderitem = nil then Return

No dots in the extension I would say. You can omit MacType and MacCreator.

Well that solved “part” of the issue…
by removing the dots in the extension, then by leaving SUGGESTEDFILE blank, the dialog shows “untitled.html”
but it still does not show existing .HTM or .HTML files as active, they are still “grayed out”
this is something that should NOT be so difficult to get right

You are doing a SaveAsDialog. Why should there be anything selectable?

I am looking to to user entering either a new (non existing) filename, or to over-write an existing one…
If the file is pre-existing, it should be selectable.
even the example in the LR doesn’t work…

the expected results (and I’ve seen this in the past)

  • SaveAsDialog with a filter, shows existing files (black) that match the filter
  • User can select one of those, OR type in a new name of their own
  • if selected or typed name does exist, a “Are you sure to overwrite” confirmation appears (this does happen for typed in names)

You didn’t mention the platform. The select to overwrite is a Windows thing.

OSX 10.11.6 / Xojo 2016r4.1

My confusion is the example in the LR DOES seem to work, and my code is not noticeable different…
The LR example builds and concats multiple filters… my app builds ONE

Lang Ref Example

		Dim dlg as New OpenDialog
		Dim f as FolderItem
		
		Dim txtType as New FileType
		txtType.Name = "Text File (*.txt)"
		txtType.MacType = "TEXT"
		txtType.Extensions = "txt"
		
		Dim htmlType As New FileType
		htmlType.Name = "HTML File (*.htm, *.html)"
		htmlType.MacType = "HTML"
		htmlType.Extensions = "htm;html"
		
		Dim csvType as New FileType
		csvType.Name = "CSV File (*.csv)"
		csvType.MacType = "TEXT"
		csvType.Extensions = "csv"
		
		Dim xlsType As New FileType
		xlsType.Name = "Excel File (*.xls)"
		xlsType.MacType = "XLS "
		xlsType.Extensions = "xls"
		
		dlg.InitialDirectory=SpecialFolder.Desktop
		dlg.promptText="Prompt Text"
		dlg.SuggestedFileName=""
		dlg.Title="Title Property"
		//dlg.Filter=txtType + htmlType + csvType +xlsType
		
		dlg.Filter= htmlType 
		f=dlg.ShowModal()
		If f <> Nil then
				  
				  If Right(f.Name,3)="txt" Then
						    MsgBox "1"
				  Elseif Right(f.Name,3)="htm" Then
						    MsgBox "2"
				  Elseif Right(f.Name,3)="csv" Then
						    MsgBox "3"
				  Elseif Right(f.Name,3)="xls" Then
						    MsgBox "4"
				  End if
				  
		Else
				  //user canceled
		End if

my code

		Dim dlg As New SaveAsDialog
		Dim f As FolderItem
		Dim typeOfFile As String
		Dim filetype1 As New FileType
		//
		Select Case fmt
		Case expDELIMITED
				typeOfFile="Delimited"
				FileType1.Name       = "CSV File (*.csv, *.txt)"
				FileType1.MacType    = "TEXT"
				FileType1.Extensions = "csv;txt"
				//
		Case expEXCEL
				typeOfFile="Microsoft™ Excel"
				FileType1.Name       = "Excel File (*.xls)"
				FileType1.MacType    = "XLS "
				FileType1.Extensions = "xls"
				//
		Case expHTML
				typeOfFile="HTML"
				FileType1.Name       = "HTML File (*.htm, *.html)"
				FileType1.MacType    = "HTML"
				FileType1.Extensions = "htm;html"
				//
		Case expINSERT
				typeOfFile="SQL Script"
				FileType1.Name       = "SQL File (*.sql)"
				FileType1.MacType    = "TEXT"
				FileType1.Extensions = "sql"
				//
		Case expJSON
				typeOfFile="JSON"
				FileType1.Name       = "JSON File (*.json)"
				FileType1.MacType    = "TEXT"
				FileType1.Extensions = "json"
		End Select
		
		//
		dlg.InitialDirectory=SpecialFolder.Documents
		dlg.promptText="Select Destination File"
		dlg.SuggestedFileName=""
		dlg.Title="Export Data to a "+typeOfFile+" File"
		dlg.Filter=FileType1
		f=dlg.ShowModal
		If f <> Nil Then
				Return f
		Else
				Return Nil
		End If

The LR example is about an OpenDialog. You use a SaveAsDialog.

You could also use the UTI. html is “public.html” IIRC.

nsd.filter = "public.html"

[quote=324123:@Sam Rowlands]You could also use the UTI. html is “public.html” IIRC.

nsd.filter = "public.html"

not sure where that fits into the scheme of things (as noted… I have FIVE(5) differing scenarios)

So I guess I am just crazy, that you cannot “see” other files the meet a filter in a SAVEASDIALOG… it is late, but that doesn’t make sense…

Oh okay; if you add them at design time to a file type set.

You can then use folderitem.filetype (IIRC) to get the name of the filetype. You still need to manually compare with your file types in the filetype set.

macOS has functions for reading the UTI from a file, which you can get at either via declares or via MBS.

But ideally you should try to use as much native Xojo as possible.

As stated in my OP, I’d rather NOT use the currently overly complex (my opinion) Filetype editor, and figure out why the “pure code” method doesn’t work.
The files I need to deal with just need to match the extensions…

  • .CSV or .TXT
  • .XLS
  • .SQL
  • .JSON
  • .HTM or .HTML

The user will have previously indicated the type of export they desire (this is the FMT variable
I need to give them the ability to create a new file, or overwrite an existing file, but enforce the extension, the SaveAsDialog does this, but does not show matching files in Black (everything is grayed out)

Declares are not an option, as this is for macOS and Windows
and MBS …well I’ve stated my stance on plug-ins many times (no offense Christian)

Again: do you want to use this for Windows or for Mac? On the Mac ALL files are greyed out for a SaveAsDialog. But when testing I found out today that you can select the greyed out files.

So, what it seems, is that my recollection of this “working” as I thought, was incorrect.
I did see you could select ANY file, and it changed the extension if required…

Ok… thanks… not optimium… but I have ALOT more work to do on this app to waste time with something I thought worked one way, but seems to not