Ok, now that I understand what you are really asking, I had another look...
The P2 example works on Windows, but doesn't work on Mac (don't have Linux handy to test). The reason that it doesn't work on Mac is due to the way the application is packaged for the OS.
You don't really need to set the defaultFolder (put an "answer the defaultFolder" in the preOpenStack). When the engine goes looking for images, it starts at the stack/executable location (if not an absolute path). In a Mac application package, that is 3 levels deeper (Application.app/Contents/MacOS/Application). I tested this theory in 2 ways. The first was to copy the image into the same location as the actual executable file. The second was to change the "set the path" button to use "../../../Test2.png" as the image target.
Part of the original issue is that when you choose files, the absolute path is stored. If you want to test out a way to have the PI use relative paths, you can edit
com.livecode.pi.file.behavior (Tools/Toolset/palettes/inspector/editors/):
Code: Select all
on mouseUp pButton
local tOptions
put the editorOptions of me into tOptions
if the name of the target contains "button" and pButton is 1 then
if tOptions is not empty then
replace return with comma in tOptions
end if
local tResult
revIDEAnswerFileWithTypes tOptions
put the result into tResult
if there is a file tResult then
local tStackPath, tFilePath
set the itemDelimiter to "/"
put item 1 to -2 of the filename of stack revtargetstack(line 1 of (the selObj)) into tStackPath
put revCalculateRelativePath(tStackPath, tResult) into tFilePath
if there is a file (tStackPath & slash & tFilePath) then put tFilePath into tResult
put tResult into field 1 of me
valueChanged
end if
end if
end mouseUp
All of the changes are in the last if statement. I'm not sure if there are any other reasons not to do this, but if you make the edits inside of LiveCode, then they go away when you quit. (Of course, this is based on the new PI so I guess it would only apply to 8 or 9, I developed the code in 9DP10).
This does not address the issue of the relative path being different between Mac and Win/(Linux?) applications. On a Mac, all of the extra files can be included inside the package which makes moving it around easier for the user. On Win/Linux, the extra files are in folders next to the executable.
EDIT: See
https://github.com/livecode/livecode-ide/pull/1817 for the latest version of the code above.