commander-s/scheme/cd.scm

85 lines
2.9 KiB
Scheme
Raw Normal View History

2004-10-10 09:22:25 -04:00
;;cd
;;This command can be used on all platforms because it uses the
;;scsh-Function "chdir"
2004-10-14 07:58:20 -04:00
;;cd-res-objects are only warppers around browse-directoty-list-res-objects.
;;They only differ in the restore-procedure:
;;Other "directory-browsing-commands" like find or ls restore the old working-directory,
;;the directory that was valid, when they were initially called. cd changes the
;;current-working-directory permanently.
2004-10-10 09:22:25 -04:00
2004-10-14 07:58:20 -04:00
(define-record-type cd-res-obj cd-res-obj
(make-cd-res-obj browse-obj)
cd-res-obj?
(browse-obj cd-res-obj-browse-obj))
2004-10-10 09:22:25 -04:00
(define cd-receiver
2004-10-14 07:58:20 -04:00
(lambda (message)
2004-10-10 09:22:25 -04:00
(cond
((next-command-message? message)
2004-10-14 07:58:20 -04:00
(let* ((width (next-command-message-width message))
(parameters (next-command-message-parameters message)))
(if (null? parameters)
(let* ((result (list "Forgot path!"))
(text
(layout-result-standard "Forgot Path!"
result width))
(browse-obj
(make-browse-dir-list-res-obj 1 1 result text (cwd)
width (cwd) '() '() #f)))
(make-cd-res-obj browse-obj))
(let ((path (car parameters)))
(if (not (file-exists? path))
(let* ((result (list "Path doesn't exist"))
(text
(layout-result-standard "Path doesn't exist!"
result width))
(browse-obj
(make-browse-dir-list-res-obj 1 1 result text (cwd)
width (cwd) '() '() #f)))
(make-cd-res-obj browse-obj))
(begin
(chdir path)
(let* ((browse-next-command-message
(make-next-command-message "browse-dir-list"
'("(directory-files)" "(cwd)")
width)))
(make-cd-res-obj (browse-dir-list-receiver
browse-next-command-message)))))))))
2004-10-10 09:22:25 -04:00
((print-message? message)
(let* ((model (message-result-object message))
2004-10-14 07:58:20 -04:00
(width (print-message-width message))
(browser (cd-res-obj-browse-obj model))
(browse-print-message
(make-print-message "browse-dir-list"
browser
width)))
(browse-dir-list-receiver browse-print-message)))
2004-10-10 09:22:25 -04:00
((key-pressed-message? message)
(let* ((model (message-result-object message))
2004-10-14 07:58:20 -04:00
(key (key-pressed-message-key message))
(browser (cd-res-obj-browse-obj model))
(browse-key-message
(make-key-pressed-message "browse-dir-list"
browser
key)))
(make-cd-res-obj (browse-dir-list-receiver
browse-key-message))))
2004-10-10 09:22:25 -04:00
((restore-message? message)
(let* ((model (message-result-object message))
2004-10-14 07:58:20 -04:00
(browser (cd-res-obj-browse-obj model))
(wd (browse-dir-list-res-obj-working-directory browser)))
(chdir wd)))
2004-10-10 09:22:25 -04:00
((selection-message? message)
(let* ((model (message-result-object message))
2004-10-14 07:58:20 -04:00
(browser (cd-res-obj-browse-obj model))
(browse-sel-message
(make-selection-message "browse-dir-list"
browser)))
(browse-dir-list-receiver browse-sel-message)))
)))
2004-10-10 09:22:25 -04:00
(define cd-rec (make-receiver "cd" cd-receiver))
(set! receivers (cons cd-rec receivers))