The LiveCode User Guide suggests the disable/enable code go in the grp "Menubar 1" script. "If you want to dynamically change a menu's contents with a mouseDown handler at the time the menu is displayed, you must place the mouseDown handler in the group's script. When a menu button is being displayed in the Mac OS menu bar, it does not receive mouseDown messages, but its group does."
So in grp "Menubar 1" script:
Code: Select all
on mouseDown --enable/disable menuItems
switch (the short name of target())
case "Edit"
get selectedChunk()
if it = empty then --no inserted cursor, no selected text
disable menuItem 1 of menu "Edit" --cut
disable menuItem 2 of menu "Edit" --copy
disable menuItem 3 of menu "Edit" --paste
else if word 2 of it > word 4 of it then --inserted cursor
disable menuItem 1 of menu "Edit" --cut
disable menuItem 2 of menu "Edit" --copy
enable menuItem 3 of menu "Edit" --paste
else if word 2 of it < word 4 of it then --selected text
--disable menuItem 1 of menu "Edit" --possible bug, won't enable without disable first if previously disabled
enable menuItem 1 of menu "Edit" --cut
enable menuItem 2 of menu "Edit" --copy
enable menuItem 3 of menu "Edit" --paste
end if
break
end switch
end mouseDown
on mouseLeave --enable menuItems, allow keyboard equivs
if the short name of target() = "Edit" then
--disable menuItem 1 of menu "Edit" --possible bug, won't enable without disable first if previously disabled
enable menuItem 1 of menu "Edit" --cut
enable menuItem 2 of menu "Edit" --copy
enable menuItem 3 of menu "Edit" --paste
end if
end mouseLeave
After Edit menuItems are disabled, they fail to re-enable using the pull-down menu. This seems to be fixed by placing a disable command before the enable commands. Strange. No help with an additional enable command, wait 0 secs with messages, re-wording the enable commands with 'menu "Edit" of me', or replacing the disable/enable commands with "(".
Problem2: After the fix for problem1, if I use the Edit menu to cut and paste text, immediately select new text, I can't cut with ctrl-x. Using the menu doesn't send a mouseLeave message to re-enable menuItems for keyboard equivilents. No fix.
Any suggestions how to script a working standardized Edit menu? Terry
stack demo: