On Jun 22, 2017, at 1:41 PM, Robert Broussard wrote: > Is there a way to use the contextual menu of the host OS (Mac or Windows) for > Cut, Copy & Paste within 4D?
It depends on the version of 4D that you are using for how much work you need to do. With v14+ there is a checkbox in the Property List for fields and variables in the “Entry” area called “Context Menu”. Check that option and you can right click in the field or variable and get the Cut, Copy & Paste options. If the object is set to be “Multi-style” you get even more options in the contextual menu. But the “Context Menu” property is only available for text and string fields or variables. Dates and numeric objects do not provide this option so you must do it yourself with code. Also if you are working with a 4D version prior to v14 you have to do this for all field and variable types. First turn on the “Clicked” form event for the field or variable on the form. Then add this method to the object method: HandleContextualMenu. // =========================================== // PROJECT METHOD: HandleContextualMenu // PARAMETERS: $1 = menu ref (optional) // $2 = method name (optional) // DESCRIPTION: Put this method in a form object and it will // respond to a right-click in the current object. // Pass no paramters and it will do the default which is to support // Cut, Copy and Paste in the current object. // CREATED BY: Tim Nevels, Innovative Solutions ©2016 // DATE: 4/1/16 // LAST MODIFIED: // ============================================ C_TEXT($1;$menuRef_t) C_TEXT($2;$methodName_t) If (Count parameters>=1) $menuRef_t:=$1 Else $menuRef_t:=<>defaultRightClickMenuRef_t End if If (Count parameters>=2) $methodName_t:=$2 End if C_TEXT($menuItem_t) C_LONGINT($mouseX;$mouseY;$mouseButton;$start;$end) If (Form event=On Clicked) GET MOUSE($mouseX;$mouseY;$mouseButton) If (Macintosh control down | ($mouseButton=2)) // right-click // determine enabled/disabled for Cut and Copy items GET HIGHLIGHT(Self->;$start;$end) If (($end-$start)>0) ENABLE MENU ITEM($menuRef_t;1) // Cut ENABLE MENU ITEM($menuRef_t;2) // Copy Else DISABLE MENU ITEM($menuRef_t;1) // Cut DISABLE MENU ITEM($menuRef_t;2) // Copy End if // determine enabled/disabled for Paste item If (Get text from pasteboard="") DISABLE MENU ITEM($menuRef_t;3) // Paste Else ENABLE MENU ITEM($menuRef_t;3) // Paste End if // display the menu $menuItem_t:=Dynamic pop up menu($menuRef_t) // handle the selected item Case of : ($menuItem_t="") // nothing selected : ($methodName_t#"") // use custom method handler EXECUTE METHOD($methodName_t;*;$menuItem_t) : ($menuItem_t="Cut") // handle default Cut operation POST KEY(Character code("x");Command key mask) : ($menuItem_t="Copy") // handle default Copy operation POST KEY(Character code("c");Command key mask) : ($menuItem_t="Paste") // handle default Paste operation POST KEY(Character code("v");Command key mask) End case End if End if I build the contextual menu On Startup for a little performance optimization with this method: // =========================================== // PROJECT METHOD: CreateDefaultRightClickMenu // PARAMETERS: none // DESCRIPTION: Creates the default right-click menu with // Cut, Copy and Paste // CREATED BY: Tim Nevels, Innovative Solutions ©2016 // DATE: 4/1/16 // LAST MODIFIED: // ============================================ <>defaultRightClickMenuRef_t:=Create menu APPEND MENU ITEM(<>defaultRightClickMenuRef_t;"Cut") SET MENU ITEM PARAMETER(<>defaultRightClickMenuRef_t;-1;"Cut") APPEND MENU ITEM(<>defaultRightClickMenuRef_t;"Copy") SET MENU ITEM PARAMETER(<>defaultRightClickMenuRef_t;-1;"Copy") APPEND MENU ITEM(<>defaultRightClickMenuRef_t;"Paste") SET MENU ITEM PARAMETER(<>defaultRightClickMenuRef_t;-1;"Paste") All of this would be unnecessary if 4D would simply enable “Context Menu” property for field types other than text and string. But as of v16 they do not so you have to do this workaround. Tim ******************************************** Tim Nevels Innovative Solutions 785-749-3444 timnev...@mac.com ******************************************** ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **********************************************************************