It seems that without updating the Menu Item's callback each time the closure only references the first instance of the outer scope variable. Is there a better way to do this so that the nested function uses the new instance of the ctrl parameter each time that the ContextMenu callback is executed?
Code: Select all
copyListRow(ctrl, item, isRightClick, x, y) {
static rMenu := MenuCreate()
; seems like I have to update the menu item each time so that the ctrl variable is correct in performCopy
rMenu.Add("Copy Selected Rows", "performCopy")
rMenu.Show(x, y)
performCopy(name, pos, menuObj) {
row := 0
colCount := ctrl.GetCount("Col")
while (row := ctrl.GetNext(row)) {
loop(colCount) {
str .= ctrl.GetText(row, A_Index) . (A_Index == colCount ? "`n" : "`t")
}
}
clipboard := str
}
}