Mark menu item as checked
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Mark menu item as checked
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?
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
Hi redfield,
please check this LC lesson: http://lessons.livecode.com/m/2592/l/12 ... -menu-item
Best
Klaus
please check this LC lesson: http://lessons.livecode.com/m/2592/l/12 ... -menu-item
Best
Klaus
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Mark menu item as checked
Being "clever" I tried this:
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.
Code: Select all
on menuPick itemPicked
set the checkmark of itemPicked to true
end menuPick
- -
Mind you: it might "be lovely" if it were re-introduced into LiveCode.
Re: Mark menu item as checked
LOL Klaus, I was just starting to type
@Richmond - I agree that sure would be easier heh.
when you popped up the linkOf course it is, you might try menuItem and ...
@Richmond - I agree that sure would be easier heh.
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Mark menu item as checked
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
Post this as a feature request here: https://quality.livecode.comrichmond62 wrote: ↑Tue Oct 15, 2019 10:06 pmSeems a slightly long-winded way of doing something that seems to have been done in a simpler way in HyperCard.
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Mark menu item as checked
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.
"There we are."
Which must rank as one of the most ridiculous and meaningless phrases there is in English.
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Mark menu item as checked
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 to toggle the checkmark
use to check the state of the menu item.
here is an complete example
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
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
use
Code: Select all
put the ChoiceIsActive of me into tIsActive
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
Kind regards
Bernd
Re: Mark menu item as checked
OOooo, that is nice Bernd!
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Mark menu item as checked
Here are some code snippets that may help in handling popUp, pullDown, and Menu buttons
This allows for a single choice in above buttons
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
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
Kind regards
Bernd
Re: Mark menu item as checked
Nice! I had started down that path, but couldn't work out the text part
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Mark menu item as checked
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
and this lists the active (checked) choices of a multiple choices button
a complete script would look like this
again the custom properties getters can be put further in the message path.
Kind regards
Bernd
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
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
Kind regards
Bernd
-
- VIP Livecode Opensource Backer
- Posts: 3999
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Mark menu item as checked
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
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
- Attachments
-
- set check marks checkmarks Menu III.livecode.zip
- (2.42 KiB) Downloaded 210 times
-
- Livecode Opensource Backer
- Posts: 9359
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Mark menu item as checked
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 . . . .
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 . . . .
-
- VIP Livecode Opensource Backer
- Posts: 9823
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Mark menu item as checked
When was it ever present in LiveCode?richmond62 wrote: ↑Sat Oct 19, 2019 9:44 amHad the way things were done in HyperCard card not been removed...
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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn