Guides/Window Driver/MessageBox

From J Wiki
Jump to navigation Jump to search

wd commands to create common dialog boxes begin with wd 'mb ...'.

mb iconspec button-list title message ; General-purpose dialog box for giving the user information and waiting for a response

iconspec is info, warn, critical, or query. It signifies the importance of the message. It also controls the result: the result will be empty for all iconspecs except query; for query the result will be the selected button-spec, in lowercase, without the leading mb_.

button-list is a list of button-specs. Each button-spec creates one button in the dialog box. The button-specs must be chosen from: mb_ok mb_open mb_save mb_cancel mb_close mb_discard mb_apply mb_reset mb_restoredefaults mb_help mb_saveall mb_yes mb_yestoall mb_no mb_notoall mb_abort mb_retry mb_ignore. Put = before the default button (the first will be the default if you omit =)

title is the title of the dialog box

message is the message text.

Example: wd 'mb query mb_yes =mb_no mb_cancel "Model Run" "OK to continue?"'

The utility wdinfo, with arguments of title;text, executes wd 'mb info mb_ok title text. For example:

 wdinfo 'my title';'some text'

mb about title text ; about common dialog (added in J802).

mb color [colors] ; choose color common dialog box. Result is chosen color. Colors are 3 integers giving RGB values. Optional argument sets initial chosen color.

mb dir title directory ; open file common dialog returns fully qualified directory name selected by user.

mb font [title] [fontspec] ; choose font common dialog. Result is a fontspec.

mb info title text ; information common dialog, see above.

mb input ; input common dialog (added in J802).
In the following, italicized names are to be replaced by user values. title is the title of the message box; label is the text shown above the input field; defaultvalue is the character value initially displayed in the input field.

  • mb input double title label defaultvalue min max decimals - input floating-point value
    • Negative numbers show as dash (-), not underbar (_).
  • mb input int title label defaultvalue min max step - input Integer
  • mb input item title label index ifeditable items - input Item from list
    • The item list must be enclosed in double quotes (").
    • Items are separated by either spaces or LF.
    • If LF is used then spaces are allowed in items.
    • Null (zero length) items are ignored.
    • The result is the value of the selected item (not its index)
  • mb input text title label defaultvalue - input Text

mb open title filename [filters] ; open file common dialog returns fully qualified file names selected by user. Filters are delimited by |. Allows selection of multiple files, with an LF delimited list returned. When a single file name is returned, it is terminated by LF.

wd 'mb open  mytitle  ""  "Write (*.wri)|Word (*.doc)"'

mb open1 title filename [filters] ; open file common dialog returns fully qualified file name selected by user. Filters are delimited by |. Only a single file may be selected and the fully qualified file name is returned without an added termination character.

mb print ; opens the printer dialog. The result is '' if the user pressed CANCEL. If the user pressed OK, the result is the name of the selected printer. Note that the print dialog does not operate correctly on OSX prior to version 10.7.

mb print filename ; The parameter selects the file to be printed to the printer chosen in the dialog. If the parameter starts with * the parameter itself will be printed as text.

mb printx filename ; same as mb print except it prints to the default session printer.

mb save title filename [filters] ; save file common dialog returns fully qualified file name (see mb open).