2005-05-25 05:44:27 -04:00
|
|
|
(define-record-type select-list :select-list
|
2005-05-25 07:36:12 -04:00
|
|
|
(really-make-select-list elements view-index cursor-index num-lines)
|
2005-05-25 05:44:27 -04:00
|
|
|
select-list?
|
|
|
|
(elements select-list-elements)
|
|
|
|
(view-index select-list-view-index)
|
|
|
|
(cursor-index select-list-cursor-index)
|
2005-05-25 07:36:12 -04:00
|
|
|
(num-lines select-list-num-lines))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
|
|
|
(define-record-discloser :select-list
|
|
|
|
(lambda (r)
|
|
|
|
`(select-list (index ,(select-list-cursor-index r))
|
|
|
|
(view-index ,(select-list-view-index r))
|
2005-05-25 07:36:12 -04:00
|
|
|
(num-lines ,(select-list-num-lines r)))))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-05-26 07:32:51 -04:00
|
|
|
(define (make-select-list elements num-lines)
|
2005-05-28 08:07:21 -04:00
|
|
|
(really-make-select-list elements 0 0 num-lines))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
|
|
|
(define key-m 109)
|
|
|
|
|
|
|
|
(define key-u 117)
|
|
|
|
|
2005-05-30 15:19:36 -04:00
|
|
|
(define (select-list-handle-key-press select-list key)
|
|
|
|
(cond
|
|
|
|
((= key key-m)
|
|
|
|
(mark-current-line select-list))
|
|
|
|
((= key key-u)
|
|
|
|
(unmark-current-line select-list))
|
|
|
|
((= key key-up)
|
|
|
|
(move-cursor-up select-list))
|
|
|
|
((= key key-down)
|
|
|
|
(move-cursor-down select-list))
|
|
|
|
(else
|
|
|
|
select-list)))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-05-30 11:38:13 -04:00
|
|
|
(define (select-list-navigation-key? key)
|
|
|
|
(or (= key key-up) (= key key-down)))
|
|
|
|
|
|
|
|
(define (select-list-marking-key? key)
|
|
|
|
(or (= key key-m) (= key key-u)))
|
|
|
|
|
2005-09-27 12:30:23 -04:00
|
|
|
(define (select-list-key? key)
|
|
|
|
(or (select-list-navigation-key? key)
|
|
|
|
(select-list-marking-key? key)))
|
|
|
|
|
2005-05-25 05:44:27 -04:00
|
|
|
(define (mark/unmark-current-line-maker mark)
|
|
|
|
(lambda (select-list)
|
|
|
|
(let* ((index (select-list-cursor-index select-list))
|
|
|
|
(elements (select-list-elements select-list)))
|
|
|
|
(really-make-select-list
|
|
|
|
(fold-right
|
|
|
|
(lambda (element.i result)
|
|
|
|
(let ((el (car element.i))
|
|
|
|
(i (cadr element.i)))
|
|
|
|
(cons (make-element
|
2005-05-26 07:32:51 -04:00
|
|
|
(element-markable? el)
|
2005-05-25 07:43:46 -04:00
|
|
|
(if (and (element-markable? el)
|
|
|
|
(= index i))
|
|
|
|
mark
|
|
|
|
(element-marked? el))
|
2005-05-25 05:44:27 -04:00
|
|
|
(element-value el)
|
2005-09-27 12:29:34 -04:00
|
|
|
(element-painter el))
|
2005-05-25 05:44:27 -04:00
|
|
|
result)))
|
|
|
|
'() (zip elements (iota (length elements))))
|
|
|
|
(select-list-view-index select-list)
|
2005-05-25 07:36:12 -04:00
|
|
|
index (select-list-num-lines select-list)))))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
|
|
|
(define unmark-current-line
|
|
|
|
(mark/unmark-current-line-maker #f))
|
|
|
|
|
|
|
|
(define mark-current-line
|
|
|
|
(mark/unmark-current-line-maker #t))
|
|
|
|
|
|
|
|
;; returns: y cursor-index view-index
|
2005-05-25 07:36:12 -04:00
|
|
|
(define (calculate-view index-move elements
|
|
|
|
view-index cursor-index
|
|
|
|
num-lines)
|
2005-05-25 05:44:27 -04:00
|
|
|
(let ((new-index (index-move cursor-index))
|
|
|
|
(max-index (- (length elements) 1)))
|
|
|
|
(cond
|
|
|
|
((< new-index 0)
|
2005-05-25 07:36:12 -04:00
|
|
|
(values 0 view-index))
|
2005-05-25 05:44:27 -04:00
|
|
|
((> new-index max-index)
|
2005-05-25 07:36:12 -04:00
|
|
|
(values max-index view-index))
|
2005-05-25 05:44:27 -04:00
|
|
|
((and (>= (- new-index view-index) num-lines)
|
|
|
|
(> new-index cursor-index))
|
2005-05-25 07:36:12 -04:00
|
|
|
(values new-index (+ view-index num-lines)))
|
2005-05-25 05:44:27 -04:00
|
|
|
((and (< new-index cursor-index)
|
|
|
|
(>= view-index cursor-index))
|
2005-05-25 07:36:12 -04:00
|
|
|
(values new-index (- view-index num-lines)))
|
2005-05-25 05:44:27 -04:00
|
|
|
(else
|
2005-05-25 07:36:12 -04:00
|
|
|
(values (index-move cursor-index) view-index)))))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-05-25 07:36:12 -04:00
|
|
|
(define (move-cursor-maker index-move)
|
|
|
|
(lambda (select-list)
|
2005-05-25 05:44:27 -04:00
|
|
|
(let* ((elements (select-list-elements select-list))
|
2005-05-25 07:36:12 -04:00
|
|
|
(old-index (select-list-cursor-index select-list))
|
|
|
|
(num-lines (select-list-num-lines select-list)))
|
2005-05-25 05:44:27 -04:00
|
|
|
(call-with-values
|
|
|
|
(lambda ()
|
2005-05-25 07:36:12 -04:00
|
|
|
(calculate-view index-move
|
2005-05-25 05:44:27 -04:00
|
|
|
elements
|
|
|
|
(select-list-view-index select-list)
|
|
|
|
old-index
|
2005-05-25 07:36:12 -04:00
|
|
|
num-lines))
|
|
|
|
(lambda (cursor-index view-index)
|
2005-05-25 05:44:27 -04:00
|
|
|
(really-make-select-list
|
2005-05-28 08:07:21 -04:00
|
|
|
elements
|
2005-05-25 05:44:27 -04:00
|
|
|
view-index
|
|
|
|
cursor-index
|
2005-05-25 07:36:12 -04:00
|
|
|
num-lines))))))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
|
|
|
(define move-cursor-up
|
2005-05-25 07:36:12 -04:00
|
|
|
(move-cursor-maker (lambda (y) (- y 1))))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
|
|
|
(define move-cursor-down
|
2005-05-25 07:36:12 -04:00
|
|
|
(move-cursor-maker (lambda (y) (+ y 1))))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
|
|
|
(define (take-max lst num)
|
|
|
|
(if (>= num (length lst))
|
|
|
|
lst
|
|
|
|
(take lst num)))
|
|
|
|
|
2005-05-25 07:36:12 -04:00
|
|
|
(define (select-visible-elements select-list num-lines)
|
|
|
|
(take-max (drop (select-list-elements select-list)
|
|
|
|
(select-list-view-index select-list))
|
|
|
|
(+ 1 num-lines)))
|
2005-05-25 05:44:27 -04:00
|
|
|
|
2005-09-27 12:31:54 -04:00
|
|
|
(define (paint-selection-list select-list win width have-focus?)
|
|
|
|
(paint-selection-list-at select-list 0 0 win width have-focus?))
|
2005-05-25 07:36:12 -04:00
|
|
|
|
2005-09-27 12:31:54 -04:00
|
|
|
(define (paint-selection-list-at select-list x y win width
|
2005-09-27 12:30:57 -04:00
|
|
|
have-focus?)
|
2005-09-27 05:02:28 -04:00
|
|
|
(let ((num-lines (select-list-num-lines select-list))
|
2005-09-27 12:31:54 -04:00
|
|
|
(cursor-index (select-list-cursor-index select-list)))
|
2005-05-31 03:59:31 -04:00
|
|
|
(let lp ((elts
|
|
|
|
(select-visible-elements select-list num-lines))
|
|
|
|
(y y)
|
|
|
|
(i (select-list-view-index select-list)))
|
|
|
|
(cond
|
|
|
|
((null? elts)
|
|
|
|
(values))
|
2005-09-27 05:02:28 -04:00
|
|
|
((= i cursor-index)
|
2005-09-27 12:30:57 -04:00
|
|
|
((element-painter (car elts)) win x y width #t (element-marked? (car elts)))
|
|
|
|
(lp (cdr elts) (+ y 1) (+ i 1)))
|
2005-05-31 03:59:31 -04:00
|
|
|
((element-marked? (car elts))
|
2005-09-27 12:30:57 -04:00
|
|
|
((element-painter (car elts)) win x y width #f #t)
|
|
|
|
(lp (cdr elts) (+ y 1) (+ i 1)))
|
2005-05-31 03:59:31 -04:00
|
|
|
(else
|
2005-09-27 12:30:57 -04:00
|
|
|
((element-painter (car elts)) win x y width #f #f)
|
2005-05-31 03:59:31 -04:00
|
|
|
(lp (cdr elts) (+ y 1) (+ i 1)))))))
|
2005-05-25 09:48:17 -04:00
|
|
|
|
2005-09-27 04:08:15 -04:00
|
|
|
(define (select-list-get-marked select-list)
|
2005-05-25 09:48:17 -04:00
|
|
|
(map element-value
|
2005-05-28 08:07:21 -04:00
|
|
|
(filter element-marked?
|
|
|
|
(select-list-elements select-list))))
|
2005-05-25 09:48:17 -04:00
|
|
|
|
2005-09-27 12:32:46 -04:00
|
|
|
(define (select-list-has-marks? select-list)
|
|
|
|
(let lp ((elts (select-list-elements select-list)))
|
|
|
|
(if (null? elts)
|
|
|
|
#f
|
|
|
|
(if (element-marked? (car elts))
|
|
|
|
#t
|
|
|
|
(lp (cdr elts))))))
|
|
|
|
|
2005-05-25 09:48:17 -04:00
|
|
|
(define (select-list-selected-entry select-list)
|
|
|
|
(element-value
|
2005-09-27 04:08:15 -04:00
|
|
|
(select-list-selected-element select-list)))
|
|
|
|
|
|
|
|
(define (select-list-selected-element select-list)
|
|
|
|
(list-ref (select-list-elements select-list)
|
|
|
|
(select-list-cursor-index select-list)))
|
|
|
|
|
|
|
|
(define (select-list-get-selection select-list)
|
|
|
|
(let ((marked (select-list-get-marked select-list)))
|
|
|
|
(if (null? marked)
|
|
|
|
(let ((selected (select-list-selected-element select-list)))
|
|
|
|
(if (element-markable? selected)
|
|
|
|
(list (element-value selected))
|
|
|
|
'()))
|
|
|
|
marked)))
|
2005-06-04 07:22:44 -04:00
|
|
|
|
2005-07-06 04:57:44 -04:00
|
|
|
(define (make-get-selection-as-ref-method select-list)
|
2005-06-04 07:22:44 -04:00
|
|
|
(lambda (self focus-object-table)
|
2005-09-27 04:08:15 -04:00
|
|
|
(let ((marked (select-list-get-marked select-list))
|
2005-06-04 07:22:44 -04:00
|
|
|
(make-reference (lambda (obj)
|
|
|
|
(make-focus-object-reference
|
|
|
|
focus-object-table obj))))
|
|
|
|
(if (null? marked)
|
2005-09-27 04:46:34 -04:00
|
|
|
(write-to-string
|
2005-06-04 07:22:44 -04:00
|
|
|
(make-reference (select-list-selected-entry select-list)))
|
|
|
|
(string-append
|
|
|
|
"(list "
|
2005-09-27 04:46:34 -04:00
|
|
|
(string-join (map write-to-string (map make-reference marked)))
|
2005-06-04 07:22:44 -04:00
|
|
|
")")))))
|
|
|
|
|