Common Desktop Environment: Advanced User's and System Administrator's Guide
11 Creating Data Types Manually
Contents of Chapter:
- Reasons You Must Create a Data Type Manually
- Components of a Data Type Definition: Criteria and Attributes
- Creating a Data Type Manually: General Steps
- Configuration Files for Data Types
- To Create a Data Type Definition
- Example of Creating a Personal Action and Data Type
- Defining the Data Attributes of a Data Type
- Specifying the Icon Image Used for a Data Type
- Associating Data Types with Actions
- Hiding Files Based on Data Type
- Specifying Behaviors When the File Is Manipulated
- Defining the Data Criteria for a Data Type
- Name-Based Data Types
- Location-Based Data Types
- Data Types Based on Name and Location
- Using File Modes as a Typing Criteria
- Content-Based Data Typing
- To Create a Data Type with Several Independent Criteria
There are two ways to create a data type definition:
- Creating Localized Data Types
- Locations for Localized Data Types
- To Localize a Data Type
Creating a data type manually requires you to edit a database file.
This chapter describes how to manually create data type definitions.
Manually creating a data type lets you use all the capabilities built into the syntax of data type definitions.
You must create an data type manually if you want to use these features of data types:
- Location (path)-based data typing
- The ability to specify actions associated with the data type other than Open and Print
- Multiple name, pattern, or content criteria for the same data type--for example, a data type based on files named *.abc or *.def
- Link-based data typing
A data type definition consists of two separate database definitions:
There must be at least one DATA_CRITERIA definition for each DATA_ATTRIBUTES definition; a DATA_ATTRIBUTES definition can have multiple DATA_CRITERIA associated with it.
- The DATA_ATTRIBUTES definition.
The DATA_ATTRIBUTES definition describes the data type's name and the appearance and behavior of files of this type.
- The DATA_CRITERIA definition.
The DATA_CRITERIA definition describes the typing criteria. Each criteria definition specifies the DATA_ATTRIBUTES definition to which the criteria apply.
For example, you could create an attributes definition for PostScript files that described how PostScript files look and behave in File Manager. Then, you could create two separate criteria for the PostScript data type-- one based on file name and the other based on file content.
For more information, see "Defining the Data Criteria for a Data Type".
This section describes how to create a data type configuration file.
The requirements for configuration files containing data type definitions are:
For information on modifying the database search path, see "Setting the Value of a Search Path".
- The files must use the naming convention name.dt
- The files must be located on the database search path. The default search path is:
- Personal data types
- System-wide data types
- Built-in data types
- /usr/dt/appconfig/types/language. You should not use this directory.
To Create a Data Type Definition
Suppose your system contains an application named xgif, which displays GIF pictures. Ordinarily, you run the program by executing:
- Open an existing database file or create a new one.
For more information, see the previous section, "Configuration Files for Data Types".
- Define the data attributes for the data type using the syntax:
See "Example of Creating a Personal Action and Data Type".
- A unique name given to this data type.
- File name or path of an icon file. Use the base name for the file. For example, for icon files myimage.m.pm and myimage.t.pm, use myimage.
- Field that defines the appearance or behavior of the data type.
- Character string. The contents will be the on-item help for the data type.
- Define the data criteria for the data type using the syntax:
See "Defining the Data Criteria for a Data Type".
- Unique name for this criteria definition
- Name used in the DATA_ATTRIBUTES definition
- Field used to define the criteria for assigning a file to this data type
- Save the database file.
- Create the icons for the data type.
For more information, see "Specifying the Icon Image Used for a Data Type".
- If necessary, create the actions listed in the ACTIONS field of the attributes definition.
- Double-click Reload Actions in the Desktop_Tools application group to reload the database.
You want to be able to display GIF pictures several ways:
- By double-clicking a GIF data file
- By selecting the data file and choosing the application from the Selected menu
- Open a new file HomeDirectory/.dt/types/GifViewer.dt for editing.
- Type the data type definitions:
DESCRIPTION Gif image file.
- Type the action definition for the GifViewer action:
Since the definition does not include an ICON field, the action will use the system's default icon.
EXEC_STRING xgif %(File)Arg_1"Gif file to view:"
DESCRIPTION Double-click or drop a file to \
start the Gif viewer.
- Type the following map action to connect the GifViewer action to the View action listed in the data type definition. Use the ARG_TYPE field to restrict this view action to Gif-type files.
- Save the file.
- Double-click Reload Actions in the Desktop_Tools application group to reread the database.
Defining the Data Attributes of a Data Type
The DATA_ATTRIBUTES definition defines the appearance and behavior of the data type. It specifies the name of the data type, and provides the ability to specify:
Use the ICON field to specify the icon used in File Manager. If you do not specify an icon image, File Manager displays only a label.
- The File Manager icon (ICON field)
- The double-click behavior and contents of the Selected menu (ACTIONS field)
- The data type's on-item help (DESCRIPTION field)
The value of the ICON field can be:
Table 11-1 lists icon sizes you should create and the corresponding file names.
- A base file name.
The base file name is the name of the file containing the icon image, minus the file-name suffixes for size (m and t) and image type (bm and pm). For example, if files are named GameIcon.m.pm and GameIcon.t.pm, use GameIcon.
If you use the base file name, the icon files must be placed in a directory on the icon search path:
- Personal icons: HomeDirectory/.dt/icons
- System-wide icons: /etc/dt/appconfig/icons/language
- An absolute path to the icon file, including the full file name.
You should use the absolute path only if the icon file is not located on the icon search path. For example, if icon file GameIcon.m.pm is placed in the directory /doc/projects, which is not on the icon search path, the value of the ICON field would be /doc/projects/GameIcon.m.pm.
There are two ways that data types are associated with actions:
For example, the following data type definition creates a data type for special "readme" files created by your system administrator that use the naming convention *.rm.
- The ACTIONS field in the DATA_ATTRIBUTES definition lists the actions that will appear in File Manager's Selected menu. The first action in the list is the default (double-click) action.
- Actions can be restricted to specified data types using the action definition's ARG_TYPE field.
A special Respond action is defined below for the file. It opens a writable copy of the file in Text Editor. When the file is saved and Text Editor is exited, the file is mailed to the system administrator (mail address sysadmin@utd).
EXEC_STRING /bin/sh -c 'cp %Arg_1% $HOME/readme.temp;\
chmod +w $HOME/readme.temp; \
dtpad $HOME/readme.temp; \
cat $HOME/readme.temp | \
/usr/bin/mailx sysadmin@utd; \
Hiding Files Based on Data Type
If a file is an invisible data type, it never appears in File Manager.
Use the PROPERTIES field in the DATA_ATTRIBUTES definition to specify that objects of this type be hidden:
Specifying Behaviors When the File Is Manipulated
The following DATA_ATTRIBUTES fields are used primarily by application programmers. They specify how files behave when the user performs various desktop activities.
For more information, see the Common Desktop Environment Programmer's Guide, which is part of the developer environment documentation.
- For containers such as directories. Specifies an action to be run when a file is moved to a container of this data type.
- For containers such as directories. Specifies an action to be run when a file is copied to a container of this data type.
- Specifies an action to be run when a file is linked to a file of this data type.
- Specifies that files of this data type contain text that can be displayed in a text box.
- Specifies the corresponding ToolTalk media type.
- MIME_TYPESpecifies the corresponding MIME type.
- Specifies the corresponding X400 type.
The DATA_CRITERIA definition defines the criteria used to assign an object type to a file or directory.
You can use the following criteria for object typing:
You can use more than one criteria for a data type. However, you should not use the NAME_PATTERN and PATH_PATTERN criteria in the same data type.
- File name
- The file name must match a specified pattern. Use the NAME_PATTERN field.
- File location
- The path must match a specified pattern. Use the PATH_PATTERN field.
- File contents
- A specified portion of the file's contents must match specified data. Use the CONTENT field.
- File mode
- The file must possess the specified permissions (read, write, execute, directory). Use the MODE field.
- Symbolic links
- The typing is based on the file to which the object is linked.
Name-Based Data Types
Use the NAME_PATTERN field to specify the naming requirement. The field value can include the following wildcards:
- ?Matches any single character
- *Matches any sequence of characters (including a null string)
- [cc...]Matches any of the characters (c) enclosed in brackets
- [c-c]Matches any of the characters in the range c through c
- The following data type definition creates a data type based on the file name. The file name must begin with QS and end with .doc.
DESCRIPTION This file contains a document for the QS project.
- The following definition creates a data type for directories named Demo_n where n is 0 through 9.
DESCRIPTION This is a directory. Double-click to open it.
Location-Based Data Types
Use the PATH_PATTERN field to specify the path. You can use the same wildcard characters as with NAME_PATTERN.
For example, the following data type uses a criteria based on path.
DESCRIPTION Graphics file for the QS project. Double-click the \
icon to see the graphic.
Data Types Based on Name and Location
To create a data type based on both file name and location, include the name in the PATH_PATTERN value. You cannot use both NAME_PATTERN and PATH_PATTERN in the same criteria definition.
- The QS_Source_Files data type defined below applies to all files named appn.c, where n= 1 through 9, located in subdirectories of */projects/QS.
- The following data type applies to all files in the directory /doc/project1 named chnn.xxx where n is 0 through 9, and xxx is any three-character file- name suffix.
DESCRIPTION Chapter file for the project document.
Using File Modes as a Typing Criteria
Use the MODE field to specify the required permissions.
Mode criteria are usually used in combination with name-based, location-based, or content-based data typing. They allow you to limit a data type to a file or directory, or to specify the required read, write, and execute permissions.
The MODE field can include the following logical operators and characters:
The default fora particular mode is that the mode does not matter.
- !Logical operator NOT
- &Logical operator AND
- Logical OR
- fThe data type applies only to files
- dThe data type applies only to directories
- rThe file is readable by any user
- wThe file is writable by any user
- xThe file is executable by any user
- The file is a link
Content-Based Data Typing
Use the CONTENT field to specify data typing based on the content of the file. Content-based data typing can be used in combination with name- or location-based data typing.
The typing can be based on either string or numeric content for files. The first byte in the file is numbered 0.
- For string content of a file, use the syntax:
CONTENT starting_byte string string
- For number content of a file, use the syntax:
CONTENT starting_byte byte number
CONTENT starting_byte short number
CONTENT starting_byte long number
- For the contents of a directory, use the syntax:
Use standard C notation for octal (leading o) and hexidecimal (leading oX) numbers.
CONTENT 0 filename "file_name"
Note: Use of content-based data typing will result in slower system performance. Wherever possible, use name- and location-based typing instead.
For example, the following data type, Writable_Wingz, applies to all files with write permission containing the string WNGZ at the beginning of the file.
CONTENT 0 string WNGZ
To Create a Data Type with Several Independent Criteria
You can create a data type with several independent criteria--that is, the file is assigned to the data type if it meets either (or both) of the criteria.
For example, the following definitions create the Mif data type. Typing is based on name or content.
- Create the DATA_ATTRIBUTES definition for the data type.
- Create a DATA_CRITERIA definition for each criteria.
Use the DATA_ATTRIBUTES_NAME field to connect each criteria to the same DATA_ATTRIBUTES definition.
CONTENT 1 string MIFFile
Creating Localized Data Types
The search path for data types includes language-dependent locations. The desktop uses the value of LANG to determine the locations searched for data type definitions.
Locations for Localized Data Types
Localized data type definitions must be placed in the proper language-dependent directories along the actions search path.
The default search path is:
- Personal actions: HomeDirectory/.dt/types
- System-wide actions: /etc/dt/appconfig/types/language
- Built-in actions: /usr/dt/appconfig/types/language
To Localize a Data Type
- Create a file in the appropriate language-dependent directory (for example, in /etc/dt/appconfig/types/japanese) .
- Copy the data type definition to the language-dependent configuration file.
- Localize one or more fields in the data type definition.