Cocoa work-around for ContextualMenu-ListBox

I already share the core of the work-around yesterday. And since then, I added two more things; here’s the text I prepared yesterday evening with the related code:

As the day’s going to its end, I come from a new version of the shared code earlier today.

Since this is a Cocoa specific code, why running it in the other targets ? I added a TargetCocoa block above and below the Cocoa previous specific code:

#If TargetCocoa // Previous code here // Cocoa only code #EndIf

The Row selection line is now in a If block and fired only if the Control key is depressed. (watch the Keyboard.AsyncControlKey block).

[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 is empty (have no Row)
If LB.ListCount = 0 Then Return

// The code is only needed for Cocoa
#If TargetCocoa Then
// 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)

// Only Row is use here, so I only check Row
If Row = -1 Then
  Return
End If

// Select the Row, but only if the Control key is depressed
If Keyboard.AsyncControlKey Then 
  LB.Selected(Row) = True
End If

#EndIf

// Show the selected folder
ShowFolderFI = LB.RowTag(Row)
If ShowFolderFI <> Nil And ShowFolderFI.Exists Then
// Open that folder
ShowFolderFI.Launch
End If

// That’s All Folks !
Return
End Sub[/code]

The code is a work-around for two Cocoa different behaviors vs Carbon / Windows (and probably Linux):

a. You don’t get the Mouse Clicked Row value (I get it through X,Y locations, watch code).
b. When you press Right-Click+Ctrl on a ListBox, the clicked Row is not selected.

In the above code, I set inside a TargetCocoa block the code to get the clicked Row # AND select the cliked Row, only for a Ctrl-Click.

Nota: In work-around #2, the Row is selected if you use Left-Click with the Mouse.