Pull-Down Menu Stack For NoSave Standalone
Posted: Wed Apr 16, 2014 7:46 pm
Any self-respecting menu bar disables the Edit menuItems cut/copy/paste under certain conditions. I've been having two problems re-enabling them. Any help would be much appreciated. (Win 7, LC 6.5.2)
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:
Problem1: There may be something wrong with the enable command. If I use the Edit menu to cut and paste text, immediately select new text, I can't use the Edit menu because cut/copy menuItems are still disabled.
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:
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: