Associating an Object with a Program

There are three ways to set up a data file object so that a program is started when the user double clicks on the data file icon. These are:

  • Create a Filename association in the program settings
  • Create a Type association in the data file settings
  • Make the program name the default setting in the "Open" cascade menu for the data file.

    An association is a special link which can be assigned to a program object. This link allows the user to specify which program will be invoked when the user double clicks on specified types of files, individual files, or files described by a global file name.

    Filename Association in a Program

    The major disadvantages of this approach are that it provides little flexibility to the user and it is not very robust. Any association is easily destroyed by changing the file extension and it is therefore only recommended for programs which do not support associations by "Type".

    The inflexibility of this method can be seen when a user subsequently wants to use a different program with his data file. To do this, he will have to either change the filename or add a new program to the "Open" menu and make it the default. Neither approach is suitable for the inexperienced user.

    A text editor may, for example, have associations for plain text files (that is, a type of file), the individual file CONFIG.SYS, and all files described with the global name READ*.*. Whenever a file object that meets these criteria is selected with a double click, OS/2 will start the appropriate program object. The workings of the association mechanism are described in Workplace Shell Implementation.

    There are some editing strings for filenames and extensions that can be used with associations to allow parameters to be passed without having to fully specify the qualified filename (or parts of it):

  • Fully qualified path

  • P %%*D %%*N %%*F %%*E

    Type Association in a Data File

    This is the preferred approach. It is described in more detail in Presentation Manager and Workplace Shell Application Development and Workplace Shell Implementation. The advantage of this approach is that it is easy for a user to use a different program with his object, simply by choosing a new "Type" in the Settings view. The process is simple:

  • Open the Settings view for the object

  • Select the "Type" page of the notebook

  • Select from the list of "Available types"

  • Press the "Add" button

  • Close the Settings window.

    Each program can be associated with a "Type" but, in practice, not all are. DOS programs are very unlikely to support the concept of file type associations. It will, therefore, probably be necessary to use the filename association technique for such files.

    If a program does not set a file type, the user can create a new one. This is described in Adding New File Types.

    Add a Default Program to the File Menu

    The process to do this is described in Modifying the Context Menu of an Object and Changing the Default View on "Open". This approach is limited to users who understand the workings of the Workplace Shell in some detail. Its main disadvantage is found when many existing files must be set up to use a particular program; each one must be modified separately. Under these circumstances the filename association would be preferred.

    If you are setting up a system for a new user, however, you can create one data file with the program set as the default on "Open" in the context menu, then make that file into a template so all new files subsequently created from it will inherit this attribute.


    [Back: Changing the Icon for an Object]
    [Next: Giving OS/2 V2.0 the Look and Feel of OS/2 Version 1.3]