Hi everyone,
After reading the posts about a NSButtonCell, I still didn’t get it quite working what I want.
What I have is a table, containing a column with NSButtonCells and underneath the table an ordinary button.
I’d like to have when all check boxes in the table are unchecked that the other button is disabled. And when you check one again that the button is enabled again.
I had this idea of counting the checked cells and when they’re zero etc. etc. but that didn’t work out, the button got disabled okay but not enabled again. It’s hard to count them if you don’t know if they’re just checked or unchecked by the user.
So basically if nothing is checked, disable the button, else enable it again.
First I thought this was what I needed but I can’t get it to work the way I want it.
on clicked theObject
set ProcessList to {}
repeat with i from 1 to (count NewList) --Newlist is a list of (text) items on the table.
if contents of data cell 1 of data row i of data source of table view "TableView" of scroll view "ScrollView" of window "window" = true then
copy (contents of data cell 2 of data row i of data source of table view "TableView" of scroll view "ScrollView" of window "window") to end of ProcessList
end if
end repeat
if (count ProcessList) = 1 then -- Not 0 but 1 because the value returned is the number of checked items before this on clicked handler.
set enabled of button "button" of window "window" to false
end if
end clicked
Hi,
try this
on clicked theObject
set enableButton to false
repeat with i from 1 to (count NewList) --Newlist is a list of (text) items on the table.
if contents of data cell 1 of data row i of data source of table view "TableView" of scroll view "ScrollView" of window "window" = true then
set enableButton to true
exit repeat
end if
end repeat
set enabled of button "button" of window "window" to enableButton
end clicked
maybe this works, too
on clicked theObject
set enableButton to (contents of data cell 1 of data rows of data source of table view "TableView" of scroll view "ScrollView" of window "window" contains true)
set enabled of button "button" of window "window" to enableButton
end clicked
Thanks Stefan!
But both of them didn’t work… They come down to the same (I prefer the last one, it’s less code). The problem here is, when you click it, it gives the result before you click it not after. So if you have <I know this isn’t about counting but it’s the easiest way to explain> 3 check boxes, you uncheck one of them, the count will be 3, if you uncheck the other one, it will be 2, then the last one will say 1. But when you check one again, it will say 0. You understand what I mean? It’s always 1 count too late…
Really thanks so far!
this is a really weird behavior. Usually the state of the checkbox after clicking will be reported.
Sorry, I don’t have further experience with button cells in NSTableView
Maybe a short delay (< 1.0) solves the problem
No the delay doesn’t work…
Yes that’s true but somehow it isn’t with the NSButtonCells. Other weird behavior is this:
display dialog integer value of theObject as text
This will always return 1, whether it’s checked or not.
I tried this because when I know if a button is checked or unchecked, I can do like -1 or +1 of the count of the items in the table.
I don’t know if it are bugs, or things that are supposed to happen or just my fault. I don’t think I connected it wrong to the on clicked handler, it’s connected to NSButtonCell.
Anyway, thanks ![:slight_smile: :slight_smile:](/images/emoji/apple/slight_smile.png?v=12)
When a table checkbox is checked it becomes the “selected” row in the table. As such we can use that. If we get the value of the checkbox, and it’s the checkbox of the selected data row, then we know that the real value is the opposite. As such this should work…
set allRows to every data row of data source of objmainTable
set selectedDataRow to item 1 of (get selected data rows of objmainTable)
set oneCheckboxIsChecked to false
repeat with i from 1 to count of allRows
set thisRow to item i of allRows
if thisRow is selectedDataRow then
set checkVal to not (content of data cell "colCheck" of thisRow)
else
set checkVal to content of data cell "colCheck" of thisRow
end if
if checkVal is true then
set oneCheckboxIsChecked to true
exit repeat
end if
end repeat
if oneCheckboxIsChecked then
-- enable the button below the table
else
-- disable the button below the table
end if
Thanks regulus6633! :D, can you only give me one more hint?
is “colCheck” the name of the NSButtonCell? My script gives an error while clicking…
Something like:
Error Number: -1728 (isn’t that the “missing object” error?)
Error Message: Can’t get <> “ButtonCell” of < id 28 of <> id 27
That’s why I think I screwed it up with the naming of in your case “colCheck” and in my case “ButtonCell”… Can you tell me what to name? I tried NSButtonCell. I also changed objmainTable in
“table view “TableView” of scroll view “ScrollView” of tab view item “TabItem” of tab view “TabView” of window “Window””
Thanks
Hi John,
colCheck is the applescript name of the column in the table view in IB which contains the checkbox. But you can use the name you used before… data cell 2 of data row i of data source of table view “TableView” of scroll view “ScrollView” of window “window”.
objmainTable is what you thought, so that’s good.
Oh thanks, I renamed my column ![:slight_smile: :slight_smile:](/images/emoji/apple/slight_smile.png?v=12)
first I thought I had another problem because I thought your script was all about getting the state of the button but after seeing that it’s directly about enabling/disabling the button it all got sorted out. Thanks a lot!