I have the following code in the DoubleClick event of a listbox.
var theItem as FolderItem
theItem = new FolderItem(me.SelectedRowValue, FolderItem.PathModes.Native)
theItem.parent.Open
The string in me.SelectedRowValue is a path to a file. The path is a correct native path.
When I run the code, however, the constructed FolderItem theItem is created with a path that appears to be relative to the application. In other words the path of the created folderItem is the path to the application, plus a space, plus the native path to the file.
Like this: /Users/JohnDoe/Documents/Tools/Xojo Projects/ /Users/JohnDoe/Documents/Tools/DATA_SETS/Files/test-file.jpg
Why might that be? I’ve done this before but I’ve never seen this behavior.
What am I overlooking?
Yes, there’s a space in it – and that’s part of the issue and I’m not sure why.
The space is between what appears to be the path to the location of the application and the path to the file in question.
I just tried with the latest Catalina and Xojo and can’t duplicate it. Just to confirm, if you stick a “MessageBox me.selectedRowValue” before you create theItem, you get " “/Users/JohnDoe/Documents/Tools/DATA_SETS/Files/test-file.jpg” and if you do “MessageBox theItem.NativePath” afterward, you get the version with the space?
Are you saying that Xojo is adding a space to the left of the path?
Seems really odd… And I would recommend that someone who can reproduce this file a Feedback Report with Xojo ASAP.
In the meantime if you use trim( <path/> ) does this resolve it?
Edit: Trimming the path may resolve this problem, but it will break the ability for a user to select a file with has a space at the end of the file name. Perhaps using
if left( path, 1 ) = " " then
path = right( path, len( path ) -1 )
end if
(off) - I find using the rowtag to hold a folderitem reference is easier
As you build your listbox, instead of just doing the name as the text of the row, set the rowtag to be the folderitem
Then, your code becomes something like this (I dont use API2 myself)
var theItem as FolderItem
theItem = me.rowtag(row)
theItem.parent.Open
That’s handy to know for other things I’m doing but in this case I’m getting the path by parsing the string output of a third party terminal routine. (My problem was that I failed to notice a space at the beginning of the parsed string. Fixed with a String.TrimLeft.)
@samRowlands that was it. The path is the result of parsing the string outpout of a third party terminal routine. I failed to notice a space at the beginning of the parsed string. Fixed with a String.TrimLeft .
Not wanting to derail this thread, but this is sort-of on topic.
I’ve had issues storing the folderitem in the rowtag on Mac. The file couldn’t be found when retrieving the folderitem from the listbox. Had to change to storing the nativepath instead.
This was with API2, but supposedly the underlying functions shouldn’t have changed. I haven’t taken the time to test it under API1 to see if it performs differently.
API 2 has had weird bugs
A RecordSet in API 1 works but the rowset didnt and switching back worked again
There have been several cases reported like that where updating to the API 2 version didnt work as expected
This could be another case like that
Such a reason why I hate when the Shell is the only way to do something, as parsing shell results are hard and easily unreliable.
I won’t ever understand why Shell and terminal commands can be “preferred methods” for some.