Page 1 of 1

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

Posted: Wed Jan 01, 2014 2:11 pm
by splash21
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!

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

Posted: Wed Jan 01, 2014 3:49 pm
by Mark
Thank, this is a nice idea.

Mark

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

Posted: Wed Jan 01, 2014 8:34 pm
by jacque
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?

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

Posted: Thu Jan 02, 2014 3:18 pm
by splash21
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 :)