Opening app + document

The last question for this project (really):

My app (osx desktop) generates user files with extension .jeexcard. In OSX I linked this filetype with my new app JeexCard. And JeexCards starts by double clicking on the user file. But it does not automatically open the user file itself.

How can i make this App open the user file when started up?

Did you checked your custom file types in OS pane ?

Click below BUILD SETTINGS in OS X,
then in the right pane, click in Choose (after “File Types”)

I assume that in App, you added the appropriate Event to deal with dropped files (dropped in the application Icon…)

Sorry, I misread (or do not read at all):

How can i make this App open the user file when started up?

What user file did your application open at run time ?
In other words, you want your application to open <user-file.myFileType> at startup time ?

If so, this is different: you have to put code to open it in the App.Open event (and so add that event) [Xojo].

Sorry, I was thinking at drag and drop.

“This App” is your app, right?
So, your app would remember the file it last opened, and re-open it when the App starts again. Is that what you ask about?

No, I think the OP was asking if a user double-clicks on a file with the app extension in Finder then the app will be launched and the selected file will be loaded.

This is done in the OpenDocument method in the App class.

However, I have a further question. How do I link my special extension to my app in the system so that when a user double-clicks the file the OS knows which is the associated application?

That’s done by associating your file types: First, add a FileType item to your project, and add your supporrted type(s) into it. Also, give them an icon (I believe it’s necessary for this to work). Then go to the OSX settings, press the “File Types” button. There you can choose which of your file types are handled by your app (choose “editor” for those).
For Windows you need to use code to add the associations to the Registry. There’s demo code for that out there.

Thank you, Thomas, much appreciated.

Thanks all. The procedure is:

The event App.OpenDocument catches the file and does the trick.

In XOJO you add a File Type Set, where name creator and icon is added as well as the extionson and the UTI (public.item).

In OSX the Info-pane of the user file gives the option of assigning an application to the file type as well as enabling this for all files of this type.

Is the UTI always ‘public.item’?

Depends on the type of file. See: https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_intro/understand_utis_intro.html

Thank you.

Ons shitty thing: the user files loose their picto after use. Also the app doesn’t keep its picto. Somehow Apple forgets them. The links and openDocument work fine.

Shitty things solved:

picto
For Cocoa the File Type Set for a user defined file type (not a predefined file type like jpg of doc) the columns MacType, MacCreator and UIT’s should remain empty. And its best to use Binary Streams, not Text Streams. OSX recognizes the text content and shows the content and not the picto.

Drop file on window
To be able to drop files on an opened application in order to open the files, I added AcceptFileDrop( defined_file_type_set.filetype ) to the Open event of the main window.

self.AcceptFileDrop( mijnType.jeexcardObject )

Then added the DropObject to the same window to actually open the file.

That’s it. What does it do?

JeexCards is a simple but growing project drawing app. It replaces my large schoolboard (on the wall): I can make sort of post-it’s, move them around, link them to each other, assign colours, etc. And save a complete project plan in a simple JSON-based file, called JeexCard.