Karen, Eli:
I cannot make my mind on what to do because both behaviors have good reasons to do like they do.
Back to the main question; here’s the message I wrote earlier:
Because I forgot to save this Conversation, I had to write this one and here’s what I ended with:
[code]Sub ShowFolder(LB As ListBox)
Dim ShowFolderFI As FolderItem
Dim LocX As Integer
Dim LocY As Integer
Dim Row As Integer
Dim Column As Integer
// Do nothing if the ListBox have no Row
If LB.ListCount = 0 Then Return
// Get the LocX, LocY values
LocX = LB.MouseX - LB.Left
LocY = LB.MouseY - LB.HeaderHeight
// Get the clicked Row, Column values
Row = LB.RowFromXY(LocX, LocY)
Column = LB.ColumnFromXY(LocX, LocY)
// Test only Row
If Row = -1 Then
Return
End If
// Set the Row as Selected (for Ctrl-Click)
LB.Selected(Row) = True
// Show the selected folder
ShowFolderFI = LB.RowTag(Row)
If ShowFolderFI <> Nil And ShowFolderFI.Exists Then
// Open that folder
ShowFolderFI.Launch
End If
// Thats All Folks !
Return
End Sub[/code]
The Method is called from the ContextualMenuAction Event (where due to get the folder open).
It works fine, but I do not understand why I have to compute X: LB.MouseX - LB.Left.
Extensively tested on OS X, a bit of testing done on Windows XP, not tested in Linux (no Linux flavor installed in VirtualBox).
It is now too late to add the following idea in the shared code, but here I am.
Since Eli said that, I was not aware there is a difference beween ctrl-click and Right-Click !
Earlier today, when I awoke, I was thinking that if the user Right-Click, the line below is useless:
LB.Selected(Row) = True
So, adding an If block to detect if the ctrl key is depressed may be a good idea. Virtual code:
If Keyboard.AsyncCtrl Then
LB.Selected(Row) = True
End If
One last word: the target ListBox have only one column and the code fits my needs. Your situation / use of ListBox may be different and you may have to modify my code. That is the reason I do not removed the line:
Column = LB.ColumnFromXY(LocX, LocY)
If you look closely the code, you will notice that I do not use Column
.
At last, the code is XPlatform: I do not used AppleScript nor AppleEvent to achieve the goal. Thanks goes to the community (where I get the idea).