Saturday, September 18, 2021

Popup menus: a misconception

In almost every Windows program (or form), right clicking will lead to displaying a context menu that provides more, but less frequently used, options for whatever is displayed. In programming terms, this context menu is called a popup menu because it pops up, as opposed to the standard menu that appears at all times. In Delphi programs, it's very easy to add a popup menu to a form: one defines the popup menu, adds options to it, then connects this menu to the form by means of the form's popup property.

In the 'ERP' program that I wrote (and continually develop) for the occupational psychologist, one of the forms that is used the most is effectively divided into two: in the top half are displayed dockets (i.e. customer files) and in the lower half can be displayed eight or nine different sorts of data, each connected to the current docket in the upper half. For example, one option is to display the people (examinees) connected to the docket, another is to show the meetings for that docket, a third shows invoices for that docket, etc. As a result of this rich amount of possible data, the popup menu for this form contained maybe twenty different possibilities, when only some of those possibilities are available at any given time (it doesn't make any sense to allow the 'delete examinee from docket' option when invoices are being shown). This requires continual updating of this menu, marking which options are available at any given time; this is confusing for the user and also is quite a headache for me to maintain.

It occurred to me yesterday that I could simplify matters by defining several popup menus for the form. As the form has a single popup property, it is easy to be under the misconception that only one popup menu can be defined for a form. In fact, most controls within a form, including a data grid, have a popup property of their own; defining a popup menu for a control will cause that menu to appear when right clicking on that control. I defined one popup menu for the upper data grid that contains four or five options that are always valid for a docket. For the lower data grid, I defined eight different popup menus: one for examinees, one for meetings, one for invoices, etc. When the user chooses which kind of data to display in the lower data grid, the grid's popup property is set to the appropriate popup menu, thus each menu contains three or four options that are always available. 

Actually, that statement '[all] the options are always available' is not true; first there is a check to see whether there is any data to be displayed (e.g. does the current docket have any invoices?) and then the options' availability is set depending on this check. After all, it makes no sense to offer the option to delete the current invoice if the docket has no invoices. 

No comments: