;;;; ;;;; F i l e b o x . s t k -- File Box composite widget ;;;; ;;;; Copyright © 1993-1998 Erick Gallesio - I3S-CNRS/ESSI ;;;; ;;;; Permission to use, copy, and/or distribute this software and its ;;;; documentation for any purpose and without fee is hereby granted, provided ;;;; that both the above copyright notice and this permission notice appear in ;;;; all copies and derived works. Fees for distribution or use of this ;;;; software or derived works may only be charged with express written ;;;; permission of the copyright holder. ;;;; This software is provided ``as is'' without express or implied warranty. ;;;; ;;;; $Id: Filebox.stklos 1.6 Tue, 03 Mar 1998 23:48:24 +0100 eg $ ;;;; ;;;; Author: Erick Gallesio [eg@kaolin.unice.fr] ;;;; Creation date: 22-Mar-1994 13:05 ;;;; Last file update: 3-Mar-1998 22:54 (require "unix") (require "Basics") (select-module STklos+Tk) (export make-file-box file-chooser) ;============================================================================= ; ; < F i l e - b o x > ; ;============================================================================= ;;;; ;;;; Resources ;;;; (option 'add "*FileBox.FileName.Entry.Background" "white" "widgetDefault") (option 'add "*FileBox.FileName.Entry.Relief" "sunken" "widgetDefault") (option 'add "*FileBox*VPaned.Width" 450 "widgetDefault") (option 'add "*FileBox*VPaned.Height" 200 "widgetDefault") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; Utilities ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define filebox-lock #F) ;; lock variable ;; ;; Filebox-associate-bindings ;; (define (filebox-associate-bindings fb) (define & string-append) (define (toggle-all-files) (let ((val (slot-ref fb 'value))) (unless (file-is-directory? val) (set! val (dirname val))) (slot-set! fb 'value val) (filebox-scan-directory fb val))) (define (choose-parent) (let* ((lb (left-frame-of fb)) (sel (current-selection lb))) (when sel ;; Read all component from 0 to sel and append them in a string (let ((dir "") (sel (car sel))) (do ((i 1 (+ i 1))) ((> i sel)) (set! dir (& dir "/" (get lb i)))) (let ((new-dir (if (string=? dir "") "/" dir))) (slot-set! fb 'value new-dir) (filebox-scan-directory fb new-dir)))))) (define (choose-file) (letrec ((box1 (left-frame-of fb)) (box2 (right-frame-of fb)) (sel (current-selection box2)) (res #t) (make-dir (lambda (l res) (if (null? l) res (make-dir (cdr l) (string-append res (car l) "/"))))) (val (& (make-dir (cdr (value box1)) "/") (get box2 (car sel))))) (set! (value fb) val) (if (file-is-directory? val) (filebox-scan-directory fb val) (filebox-validate fb)))) (define (complete-file) (catch (let ((val (sort (glob (& (value fb) "*")) string" (lambda () (set! filebox-lock 'destroy))) (set! (command (cancel-button-of fb))(lambda () (set! filebox-lock 'cancel))) (set! (command (ok-button-of fb)) (lambda () (filebox-validate fb))) (set! (command (all-button-of fb)) toggle-all-files) (set! (command (help-button-of fb)) (lambda () (STk:show-help-file "fbox-hlp.html"))) ;; Button release in paned (bind (listbox-of (left-frame-of fb)) "" choose-parent) (bind (listbox-of (right-frame-of fb)) "" choose-file) ;; Character bindings in the entry (let ((ent (lentry-of fb))) (bind ent "" complete-file) (bind ent "" complete-file) (bind ent "" invoke)) ) ;; ;; Filebox-scan-directory ;; (define (filebox-scan-directory fb directory) (let ((& string-append)) (when (file-is-directory? directory) (let ((files (if (value (all-button-of fb)) (glob (& directory "/*") (& directory "/.*")) (glob (& directory "/*"))))) ;; Display the right part (delete (right-frame-of fb) 0 'end) (apply insert (right-frame-of fb) 0 (map (lambda (x) (basename x)) (sort files string () ((class :init-keyword :class :init-form "FileBox") (title :initform "File Selection" :accessor title :init-keyword :title :allocation :propagated :propagate-to (frame)) (validate :accessor validate :init-form (lambda (fb path) #t) :init-keyword :validate) (paned) ;; paned and buttons are not intended to the user (buttons) (left-frame :accessor left-frame-of) (right-frame :accessor right-frame-of) (left-title :accessor left-title-of) (right-title :accessor right-title-of) (lentry :accessor lentry-of) (ok-button :accessor ok-button-of) (canc-button :accessor cancel-button-of) (help-button :accessor help-button-of) (all-button :accessor all-button-of) ;; Fictives slots (value :accessor value :init-keyword :value :init-form (getcwd) :allocation :virtual :slot-ref (lambda (o) (expand-file-name (value (lentry-of o)))) :slot-set! filebox-set-value! :propagate-to (lentry)) (background :accessor background :allocation :propagated :propagate-to (frame buttons left-frame right-frame left-title right-title lentry ok-button canc-button help-button all-button)) (width :accessor width :init-keyword :width :allocation :propagated :propagate-to (frame)) (height :accessor height :init-keyword :height :allocation :propagated :propagate-to (frame)))) ;================================================== (define-method initialize-composite-widget ((self ) initargs frame) (let* ((paned (make :parent frame :fraction 0.3)) (f (make :parent frame)) (lf (left-frame-of paned)) (rf (right-frame-of paned))) (next-method) (slot-set! self 'Id (Id frame)) (slot-set! self 'paned paned) (slot-set! self 'buttons f) (slot-set! self 'left-frame (make :parent lf)) (slot-set! self 'right-frame (make :parent rf)) (slot-set! self 'left-title (make