Pull-Down Menu Stack For NoSave Standalone

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
TerryL
Posts: 78
Joined: Sat Nov 23, 2013 8:57 pm

Pull-Down Menu Stack For NoSave Standalone

Post by TerryL » 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:

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
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:
EnableTest.zip
(3.42 KiB) Downloaded 188 times
Last edited by TerryL on Thu Apr 24, 2014 7:48 pm, edited 1 time in total.
Beginner Lab (LiveCode tutorial) and StarterKit (my public stacks)
https://tlittle72.neocities.org/info.html

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7228
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Edit MenuItems Enable Problem

Post by jacque » Thu Apr 17, 2014 10:07 pm

Typically all the commands are done in the mouseDown handler. (I'm a little surprised to learn that mouseleave is supported in menus, but probably that's because I develop on a Mac where menus behave differently.)

What I always do is enable everything, and then disable the parts I don't want. In your example:

Code: Select all

on mouseDown
 repeat with x = 1 to 3
   enable menuitem x of btn "edit" of me
 end repeat
 switch (the short name of target())
   case "Edit"
     get selectedChunk()
       ... etc 
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

TerryL
Posts: 78
Joined: Sat Nov 23, 2013 8:57 pm

Re: Edit MenuItems Enable Problem

Post by TerryL » Sat Apr 19, 2014 8:35 pm

Thanks to Jacque's comments I removed the mouseLeave handler from the grp "Menubar 1" script and placed a commandKeyDown handler in the stack script to restore edit menu keyboard equivilents, which as I understand is cross-platform compatible. This fixed both problems.

I added Undo to the edit menu, and fixed a small problem with the menu bar width following the stack width in Geometry manager. I think everything works on Win 7, LC 6.5.2. A public stack with a pull-down menu is quite rare. I searched the forum and revOnline and found only two, both from Jacque. This one is free for anyone to use in their projects.

Could someone try it out on a Mac and verify? Terry

Code: Select all

--in grp "Menubar 1" script:
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 3 of menu "Edit"  --cut
            disable menuItem 4 of menu "Edit"  --copy
            disable menuItem 5 of menu "Edit"  --paste
         else if word 2 of it > word 4 of it then  --inserted cursor
            disable menuItem 3 of menu "Edit"  --cut
            disable menuItem 4 of menu "Edit"  --copy
            enable menuItem 5 of menu "Edit"  --paste
         else  --selected text
            enable menuItem 3 of menu "Edit"  --cut
            enable menuItem 4 of menu "Edit"  --copy
            enable menuItem 5 of menu "Edit"  --paste
         end if
         break
   end switch
end mouseDown

--In stack script:
on commandKeyDown pKey  --cross-platform
   if pKey = "c" then copy
   else if pKey = "v" then paste
   else if pkey = "x" then cut
   else pass commandKeyDown
end commandKeyDown
Attachments
NoSave Pull-Down Menu.zip
(3.09 KiB) Downloaded 177 times
Last edited by TerryL on Mon May 05, 2014 7:23 pm, edited 2 times in total.
Beginner Lab (LiveCode tutorial) and StarterKit (my public stacks)
https://tlittle72.neocities.org/info.html

TerryL
Posts: 78
Joined: Sat Nov 23, 2013 8:57 pm

Re: Pull-Down Menu Stack For NoSave Standalone

Post by TerryL » Thu Apr 24, 2014 7:54 pm

Added a button to assist changing the Help > About menuItem.

The pull-down menu is fully functional. Terry
Beginner Lab (LiveCode tutorial) and StarterKit (my public stacks)
https://tlittle72.neocities.org/info.html

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9823
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Edit MenuItems Enable Problem

Post by FourthWorld » Thu Apr 24, 2014 8:15 pm

TerryL wrote:Thanks to Jacque's comments I removed the mouseLeave handler from the grp "Menubar 1" script and placed a commandKeyDown handler in the stack script to restore edit menu keyboard equivilents, which as I understand is cross-platform compatible. This fixed both problems.
If memory serves, you shouldn't need to add a commandKeydown message as command keys which can trigger menu items cause a mouseDown to go to the menuGroup before the menus are rendered, thus allowing us to centralize menu updating code in one mouseDown handler in the menu group.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

TerryL
Posts: 78
Joined: Sat Nov 23, 2013 8:57 pm

Re: Pull-Down Menu Stack For NoSave Standalone

Post by TerryL » Fri Apr 25, 2014 7:20 pm

I re-tested the disabled Edit menuItems at Richard's suggestion. The commandKeyDown handler in the stack script IS necessary. If the cut, copy, or paste menuItems are disabled, their keyboard equivalents are also disabled and remain disabled until the mouseDown handler in the menu bar group script re-enables them. For example, with the commandKeyDown handler commented out, cut and paste text with the Edit menu. Now text can't be cut or copied with the keyboard unless the commandKeyDown handler is restored.

The ctrl-A (select all) and ctrl-Z (undo) though were unnecessary and now removed from the commandKeyDown handler in the updated attachment. Thanks for looking over the code Richard. It really does help make it better. Terry
Beginner Lab (LiveCode tutorial) and StarterKit (my public stacks)
https://tlittle72.neocities.org/info.html

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”