;;; SHOWFILE.LSP
;;; Sample how to use the action callbacks in STD-SHOWFILE-DIALOG
(defun C:SWITCH (/ fn1 fn2 *current* *other*) (std-var-init nil)
;;; This shows the next file in the dialog
(defun switch () (if (/= *current* fn1) (setq *current* fn1 *other* fn2) (setq *current* fn2 *other* fn1))
;; cascade the next
(if (std-number-list-p *dlg-pt*) (setq *dlg-pt* (mapcar '+ *dlg-pt* '(60 0)))) (std-showfile-dialog *current* (strcat *current* " (click to see the same line of the other file)") 'show-action-cb)) (princ "\ncreating two random files...") (setq fn1 (std-filename-mktemp "1") fn2 (std-filename-mktemp "2")) (random-file fn1) (random-file fn2) (princ "\ndisplaying both...") (princ "\nsingle click to see the corresponding line of the other file...") (princ "\ndouble click to switch to the other file...") (switch) (std-var-restore) ) (defun rand-char () (chr (+ (ascii "a") (std-random 26))))
;; A word has about 3 to 15 chars
(defun rand-word () (std-make-string (+ 3 (std-random 12)) 'rand-char))
;; A line has about 3 to 6 words
(defun rand-line () (std-strlist->string (std-make-list (+ 3 (std-random 3)) 'rand-word)" "))
;; At all 80 random lines
(defun random-file (fn / f) (setq f (std-fopen fn "w")) (repeat 80 (write-line (rand-line) f)) (std-fclose f))
;;; On any click it shows the corresponding line in the status line.
;;; on double click it opens the other file in a new dialog.
;;; 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" "")))