![]() |
Interactive dialogues | ![]() |
The routines on this page allow Scheme programs to ask simple questions to the user and to display messages. They are defined in
kernel/texmacs/tm-dialogue.scm
and
kernel/gui/menu-widget.scm
. Since the graphical user interface is event driven, the answers are passed to continuations rather than returned. More complex dialogues can be built using widgets, as explained in dialogs and composite widgets.
Prompt the user with the string prompt (in the footer or in a dialogue window, depending on the preferences) and call cont with the answer (a string). Instead of a string, prompt may also be a list (prompt type proposal …), where type is as in the :argument option of tm-define (see function definitions) and the proposals are the suggested answers.
Ask a yes/no question and call cont with a boolean. The boolean default determines whether "yes" or "no" is proposed first. For instance:
(user-confirm "Really close the document?" #f
(lambda (answ) (when answ (buffer-close (current-buffer))))) |
Open a file chooser with title prompt and call cont with the chosen URL. The type can for instance be "texmacs", "image" or "directory"; see choose-file in
kernel/boot/abbrevs.scm
.
(interactive fun)
Prompt the user for the arguments of the function fun and then call it. In the first form, the prompts, types and default values of the arguments are taken from the :argument, :default and :proposals options of the definition of fun. In the second form, each arg-i is a prompt string or a list (prompt type proposal …). Answers are learned, so that they can be proposed again next time (see also learn-interactive and forget-interactive). This is the usual way to bind commands which require arguments in menus, as in (interactive load-buffer).
(set-message left right)
Display the message left in the footer, together with the information right (which usually describes the action that caused the message). The temporary variant restores the previous message after ms milliseconds of inactivity. The messages may be strings or TeXmacs content.
(show-message msg title)
Show the message msg in a small window with an Ok button. The routine notify-now uses the title Notification and opens the window after the current event has been processed.
Open a new window with the widget widget (defined using tm-widget) and the given title. When the widget calls its continuation with some arguments, then cmd is applied to these arguments and the window is closed. See dialogs and composite widgets for details and examples.
Many dialogues need to be executed after the current event has been processed or after some delay. This can be done using the following macro.
Schedule the evaluation of body after the current event has been processed. The following options modify when and how often body is evaluated:
Wait until the user has been inactive during ms milliseconds.
Wait ms milliseconds.
Evaluate body every ms milliseconds (usually combined with :while or :permanent).
Wait at least ms milliseconds, and then until the computer has been idle during 30 seconds; with :permanent, this is used for periodic maintenance, such as the backups of the server.
Evaluate body once the user has been inactive during ms milliseconds. With :permanent after it, body is evaluated again after each later change of the document, once the user has been inactive again during ms milliseconds; without a change, nothing happens.
Postpone the evaluation until cond holds.
Repeat the evaluation as long as cond holds.
Reschedule the evaluation after each execution as long as cond evaluates to #t.
Evaluate expr once the task has finished.
Evaluate expr each time the task is checked.
For instance, (delayed (:idle 1000) (set-message "Hi" "")) displays a message after one second of inactivity. The macro is defined in
kernel/texmacs/tm-dialogue.scm
. Notice that :idle does not work in headless mode.