KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Enabling text copy and paste without a menu bar
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: August 3, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

You can't copy and paste text if you do not define a menu bar. However, if you really need to be able to copy and paste text without a menu bar in your dialog, then this Tech Tip will show you how. Of course, it will be up to you do handle the Select All, Copy, Cut, and Paste shortcuts.

In this example, let's have a text variable named Area and let's create these scripts for this variable:

You can create 4 invisible buttons with the keyboard shortcuts Command+A, Command+C, Command+X, and Command+V with the following scripts:

`Button1 Command+A/CTRL+A:
` Select All

HIGHLIGHT TEXT(area;1;32000)

  `Button2 Command+C/CTRL+C:
  ` Copy
GET HIGHLIGHT(area;startSel;endSel)
If ((startSel>0) & (startSel#endSel))
 $text:=Substring(area;startSel;endSel-StartSel)
 SET TEXT TO CLIPBOARD($text) ` Copy selected text
Else
 SET TEXT TO CLIPBOARD(area) ` No selection/ Copy all
End if

  `Button3 Command+X/CTRL+X:
  ` Cut
GET HIGHLIGHT(area;startSel;endSel)
If ((startSel>0) & (startSel#endSel))
 $text:=Substring(area;startSel;endSel-StartSel)
 SET TEXT TO CLIPBOARD($text)    ` Copy selected text
 $text1:=Substring(area;1;startSel-1)
 $text2:=Substring(area;endSel;32000)
 area:=$text1+$text2    ` Cut the text by removing it
Else
 SET TEXT TO CLIPBOARD(area)    ` No selection/ Cut all
 area:=""
End if

  `Button4 Command+V/CTRL+V:

  ` Paste
GET HIGHLIGHT(area;startSel;endSel)    ` Remove selected text and insert clipboard
$text1:=Substring(area;1;startSel-1)
$text2:=Substring(area;endSel;32000)
area:=$text1+Get text from clipboard+$text2     ` Paste where cursor is