Page 1 of 4
Mark menu item as checked
Posted: Tue Oct 15, 2019 9:05 pm
by redfield
Hey Experts,
I have created a menu with the menu builder and in the builder noticed an option to mark an item as checked. When I select it, a !c appears in front of the item and in the application the item appears as checked. But I don't want it permanently checked but only when the item has been clicked. I tried coding it with the property the mark but without success. Is it actually possible to code this?
Re: Mark menu item as checked
Posted: Tue Oct 15, 2019 9:33 pm
by Klaus
Re: Mark menu item as checked
Posted: Tue Oct 15, 2019 9:41 pm
by richmond62
Being "clever" I tried this:
Code: Select all
on menuPick itemPicked
set the checkmark of itemPicked to true
end menuPick
But that was because I was silly and didn't read
THIS first:
-
-
Mind you: it might "be lovely" if it were re-introduced into
LiveCode.
Re: Mark menu item as checked
Posted: Tue Oct 15, 2019 9:50 pm
by bogs
LOL Klaus, I was just starting to type
Of course it is, you might try menuItem and ...
when you popped up the link
@Richmond - I agree that sure would be easier heh.
Re: Mark menu item as checked
Posted: Tue Oct 15, 2019 10:06 pm
by richmond62

- Screenshot 2019-10-16 at 0.04.52.png (6.93 KiB) Viewed 9719 times

- oink.jpg (7.35 KiB) Viewed 9719 times
-
Seems a slightly long-winded way of doing something that seems to have been done in a simpler way in HyperCard.
Re: Mark menu item as checked
Posted: Wed Oct 16, 2019 11:27 am
by Klaus
richmond62 wrote: ↑Tue Oct 15, 2019 10:06 pm
Seems a slightly long-winded way of doing something that seems to have been done in a simpler way in HyperCard.
Post this as a feature request here:
https://quality.livecode.com
Re: Mark menu item as checked
Posted: Wed Oct 16, 2019 6:36 pm
by richmond62
https://quality.livecode.com/show_bug.cgi?id=22413
"There we are."
Which must rank as one of the most ridiculous and meaningless phrases there is in English.

Re: Mark menu item as checked
Posted: Fri Oct 18, 2019 4:14 pm
by bn
Here are some code snippets that may help in handling popUp, pullDown, and Menu buttons
This allows for multiple choices in above buttons
put this into the script of above buttons
use
Code: Select all
set the toggleChoice of me to pItem
to toggle the checkmark
use
Code: Select all
put the ChoiceIsActive of me into tIsActive
to check the state of the menu item.
here is an complete example
Code: Select all
on menuPick pItem
local tIsActive
## toggle choice on/off of multiple items of
## a menu button, a pop up button or a pulldown button
set the toggleChoice of me to pItem
## check the state of the choice if you need to know
put the ChoiceIsActive of me into tIsActive
-- more code
end menuPick
setProp toggleChoice pItem
local tText, tLineNum, tPrefix
put "!c" into tPrefix
put the text of the target into tText
put lineOffset(tPrefix & pItem, tText) into tLineNum
if tLineNum is 0 then
put lineOffset(pItem, tText) into tLineNum
end if
if char 1 to 2 of line tLineNum of tText is tPrefix then
put empty into char 1 to 2 of line tLineNum of tText
else
put tPrefix before line tLineNum of tText
end if
set the text of the target to tText
end toggleChoice
getProp ChoiceIsActive
return line (the menuHistory of the target) of the text of the Target begins with "!c"
end ChoiceIsActive
You can put the setter and getter (setProp toggleChoice, getProp ChoiceIsActive) either into the same script or into a script in the message path. Typically a card script or the stack script. These are then accessible to all buttons that use "set the toggleChoice of me to pItem" and "put the ChoiceIsActive of me into tIsActive".
Kind regards
Bernd
Re: Mark menu item as checked
Posted: Fri Oct 18, 2019 4:16 pm
by bogs
OOooo, that is nice Bernd!
Re: Mark menu item as checked
Posted: Fri Oct 18, 2019 4:19 pm
by bn
Here are some code snippets that may help in handling popUp, pullDown, and Menu buttons
This allows for a single choice in above buttons
Code: Select all
on menuPick pItem
set the checkChoice of me to pItem
end menuPick
setProp checkChoice pItem
local tText
put the text of me into tText
replace "!c" with empty in tText
put "!c" before line (lineOffset(pItem, tText)) of tText
set the text of me to tText
end checkChoice
Again you can put the handler "setProp checkChoice" further along in the message path so it is accessible from mutliple buttons of the same setup.
Kind regards
Bernd
Re: Mark menu item as checked
Posted: Fri Oct 18, 2019 4:47 pm
by bogs
Nice! I had started down that path, but couldn't work out the text part

Re: Mark menu item as checked
Posted: Fri Oct 18, 2019 4:48 pm
by bn
this are two helper handlers for
Multiple Choices buttons
it lets you find out the state of the button with mulitple choices and returns the state of the currently clicked item
Code: Select all
getProp ChoiceIsActive
return line (the menuHistory of the target) of the text of the Target begins with "!c"
end ChoiceIsActive
and this lists the active (checked) choices of a multiple choices button
Code: Select all
getProp activeChoices
local tText, tChoices
put the text of the target into tText
repeat for each line aChoice in tText
if aChoice begins with "!c" then
put aChoice & cr after tChoices
end if
end repeat
delete char -1 of tChoices -- a return
return tChoices
end activeChoices
a complete script would look like this
Code: Select all
on menuPick pItem
local tIsActive, tActiveChoices
set the toggleChoice of me to pItem
## check the state of the current choice
## returns true if checked else false
put the ChoiceIsActive of me into tIsActive
## returns a list of items that are currently checked
put the activeChoices of me into tActiveChoices
-- put the current state of a choice and the
-- checked choices of a multiple choices button
put tIsActive &cr & tActiveChoices && the milliseconds
-- more code
end menuPick
setProp toggleChoice pItem
local tText, tLineNum, tPrefix
put "!c" into tPrefix
put the text of the target into tText
put lineOffset(tPrefix & pItem, tText) into tLineNum
if tLineNum is 0 then
put lineOffset(pItem, tText) into tLineNum
end if
if char 1 to 2 of line tLineNum of tText is tPrefix then
put empty into char 1 to 2 of line tLineNum of tText
else
put tPrefix before line tLineNum of tText
end if
set the text of the target to tText
end toggleChoice
getProp ChoiceIsActive
return line (the menuHistory of the target) of the text of the Target begins with "!c"
end ChoiceIsActive
getProp activeChoices
local tText, tChoices
put the text of the target into tText
repeat for each line aChoice in tText
if aChoice begins with "!c" then
put aChoice & cr after tChoices
end if
end repeat
delete char -1 of tChoices -- a return
return tChoices
end activeChoices
again the custom properties getters can be put further in the message path.
Kind regards
Bernd
Re: Mark menu item as checked
Posted: Sat Oct 19, 2019 12:27 am
by bn
here is a stack that sums it all up
It has some refinements over the scripts I posted above. Please use this stack.
The card script contains the working code for the buttons which just invoke that code.
Kind regards
Bernd
Re: Mark menu item as checked
Posted: Sat Oct 19, 2019 9:44 am
by richmond62
Had the way things were done in HyperCard card not been removed
all this long, complicated discussion would not have been necessary.
I assume (?) that the reason the HyperCard way was removed was for
a good reason . . . .
Re: Mark menu item as checked
Posted: Sat Oct 19, 2019 2:58 pm
by FourthWorld
richmond62 wrote: ↑Sat Oct 19, 2019 9:44 am
Had the way things were done in HyperCard card not been removed...
When was it ever present in LiveCode?
Of all the xTalk dialects I've used, I've never seen any of them claim to be a true superset of HyperTalk. Each has at least least some HyperTalk syntax implemented differently or not at all. To the best of my recollection this has been true of SuperCard, OMO, Plus, Gain, Toolbook, and others in addition to LiveCode.