2004-10-14 07:58:20 -04:00
|
|
|
;;This addition provides a directory-tree-browsing-functionality.
|
|
|
|
;;This means:
|
|
|
|
;;When using it you hand over a list of strings, that shall be
|
|
|
|
;;interpreted as paths and a string that represents the path, relative to
|
|
|
|
;;which the path-list is given.
|
|
|
|
;;In the result-window of the NUIT a file-browsing screen is shown
|
|
|
|
;;which you can browse in using arrow-keys and enter. You can also
|
|
|
|
;;select some items and paste them into the upper window.
|
|
|
|
|
|
|
|
;;If there are paths to files handed over that do not exist, they will not be
|
|
|
|
;;displayed in the browser!
|
|
|
|
|
|
|
|
;;If the given path does not exist you will not be able to navigate!
|
|
|
|
|
2005-05-17 05:56:11 -04:00
|
|
|
(define key-m 109)
|
|
|
|
(define key-u 117)
|
2004-10-14 07:58:20 -04:00
|
|
|
|
|
|
|
(define-record-type browse-dir-list-res-obj browse-dir-list-res-obj
|
|
|
|
(make-browse-dir-list-res-obj pos-y
|
|
|
|
pos-x
|
|
|
|
file-list
|
|
|
|
result-text
|
|
|
|
working-directory
|
|
|
|
width
|
|
|
|
initial-wd
|
|
|
|
marked-items
|
|
|
|
res-marked-items
|
|
|
|
c-x-pressed)
|
|
|
|
browse-dir-list-res-obj?
|
|
|
|
(pos-y browse-dir-list-res-obj-pos-y)
|
|
|
|
(pos-x browse-dir-list-res-obj-pos-x)
|
|
|
|
(file-list browse-dir-list-res-obj-file-list)
|
|
|
|
(result-text browse-dir-list-res-obj-result-text)
|
|
|
|
(working-directory browse-dir-list-res-obj-working-directory)
|
|
|
|
(width browse-dir-list-res-obj-width)
|
|
|
|
(initial-wd browse-dir-list-res-obj-initial-wd)
|
|
|
|
(marked-items browse-dir-list-res-obj-marked-items)
|
|
|
|
(res-marked-items browse-dir-list-res-obj-res-marked-items)
|
|
|
|
(c-x-pressed browse-dir-list-res-obj-c-x-pressed))
|
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(define (layout-dir-list files wdir width)
|
|
|
|
(let ((marked-files (mark-special-files wdir files)))
|
|
|
|
(append
|
|
|
|
(list
|
|
|
|
(if (<= (string-length wdir) (- width 25))
|
|
|
|
(string-append "Paths relative to " wdir " :")
|
|
|
|
(let ((dir-string (substring wdir
|
|
|
|
(- (string-length wdir)
|
2005-05-17 16:08:39 -04:00
|
|
|
(- width 25))
|
2005-05-22 11:05:25 -04:00
|
|
|
(string-length wdir))))
|
|
|
|
(string-append "Paths relative to ..."
|
|
|
|
dir-string))))
|
|
|
|
marked-files)))
|
2004-10-14 07:58:20 -04:00
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(define (mark-special-files dir files)
|
|
|
|
(map (lambda (file)
|
|
|
|
(let ((complete-name (string-append dir "/" file)))
|
|
|
|
(cond
|
|
|
|
((file-directory? complete-name)
|
|
|
|
(string-append " " file "/"))
|
|
|
|
((file-executable? complete-name)
|
|
|
|
(string-append "*" file))
|
|
|
|
((file-symlink? complete-name)
|
|
|
|
(string-append "@" file))
|
|
|
|
(else
|
|
|
|
(string-append " " file)))))
|
|
|
|
files))
|
|
|
|
|
2004-10-14 07:58:20 -04:00
|
|
|
;;selection->descend
|
|
|
|
(define selected-browse-dir-list
|
|
|
|
(lambda (model)
|
|
|
|
(let ((ln (browse-dir-list-res-obj-pos-y model))
|
|
|
|
(wd (browse-dir-list-res-obj-working-directory model)))
|
|
|
|
(if (not (file-exists? wd))
|
|
|
|
model
|
|
|
|
(begin (chdir wd)
|
|
|
|
(if (or (>= ln (+ (length
|
|
|
|
(browse-dir-list-res-obj-result-text model)) 1))
|
|
|
|
(<= ln 1))
|
|
|
|
model
|
|
|
|
(if (= ln 2)
|
|
|
|
(if (not (equal? "/" (cwd)))
|
|
|
|
(begin
|
|
|
|
(chdir "..")
|
2005-05-22 11:05:25 -04:00
|
|
|
(let* ((new-result (directory-files))
|
2004-10-14 07:58:20 -04:00
|
|
|
(width (browse-dir-list-res-obj-width model))
|
2005-05-22 11:05:25 -04:00
|
|
|
(new-text (layout-dir-list
|
|
|
|
new-result (cwd) width))
|
2004-10-14 07:58:20 -04:00
|
|
|
(new-model (make-browse-dir-list-res-obj
|
|
|
|
2
|
|
|
|
1
|
|
|
|
new-result
|
|
|
|
new-text
|
|
|
|
(cwd)
|
|
|
|
width
|
|
|
|
(browse-dir-list-res-obj-initial-wd
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-marked-items
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-res-marked-items
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-c-x-pressed
|
|
|
|
model))))
|
|
|
|
new-model))
|
|
|
|
model)
|
|
|
|
(let* ((text (browse-dir-list-res-obj-result-text model))
|
|
|
|
(ent (list-ref text (- ln 1)))
|
|
|
|
(len (string-length ent))
|
|
|
|
(last-char (substring ent (- len 1) len))
|
|
|
|
(rest (substring ent 1 (- len 1))))
|
|
|
|
(if (equal? last-char "/")
|
|
|
|
(begin
|
|
|
|
(chdir wd)
|
|
|
|
(chdir rest)
|
2005-05-22 11:05:25 -04:00
|
|
|
(let* ((new-result (directory-files))
|
2004-10-14 07:58:20 -04:00
|
|
|
(width (browse-dir-list-res-obj-width model))
|
2005-05-22 11:05:25 -04:00
|
|
|
(new-text (layout-dir-list
|
|
|
|
new-result (cwd) width))
|
2004-10-14 07:58:20 -04:00
|
|
|
(new-model (make-browse-dir-list-res-obj
|
|
|
|
2
|
|
|
|
1
|
|
|
|
new-result
|
|
|
|
new-text
|
|
|
|
(cwd)
|
|
|
|
width
|
|
|
|
(browse-dir-list-res-obj-initial-wd
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-marked-items
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-res-marked-items
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-c-x-pressed model))))
|
|
|
|
new-model))
|
|
|
|
model)))))))))
|
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(define (init-with-list-of-files files dir width)
|
|
|
|
(make-browse-dir-list-res-obj
|
|
|
|
2 1
|
|
|
|
files (layout-dir-list files dir width) dir
|
|
|
|
width (cwd) '() '() #f))
|
|
|
|
|
2004-10-14 07:58:20 -04:00
|
|
|
(define browse-dir-list-receiver
|
|
|
|
(lambda (message)
|
2005-05-22 11:05:25 -04:00
|
|
|
(debug-message "browse-dir-list-receiver " message)
|
2004-10-14 07:58:20 -04:00
|
|
|
(cond
|
2005-05-22 11:05:25 -04:00
|
|
|
|
|
|
|
((init-with-result-message? message)
|
|
|
|
(let ((fs-objects (init-with-result-message-result message)))
|
|
|
|
(init-with-list-of-files
|
|
|
|
(map fs-object-name fs-objects) (cwd)
|
|
|
|
(init-with-result-message-width message))))
|
|
|
|
|
2004-10-14 07:58:20 -04:00
|
|
|
((next-command-message? message)
|
2005-05-22 11:05:25 -04:00
|
|
|
(init-with-list-of-files (directory-files) (cwd)))
|
2004-10-14 07:58:20 -04:00
|
|
|
|
|
|
|
((print-message? message)
|
2005-05-20 11:20:34 -04:00
|
|
|
(let* ((model (message-result-object message))
|
2004-10-14 07:58:20 -04:00
|
|
|
(pos-y (browse-dir-list-res-obj-pos-y model))
|
|
|
|
(pos-x (browse-dir-list-res-obj-pos-x model))
|
|
|
|
(text (browse-dir-list-res-obj-result-text model))
|
|
|
|
(marked-pos (get-marked-positions-3
|
|
|
|
(browse-dir-list-res-obj-file-list model)
|
|
|
|
(browse-dir-list-res-obj-marked-items model))))
|
2005-05-25 05:44:27 -04:00
|
|
|
(debug-message "browse-dir-list-receiver "
|
|
|
|
"pos-y " pos-y " pos-x " pos-x
|
|
|
|
" marked-pos " marked-pos)
|
|
|
|
(make-simple-result-buffer-printer
|
|
|
|
pos-y pos-x text (list pos-y) marked-pos)))
|
2004-10-14 07:58:20 -04:00
|
|
|
|
|
|
|
((key-pressed-message? message)
|
2005-05-20 11:20:34 -04:00
|
|
|
(let* ((model (message-result-object message))
|
2004-10-14 07:58:20 -04:00
|
|
|
(key (key-pressed-message-key message))
|
|
|
|
(c-x-pressed (browse-dir-list-res-obj-c-x-pressed model)))
|
|
|
|
|
2005-05-17 05:56:11 -04:00
|
|
|
(cond
|
|
|
|
|
|
|
|
;; user pressed 'm' --- mark current entry
|
|
|
|
((= key key-m)
|
|
|
|
(let* ((marked-items (browse-dir-list-res-obj-marked-items model))
|
|
|
|
(res-marked-items (browse-dir-list-res-obj-res-marked-items
|
|
|
|
model))
|
|
|
|
(actual-pos (browse-dir-list-res-obj-pos-y model))
|
|
|
|
(all-items (browse-dir-list-res-obj-file-list model)))
|
|
|
|
(if (<= actual-pos 2)
|
|
|
|
model
|
2005-05-17 16:08:39 -04:00
|
|
|
(let* ((actual-item (list-ref all-items (- actual-pos 3)))
|
|
|
|
(actual-res-item
|
|
|
|
(if (not (string=? (cwd) "/"))
|
|
|
|
(string-append (cwd) "/" actual-item)
|
|
|
|
(string-append "/" actual-item))))
|
2005-05-17 05:56:11 -04:00
|
|
|
(if (member actual-res-item marked-items)
|
|
|
|
model
|
|
|
|
(let* ((new-res-marked-items (append res-marked-items
|
|
|
|
(list
|
|
|
|
actual-res-item)))
|
|
|
|
(new-marked-items (append marked-items
|
|
|
|
(list actual-item)))
|
|
|
|
(new-model (make-browse-dir-list-res-obj
|
|
|
|
(browse-dir-list-res-obj-pos-y model)
|
|
|
|
(browse-dir-list-res-obj-pos-x model)
|
|
|
|
(browse-dir-list-res-obj-file-list
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-result-text
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-working-directory
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-width model)
|
|
|
|
(browse-dir-list-res-obj-initial-wd
|
|
|
|
model)
|
|
|
|
new-marked-items
|
|
|
|
new-res-marked-items
|
|
|
|
#f)))
|
2005-05-17 16:08:39 -04:00
|
|
|
new-model))))))
|
2004-10-14 07:58:20 -04:00
|
|
|
|
2005-05-17 05:56:11 -04:00
|
|
|
;; user pressed 'u' --- unmark current entry
|
|
|
|
((= key key-u)
|
|
|
|
(let* ((marked-items (browse-dir-list-res-obj-marked-items model))
|
|
|
|
(res-marked-items (browse-dir-list-res-obj-res-marked-items
|
|
|
|
model))
|
|
|
|
(actual-pos (browse-dir-list-res-obj-pos-y model))
|
|
|
|
(all-items (browse-dir-list-res-obj-file-list model)))
|
|
|
|
(if (<= actual-pos 2)
|
|
|
|
model
|
|
|
|
(let* ((actual-item (list-ref all-items (- actual-pos 3)))
|
|
|
|
(actual-res-item (string-append (cwd) "/" actual-item))
|
|
|
|
(rest (member actual-item marked-items))
|
|
|
|
(res-rest (member actual-res-item res-marked-items)))
|
|
|
|
(if (not res-rest)
|
|
|
|
model
|
|
|
|
(let* ((after-item (length rest))
|
|
|
|
(all-items (length marked-items))
|
|
|
|
(before-item (sublist marked-items
|
|
|
|
0
|
|
|
|
(- all-items
|
|
|
|
after-item )))
|
|
|
|
(new-marked-items (append before-item
|
|
|
|
(list-tail rest 1)))
|
|
|
|
(after-res-item (length res-rest))
|
|
|
|
(all-res-items (length res-marked-items))
|
|
|
|
(before-res-item (sublist res-marked-items
|
|
|
|
0
|
|
|
|
(- all-res-items
|
|
|
|
after-res-item)))
|
|
|
|
(new-res-marked-items (append before-res-item
|
|
|
|
(list-tail res-rest
|
|
|
|
1)))
|
|
|
|
(new-model (make-browse-dir-list-res-obj
|
|
|
|
(browse-dir-list-res-obj-pos-y model)
|
|
|
|
(browse-dir-list-res-obj-pos-x model)
|
|
|
|
(browse-dir-list-res-obj-file-list
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-result-text
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-working-directory
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-width model)
|
|
|
|
(browse-dir-list-res-obj-initial-wd
|
|
|
|
model)
|
|
|
|
new-marked-items
|
|
|
|
new-res-marked-items
|
|
|
|
#f)))
|
2004-10-14 07:58:20 -04:00
|
|
|
new-model))))))
|
2005-05-17 05:56:11 -04:00
|
|
|
|
2004-10-14 07:58:20 -04:00
|
|
|
((= key key-up)
|
|
|
|
(let ((posy (browse-dir-list-res-obj-pos-y model)))
|
|
|
|
(if (<= posy 2)
|
|
|
|
model
|
|
|
|
(let* ((new-posy (- posy 1))
|
|
|
|
(new-model (make-browse-dir-list-res-obj
|
|
|
|
new-posy
|
|
|
|
(browse-dir-list-res-obj-pos-x model)
|
|
|
|
(browse-dir-list-res-obj-file-list model)
|
|
|
|
(browse-dir-list-res-obj-result-text model)
|
|
|
|
(browse-dir-list-res-obj-working-directory
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-width model)
|
|
|
|
(browse-dir-list-res-obj-initial-wd model)
|
|
|
|
(browse-dir-list-res-obj-marked-items model)
|
|
|
|
(browse-dir-list-res-obj-res-marked-items
|
|
|
|
model)
|
|
|
|
#f)))
|
|
|
|
new-model))))
|
|
|
|
|
|
|
|
((= key key-down)
|
|
|
|
(let ((posy (browse-dir-list-res-obj-pos-y model))
|
|
|
|
(num-lines (length
|
|
|
|
(browse-dir-list-res-obj-result-text model))))
|
|
|
|
(if (>= posy num-lines)
|
|
|
|
model
|
|
|
|
(let* ((new-posy (+ posy 1))
|
|
|
|
(new-model (make-browse-dir-list-res-obj
|
|
|
|
new-posy
|
|
|
|
(browse-dir-list-res-obj-pos-x model)
|
|
|
|
(browse-dir-list-res-obj-file-list model)
|
|
|
|
(browse-dir-list-res-obj-result-text model)
|
|
|
|
(browse-dir-list-res-obj-working-directory
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-width model)
|
|
|
|
(browse-dir-list-res-obj-initial-wd model)
|
|
|
|
(browse-dir-list-res-obj-marked-items model)
|
|
|
|
(browse-dir-list-res-obj-res-marked-items
|
|
|
|
model)
|
|
|
|
#f)))
|
|
|
|
new-model))))
|
2005-05-17 05:56:11 -04:00
|
|
|
|
2004-10-14 07:58:20 -04:00
|
|
|
((= key 10)
|
|
|
|
(selected-browse-dir-list model))
|
|
|
|
|
2005-05-17 05:56:11 -04:00
|
|
|
;; user pressed C-x
|
|
|
|
((= key 24)
|
|
|
|
(make-browse-dir-list-res-obj
|
|
|
|
(browse-dir-list-res-obj-pos-y model)
|
|
|
|
(browse-dir-list-res-obj-pos-x model)
|
|
|
|
(browse-dir-list-res-obj-file-list model)
|
|
|
|
(browse-dir-list-res-obj-result-text model)
|
|
|
|
(browse-dir-list-res-obj-working-directory
|
|
|
|
model)
|
|
|
|
(browse-dir-list-res-obj-width model)
|
|
|
|
(browse-dir-list-res-obj-initial-wd model)
|
|
|
|
(browse-dir-list-res-obj-marked-items model)
|
|
|
|
(browse-dir-list-res-obj-res-marked-items
|
|
|
|
model)
|
|
|
|
(not c-x-pressed)))
|
|
|
|
|
|
|
|
(else model))))
|
2004-10-14 07:58:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
((restore-message? message)
|
2005-05-20 11:20:34 -04:00
|
|
|
(let* ((model (message-result-object message))
|
2004-10-14 07:58:20 -04:00
|
|
|
(initial-wd (browse-dir-list-res-obj-initial-wd model)))
|
|
|
|
(chdir initial-wd)))
|
|
|
|
|
|
|
|
((selection-message? message)
|
2005-05-20 11:20:34 -04:00
|
|
|
(let* ((model (message-result-object message))
|
2004-10-14 07:58:20 -04:00
|
|
|
(marked-items (browse-dir-list-res-obj-res-marked-items model)))
|
|
|
|
(string-append "'" (exp->string marked-items)))))))
|
|
|
|
|
2005-05-22 11:05:25 -04:00
|
|
|
(define (list-of-fs-objects? thing)
|
|
|
|
(and (proper-list? thing)
|
|
|
|
(every fs-object? thing)))
|
2004-10-14 07:58:20 -04:00
|
|
|
|
2005-05-23 08:47:41 -04:00
|
|
|
(register-plugin!
|
|
|
|
(make-view-plugin browse-dir-list-receiver
|
|
|
|
list-of-fs-objects?))
|