Page 1 of 1
String of the file that opened the app?
Posted: Tue May 20, 2014 2:15 am
by J. Baker
I didn't want to bump an old feature request topic...
http://www.purebasic.fr/english/viewtop ... 89#p391289
...but what am I missing? Global doesn't seem to work here. I just need the string outside of ProcedureC.
Code: Select all
Global FileIn$ = ""
ImportC ""
PB_Gadget_SetOpenFinderFiles(Callback)
EndImport
IsGadget(0)
ProcedureC OpenFinderFilesCallback(*Utf8Files)
FileIn$ = PeekS(*Utf8Files, -1, #PB_UTF8)
EndProcedure
PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback())
MessageRequester("Result", FileIn$)
Re: String of the file that opened the app?
Posted: Tue May 20, 2014 5:32 am
by wilbert
You can try to combine the global variable with a PostEvent inside the callback procedure.
That way you can respond to the event and be sure the global variable has been set.
Did you also think about CFBundleDocumentTypes in the Info.plist file ?
Re: String of the file that opened the app?
Posted: Tue May 20, 2014 5:52 am
by Danilo
Works here.
Code: Select all
#My_Event_NewFiles = #PB_Event_FirstCustomValue
Global FileIn$ = ""
ImportC ""
PB_Gadget_SetOpenFinderFiles(Callback)
EndImport
IsGadget(0)
ProcedureC OpenFinderFilesCallback(*Utf8Files)
FileIn$ = PeekS(*Utf8Files, -1, #PB_UTF8)
PostEvent(#MY_EVENT_NEWFILES)
EndProcedure
PB_Gadget_SetOpenFinderFiles(@OpenFinderFilesCallback())
OpenWindow(0,0,0,200,200,"OpenFinderFilesCallback",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : End
Case #My_Event_NewFiles : MessageRequester("Result", FileIn$)
EndSelect
ForEver
Info.plist additions:
Code: Select all
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>smpf</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>FileIcon.icns</string>
<key>CFBundleTypeName</key>
<string>Sprite Monkey Project</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
Re: String of the file that opened the app?
Posted: Tue May 20, 2014 6:11 am
by J. Baker
@ Danilo - That does work great, thanks!
@Wilbert - Yeah, I have the icon made and everything.
Now I'm trying to get the file association done. For some reason it's not working. I've done it before, just like the plist example you posted and all was fine but not now for some reason. May have to log into OS X 10.6 and try there.
Re: String of the file that opened the app?
Posted: Tue May 20, 2014 7:32 am
by J. Baker
It's done! Thanks you both for the feedback and help!
The weird thing was, I had to change my file icon name from "smpf.icns" to "FileIcon.icns". In the plist and the actual icon name, of course. I thought you could name them however you want.
Anyway, I've been testing it and all seems good but I'll do some more testing before uploading to iTunes Connect.

Re: String of the file that opened the app?
Posted: Tue May 20, 2014 12:44 pm
by Wolfram
On thing what I've noticed is, that I often have to restart the Finder before the file drag and drop works on a fresh compiled app.
Or you can use a tool which is called Refresh Finder.
The Name of the Icon has definitely no effect for the drag and drop function.
Re: String of the file that opened the app?
Posted: Tue May 20, 2014 4:58 pm
by J. Baker
I don't have any issues with drag and drop but thanks.
