The problem: Saving a data file doesn’t add a file extension in the Save dialog and the resulting file, even with a manually added extension does not have the correct metadata so it’s seen as a text document and the custom icon is not displayed.
I’ve read all the relevant documentation and years worth of Xojo and RealBasic forum posts on this topic, and it seems to be a recurring problem. I’m developing for the Mac platform and am trying to avoid the deprecated MacCreator and MacType codes. I’m posting here in the General forum because I think this is of general interest.
Here’s what I’ve done:
My Build Settings look like this:
Mac App Name: SectorMaker
Framework: Cocoa
Creator Code: ???
File Types: (first 2 not relevant but shown for completeness)
ExportFileTypes.Sec Role: None
ExportFileTypes.Metadata Role: None
SaveFileTypes.Data CHECKED and Role: Editor
Bundle Identifier: com.naasirka.sectormaker
SaveFileTypes File Types Set (Only 1 file type defined)
Display Name: SectorMaker Data
Object Name: Data
MacType: ???
MacCreator: ???
Extensions: nsec
UTI’s: com.naasirka.sectormaker.nsec
Icon: Defined and loaded in
FileSaveMenuItem MenuHandler (excerpted)
[code] dim xml As XmlDocument
dim f as FolderItem, dlg As New SaveAsDialog, t As TextOutputStream
dlg.InitialDirectory=SpecialFolder.Documents
dlg.PromptText=“Save Sector Data”
dlg.Filter=SaveFileTypes.Data
dlg.SuggestedFileName=SectorName
f=dlg.ShowModalWithin(MainWindow)
if f <> Nil then
t=TextOutputStream.Create(f)
xml=New XmlDocument
blah, blah, blah
t.Write xml.Transform(IndentXML)
t.Close
end if
Return True
[/code]
Manually edited info.plist file in bundle:
[code]<?xml version="1.0" encoding="UTF-8"?>
CFBundleExecutable SectorMaker CFBundleName SectorMaker CFBundleIdentifier com.naasirka.sectormaker CFBundleInfoDictionaryVersion 6.0 CFBundleVersion 1.0.0.0.0 CFBundleDevelopmentRegion en CFBundlePackageType APPL CFBundleSignature ???? CFBundleGetInfoString 1.0 Copyright © 2013 Art Gorski CFBundleShortVersionString 1.0 CFBundleIconFile SectorMaker.icns LSMinimumSystemVersion 10.6.0 CFBundleDocumentTypes CFBundleTypeName SectorMaker Data CFBundleTypeIconFile Data.icns CFBundleTypeOSTypes **** CFBundleTypeExtensions nsec LSItemContentTypes com.naasirka.sectormaker.nsec CFBundleTypeRole Editor UTExportedTypeDeclarations UTTypeConformsTo public.data public.item UTTypeIdentifier com.naasirka.sectormaker.nsec UTTypeTagSpecification public.filename-extension nsec [/code]Can anyone see anything wrong in any of this? Thanks in advance for your help.