std-showfile shows the content of the textfile fname either in a dialogbox using std-showfile-dialog or prints it to the console. Similar to the AutoCAD command ABOUT.
It is used to present to the user some short text.
std-showfile-dialog is the GUI version using dynamically created DCL. It takes two aditional arguments to provide some more bells and whistles:
The dcl file is created and deleted dynamically (on the next std-var-restore).
It uses ok_cancel_err;
as lower botton row.
The size is calculated dynamically, dependent on the length and number of lines in the textfile:
Height: between 10 and 33 lines (to stay below 600 pixel on the most common font sizes)
Width: between 35 and 85 chars.
The action-callback argument is a function which requires exactly four arguments:
$key $value $data $reason.
With the $data argument you have access to the whole file, but you can also use global variables, as in the example below. If the action-callback is nil, nothing happens, if you click or double-click onto the list.
For example you may define scrollers or lists when clicked onto one entry jumping to another lists.
An useful action template:
(lambda (key val data how) (cond ((= how 4) (double-click-action key val data)) (T (single-click-action key val data))))
;;; see also samples/SHOWFILE.LSP
(defun C:SWITCH (/ fn1 fn2 *current* *other*
switch show-action-cb show-status-cb)
;; these textfiles must exist!
(setq fn1 "file1.txt" fn2 "file2.txt")
;;; This shows the first file in the dialog and on any click
;;; it shows the corresponding line in the status line.
;;; on double click it opens the other file in a new dialog.
(defun switch () (if (/= *current* fn1) (setq *current* fn1 *other* fn2) (setq *current* fn2 *other* fn1)) (std-showfile-dialog *current* (strcat *current* " (click to see the same line of the other file)")
'show-action-cb))
;;; double-click: other file in new dialog
;;; single-click: show matching line at status line
;;; val is the line number, zero-based
(defun show-action-cb (key val data reason)
(cond ((= reason 4) (switch))
(T (show-status-cb (read val)))))
;;; show the corresponding line at the status line
;;; uses the global *other*
(defun show-status-cb (pos / s)
(if (and (stringp *other*) (setq s (std-ft-nth-line *other* (1+ pos)))) (set_tile "error" (substr s 1 80)) (set_tile "error" ""))) (switch))
fname: The fully qualified filename of a textfile. (findfile) is not used.
title: a string being displaying as window title
action-callback: the symbol of a function or quoted lambda list taking 4 arguments.
Not defined.
Interrupts the program flow. It may raise a dialog box. It waits for the user to press the "OK" or "Cancel" button or the <Enter> or <Escape> key.
std-showfile-dialog creates temporary files, so it should be surrounded in any calling function above by the stdlib error handler pair std-var-init and std-var-restore.
(std-require 'STDFILE)
Defined in STDFILE