4DPop Macros
adds macros available to the method editor. Using macro-commands saves a lot of time during method entry.
When the component is loaded, the macros are automatically installed and available in the method editor, they can be invoked:
- By clicking on the Macros button in the method editor toolbar.
- By double-clicking on their name in one of the footer lists of the method editor.
- For some of them (see the "Menu" column below) in the "Method" menu or the sub-menu of the "Insert macro" item of the editor's contextual menu.
- For some, by a keyboard shortcut indicated in the "Shortcut" column below.
- For some, in the predictive input window. The triggering text is indicated in the "Input" column below.
For more information on the use and operation of macros, you can refer to the Creating and using macros of the 4D documentation.
That's why they have an associated shortcut š
Name | Goal | Menu | Input | Shortcut* |
---|---|---|---|---|
Declarationsā¦ | Help with the declaration of parameters and local variables | āļø | ā $ | |
CompilerĀ directiveā¦ | Help to enclose selection with //%W directive | āļø | āĀ ā„Ā ā§Ā c | |
Beautifierā¦ | A code formatter | āļø | ā Ā§ | |
CopyĀ andĀ replace | Swaps the selection with the contents of the clipboard | āļø | ā ā„Ā c | |
SpecialĀ pasteā¦ | Paste the text contained in the clipboard by applying transformations | āļø | _p | āĀ ā„Ā v |
Comments | Intelligent comment/uncomment | āļø | āĀ j | |
DuplicateĀ andĀ comment | The selected text is saved as a comment immediately before the selection. | āļø | āĀ ā„Ā d | |
Replay last macro | Replays the last macro used for the method being edited | āļø | ā + |
*Shortcuts may be displayed incorrectly in the macro menu because they are interpreted. e.g. ā ā„ c
will be displayed ā Ā©
This tool operate on the selected text of the frontmost method (or on the whole method if there is no selection*). It extract the parameters and local variables, then tries to discover their type and displays the list of elements found, allowing you to change their type. Once validated, the declarations are placed at the top of the method or selection according to your choice. The declaration tool is able to parse the C_xxx directives and replace it using the var
keyword.
*Not yet for a class method, so it's best to work with the selection for now.
-
ā The list displays first the parameters, then the local variables.
- For each element, an icon represents the type deduced, and the number of uses in the analyzed code is displayed on the right.
- The elements for which the type could not be determined are displayed in red.
- Items that were found in a statement instruction, but are not used, are displayed in orange. They will not be included in the created directives.
- Arrays are underlined.
-
ā” The line of code in which the first occurrence of the element was found is displayed under the list
- The same information is available via the tooltip.
-
ā¢ To the right are the available types.
- The shortcut for each type is
option + the underlined letter
of the label - The class is displayed when relevant.
- The shortcut for each type is
-
ā£ The Filter menu allows you to display only certain items.
- ā¤ If you validate, the directives are pasted at the top of the method or selection, before the first line which is not a comment. Untyped or unused variables are ignored, declarations that have been made throughout the method, as well as all previous declarative blocks are deleted.
- If you close the window with the close box, the method is not changed.
Arrays:
šSince declaration and sizing use the same command, you can force the position of the command by using hexadecimal notation (or a variable) for the size, i.e.:
ARRAY LONGINT($array; 0x0000) ARRAY TEXT($array; $size)šTwo-dimensional arrays are not yet supported
- If a variable or a parameter is already declared (with var, C_xxx or #DECLARE). It is obvious ;-)
- If no declaration line was found, the tools try to deduce the type by analyzing the code.
- First by detecting simple patterns: for example,
$x:=10
gives the type Integer to $x,$o.key:=10
gives the type Object to $o. - Then, using the 4D command syntax:
$x:=Count parameters
gives the type Integer to $x,Is picture file ($pathname)
gives the type Text to $pathname. - And finally, if the type has still not been found using the nomenclature that you can define in the preferences.
- First by detecting simple patterns: for example,
- You can always force a type by selecting the one you want using the radio buttons on the right.
This macro is often useful even if the explanation of its operation seems complex. The usage scenario is as follows:
You type some code referring to a calculated expression and then you realize that you need this expression again later on and decide to put the expression in an intermediate variable. In this case you type $maVariable:=MyExpression
and then replace MyExpression
with $maVariable
.
With the macro:
- First type
$maVariable
and copy this text. - Then, select
MyExpression
and call the macro: The text "MyExpression" is placed in the clipboard and replaced by the text "$maVariable". - Then, you position the cursor after the first occurence of
$myVariable
and type:=
then paste the content of the clipboard to obtain$myVariable:=MyExpression
.
This tool formats the selected text, or the whole method if there is no selection, by applying the rules you have defined in the preferences.
The tool displays a dialog allowing to choose what will be pasted in the method editor. The "Result" area allows you to preview the text as it will be pasted.
The available transformations are :
- String: The text is pasted between quotation marks, the special characters (\r, \n, \t and ") are escaped .
- Comments: Each line is preceded by a comment mark, the text is not modified.
- HTML: The html code contained in the clipboard is assigned to a local variable. The characters are escaped.
- Regex Pattern: The text is pasted between quotation marks. The special characters of the pattern are escaped to be used as such taking into account that the backslash must be escaped in 4D.
- Pathname: Pastes the path name of a file or folder copied to disk. You can choose the POSIX format instead of the system and choose to use a path relative to the project folder if relevant.
- Insert in text: Allows you to insert an expression into a string by surrounding the clipboard content with
"+
and+"
. The text thus created replaces the text selected in the string or is inserted at the cursor position. - JSON code: Transforms a JSON text into code to create a 4D object
- Tokenized: Paste code with tokens
When the compiler displays warnings to draw your attention to instructions that could lead to runtime errors, you can, after analysis, selectively disable some of them during compilation.
To do this, select the line(s) of code in the method editor that cause this warning and select the "Compiler directiveā¦" action from the macro menu. The tool asks for the number displayed in brackets (e.g. 538.3) and when you validate, surrounds the selected code with the pattern //%W-538.3
... //%W+538.3
.
If the selected text is already commented, it is uncommented. Otherwise, the macro analyzes the selected text to choose the best commenting method:
- single-line comment:
// CLOSE DOCUMENT($Doc_shortcuts)
- block comment:
/*
APPEND TO ARRAY($tTxt_attributeName; "editable")
APPEND TO ARRAY($tTxt_attributeValue; "false")
*/
- intra-line
ON ERR CALL(/*"noERROR"*/"")
I use it when I want to preserve a piece of code before editing it, but an image is better than text ;-)
As the name suggests, the selected code is copied with the tokens.
Name | Goal | Menu | Input | Shortcut* |
---|---|---|---|---|
Macro test | Call the project method 4DPop_TEST_Macros of your database. Be sure to share the method. |
āļø | ā 0 | |
Paste a color | Displays the system color palette and pastes the value of the selected color. | āļø | _c | |
FindĀ withĀ Google | Launch a Google search, in the default browser, with the selected test | āļø | ||
New methodā¦ | Creates a new method containing the selected text and replaces the selection with the method name. | āļø | ||
RemoveĀ blankĀ lines | As the name suggests | āļø | ā * | |
Comment block | Surround the selection with /* and */ |
āļø |
š§
š§