Adding an 'Edit Behavior' item to the IDE context menu

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Contact:

Adding an 'Edit Behavior' item to the IDE context menu

Post by splash21 » Wed Jan 01, 2014 2:11 pm

Happy new year, everyone. The MobGUI plugin has an optional menu item in the IDE context menu to edit the behavior of a control (or controls) and it was pointed out that this would be a handy thing to have in general, so here it is. :) Hopefully this little feature will make it's way into LiveCode's IDE, but - in the meantime - you can always add this snippet to your own utilities, or even just use it as is.

Code: Select all

# catch the IDE's context menu message
on revHookBuildObjectEditorContextMenu pMenuTarget, pMenuName, @pMenu, pModifiedMenu
   
   local tMenu, tSelected, tBehavior
   
   # custom menu item
   repeat for each line tSelected in selObj()
      put the behavior of tSelected into tBehavior
      if tBehavior <> empty and exists(tBehavior) then
         put "Edit Behavior" & LF after tMenu
         exit repeat
      end if
   end repeat
   
   # prepend the standard context menu
   if tMenu <> empty then
      put tMenu & "-" & LF before pMenu
   end if
   
   pass revHookBuildObjectEditorContextMenu
end revHookBuildObjectEditorContextMenu





# catch the IDE's message when an item is selected from the context menu
function dispatchContextMenuPick pMenuName, pItem
   
   local tSelected, tBehavior
   
   switch word 1 to -1 of pItem
         
      case "Edit Behavior"
         repeat for each line tSelected in selObj()
            put the behavior of tSelected into tBehavior
            if tBehavior <> empty and exists(tBehavior) then
               edit the script of tBehavior
            end if
         end repeat
         exit to top
         break
         
   end switch
   
   pass dispatchContextMenuPick
end dispatchContextMenuPick
... and here it is in a little plugin ...
s21EditBehavior.livecode.zip
(1.56 KiB) Downloaded 302 times

Enjoy the rest of the holiday period!
Last edited by splash21 on Thu Jan 02, 2014 3:21 pm, edited 2 times in total.
LiveCode Development & Training : http://splash21.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Adding an 'Edit Behavior' item to the IDE context menu

Post by Mark » Wed Jan 01, 2014 3:49 pm

Thank, this is a nice idea.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7394
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Adding an 'Edit Behavior' item to the IDE context menu

Post by jacque » Wed Jan 01, 2014 8:34 pm

Wonderful, thanks John. This is a very useful addition.

Edit: Seems to be a typo in the "else" clause of the preOpenCard handler in the plugin:

set the uAcive...

should be "uActive", yes?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

splash21
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 369
Joined: Sun Dec 19, 2010 1:10 am
Contact:

Re: Adding an 'Edit Behavior' item to the IDE context menu

Post by splash21 » Thu Jan 02, 2014 3:18 pm

Well spotted! I've been using strict compilation mode for MobGUI, but that plugin stack was originally an example from yesteryear... A nice example of how strict compilation mode is worth the extra small bit of effort - specially for larger scripts :)
LiveCode Development & Training : http://splash21.com

Post Reply