Friday, April 10, 2020

Customizing IntelliSense - II


Last week I began a discussion of the VFP IntelliSense functionality by talking about the configuration of IntelliSense and how to control its various features. The foxcode.dbf table lies at the very heart of the VFP IntelliSense functionality and understanding how it is constructed and used is the key to making full use of the power of IntelliSense. So, at the risk of duplicating information that is already in the Visual FoxPro Help files, here is the structure and a brief explanation of how each column is used by the IntelliSense engine.
Table 1:FoxCode Table Structure
Field
Defined
Description
Type
C (1)
Identifier which defines how the record should be processed:
        C (Command)  Auto-complete items. Triggered by “ ”
        F (Function)    Quick Info items. Triggered by “(“
        O (COM)        The Type Library to use when populating the Members List for “DEFINE AS” declarations for COM objects
        P (Property)     Define actions when a property is accessed
        S (Script)       Execute the script in the Data Field
        T (Type)          The contents to use in the Members List for “DEFINE AS” declarations or for objects that do not have Type Libraries
        U (User)        User-defined
        V (Version)     Reserved for default/version information
        Z (Special)     No automatic interpretation, define custom behavior
Abbrev
C (24)
Abbreviated string to trigger the specified action
Expanded
C (26)
The string to replace the abbreviation with, where appropriate
Cmd
C (15)
The name of the script to execute for this item. Enclosed in “{}”
Tip
M ( 4)
The contents to display as a Quick Tip
Data
M ( 4)
Holds any content for this record. (List values, code, script text etc)
Case
C ( 1)
Specifies how Expanded text is formatted to replace abbreviated text
        U = use Upper() function to format
        L = use Lower() function to format
        P = use Proper() function to format
        M or <empty> = No formatting applied
        X = No replacement applied
Note: The value specified in the ‘Version’ record defines the default to be used for any record that does not have its own setting.
Save
L (1)
Flag to indicate whether record is preserved during updates (False for native items)
TimeStamp
T (8)
Timestamp (VFP Items Only)
Source
M (4)
The source to use for record content. (Native items use “Reserved”)
UniqueID
C (10)
Unique ID (VFP items only)
User
M ( 4)
Available for any user-defined information that is needed

The Advanced tab of the IntelliSense Manager form includes options to restore the FoxCode table. This means that if the table gets damaged, or even if you inadvertently delete or change some critical entry, you can simply restore the table to its original state. The nice thing about the restoration is that it will not destroy your custom items. The TimeStamp, UniqueID and Save fields are used whenever updating or restoring the FoxCode table to determine the origin of the data and whether it may be overwritten. By default the native Visual FoxPro entries have both a time stamp and a unique ID, but their Save field is set to False so that they can be overwritten. User defined entries, on the other hand, do not have either a unique ID or a time stamp, but the Save field is set to True so that when the table is updated, or refreshed, your user-defined items are preserved.
How FoxCode records are used
Each of the record types has a very specific set of functionality associated with it, and the different types indicate how the fields are interpreted by the IntelliSense engine.
Version Record (Type = “V”)
There is only one of these and it is intended for internal use by Visual FoxPro. The Expanded field contains the version number for the current FoxCode table, and the Case field defines the default setting for any item that does not have one set.
Command Record (Type = “C”)
This type is used for defining auto-complete text that is triggered by the space key and which use the “Default Script” that is defined in the Data field of the record with Type = S and an empty Abbrev field. All of the native commands use this methodology. However, you can also create your own ‘commands’ that explicitly associate Quick Info (from the Tip field) or a Members List (from the Data Field) by defining an abbreviation and including a call to the command handler script ({cmdhandler}) in the Cmd field.
Function Record (Type = “F”)
This type is used to define auto-complete text that is triggered by the left parenthesis character “(“. In this record type the contents of the Tip field are used to display the ‘smart’ Quick Info tips that track parameter entry by matching the pattern of the text you type with that defined in the record.
Property Record (Type = “P”)
This type is used to assign a pop-up dialog (or value list) to be displayed whenever a value is assigned to a property whose name matches the entry in the Abbrev field. The Cmd Field is used to indicate whether a script defined elsewhere in the table, or the contents of the Data field in the current record, are to be used to generate the list. The Version 9.0 FoxCode table ships with several generic scripts that are used with this record type. For example one (named {color}) displays the color picker dialog and is associated with a number of color definition properties (e.g. “BackColor”, “BorderColor” and “FillColor”). Another (named {picture}) displays the open picture dialog whenever either an “Icon” or “Picture” property is assigned and there are also scripts for {Font} and {MemberClassLib}.
COM Component Record (Type = “O”)
This type is used to define, to the IntelliSense engine, the Type Library for a COM Component (or ActiveX control). The Data field is used to store the GUID (and Version) information, and the Tip field to store the full name of the control. The content of the Abbrev field is included in drop down list of objects associated with an AS clause (DEFINE CLASS…AS…LOCAL…AS… ). However, the easiest way to add a COM object to the table is to use the IntelliSense Manager that ships with VFP because it avoids the necessity to go hunting in the registry for GUIDs and Class IDs.
Typing Record (Type = “T”)
This type is used to define an entry for the drop-down list of an AS clause. The difference between this type and preceding “O” record type is that there is no type library associated with this record type. Thus your own personal classes can be added to the drop down list displayed by the DEFINE CLASS command. The content of the Data field is displayed directly in the drop down list and this is the only field that needs to be completed. However, we do recommend adding a description to the Abbrev field to make maintaining the table easier, and if you add text to the tip field it will be displayed as you scroll over the entry in the list.
User Record (Type = “U”)
This record type is used to identify abbreviations for user-defined content. It differs from the Command type in that it replaces the content of the Abbrev field with the content of the Expanded field. Instead of just ‘completing’ text, it actually substitutes text – more like a keyboard macro than an auto-complete. There is no need to have the expanded text related to the abbreviation that triggers it.
You can also associate a script with a User Type record by including empty braces (“{}”) in the Cmd field. This indicates to the IntelliSense engine that the Data field of the record contains script code that is to be executed.
Script Record (Type = “S”)
This type is used to store code as named scripts that can be executed by the IntelliSense engine. To create a script all that is required is the name in the Abbrev field and the code in the Data field. Other records can trigger the execution of these scripts by including the name (enclosed in braces “{}”) in their Cmd field.
Whilst “S” type records are used to create “generic” scripts that can be used by more than one entry any record type (with the exception of “T” and “O” records) can include a script in its own Data field. However, in order to execute those scripts, a pair of empty braces “{}” must be inserted into the Cmd field.
Custom Extension Record (Type = “Z”)
This type is not covered by the documentation and is reserved for records that IntelliSense does not process automatically. There are two of these by default. The first “CustomPEMs” is used to store the ‘advanced’ configuration property information. The Tip column contains the prompts for display in the IntelliSense manager, while the Data column contains the settings as a list of attribute=value pairs. The second, named “CustomDefaultScripts“ is used to list the scripts that can be called by the default script handler (i.e. the space bar). The scripts named in this field are only activated when the “lAllowCustomDefScripts” configuration property is set to TRUE.
MemberData Extension (Type = “E”)
Introduced in Version 9.0 this type is used to indicate that the associated data is concerned with the extensibility offered by MemberData. For a full discussion of memberdata see the VFP 9.0 help file.

Next time we will look at how to create customized IntelliSense actions, and how the various record types are used in Visual FoxPro.

No comments:

Post a Comment

Writing better code (Part 1)

Writing better code (Part 1) As we all know, Visual FoxPro provides an extremely rich and varied development environment but sometimes to...