moved feedback messages till after add and remove are done. now shows which item was removed
parent
fe35b97834
commit
d9aea661a1
72
util.rkt
72
util.rkt
|
@ -27,28 +27,18 @@
|
||||||
(define (list-empty? lst)
|
(define (list-empty? lst)
|
||||||
(empty? (rest (file->string-list lst))))
|
(empty? (rest (file->string-list lst))))
|
||||||
|
|
||||||
(define (quote-item-in-list lst args)
|
(define (get-removed-item lst args)
|
||||||
(cond
|
(list-ref lst (string->number args)))
|
||||||
[(number? args)
|
|
||||||
(display
|
(define (quote-item args)
|
||||||
(string-append
|
(display
|
||||||
"\""
|
(string-append "\"" args "\"")))
|
||||||
(list-ref lst (string->number args))
|
|
||||||
"\""))]
|
|
||||||
[(string? args)
|
|
||||||
(display
|
|
||||||
(string-append
|
|
||||||
"\""
|
|
||||||
args
|
|
||||||
"\""))]))
|
|
||||||
|
|
||||||
(define (number-list lst)
|
(define (number-list lst)
|
||||||
(map
|
(map string-append
|
||||||
string-append
|
(map number->string
|
||||||
(map
|
(rest (range (length lst))))
|
||||||
number->string
|
(rest lst)))
|
||||||
(rest (range (length lst))))
|
|
||||||
(rest lst)))
|
|
||||||
|
|
||||||
(define (indent-list)
|
(define (indent-list)
|
||||||
(lambda (lst)
|
(lambda (lst)
|
||||||
|
@ -75,46 +65,44 @@
|
||||||
(d-hash-ref messages 'try-init)]))
|
(d-hash-ref messages 'try-init)]))
|
||||||
|
|
||||||
(define (add-item-to-file args)
|
(define (add-item-to-file args)
|
||||||
(begin
|
|
||||||
(d-hash-ref messages 'item-added-prefix)
|
|
||||||
(quote-item-in-list (file->string-list path) args)
|
|
||||||
(d-hash-ref messages 'item-added-suffix))
|
|
||||||
(let ([new-list
|
(let ([new-list
|
||||||
(reverse
|
(reverse
|
||||||
(append (list args)
|
(append (list args)
|
||||||
(reverse
|
(reverse (file->string-list path))))])
|
||||||
(file->string-list path))))])
|
|
||||||
(display-to-file
|
(display-to-file
|
||||||
(string-join new-list "\n" #:after-last "\n")
|
(string-join new-list "\n" #:after-last "\n")
|
||||||
path
|
path
|
||||||
#:mode 'text
|
#:mode 'text
|
||||||
#:exists 'replace)))
|
#:exists 'replace)
|
||||||
|
(d-hash-ref messages 'item-added-prefix)
|
||||||
|
(quote-item args)
|
||||||
|
(d-hash-ref messages 'item-added-suffix)))
|
||||||
|
|
||||||
(define (add-item args)
|
(define (add-item args)
|
||||||
(if
|
(if
|
||||||
(and
|
(and
|
||||||
(check-for-folder)
|
(check-for-folder)
|
||||||
(check-for-file))
|
(check-for-file))
|
||||||
(add-item-to-file (vector-ref args 1))
|
(add-item-to-file (vector-ref args 1))
|
||||||
(begin
|
(begin
|
||||||
(d-hash-ref messages 'file-not-found)
|
(d-hash-ref messages 'file-not-found)
|
||||||
(d-hash-ref messages 'try-init))))
|
(d-hash-ref messages 'try-init))))
|
||||||
|
|
||||||
(define (remove-item-from-file args)
|
(define (remove-item-from-file args)
|
||||||
(d-hash-ref messages 'item-removed-prefix)
|
(let ([removed-item
|
||||||
(quote-item-in-list (file->string-list path) args)
|
(get-removed-item (file->string-list path) args)])
|
||||||
(d-hash-ref messages 'item-removed-suffix)
|
(let ([new-list
|
||||||
(let ([new-list
|
(remove
|
||||||
(remove (list-ref
|
(list-ref (file->string-list path) (string->number args))
|
||||||
(file->string-list path)
|
(file->string-list path))])
|
||||||
(string->number
|
(display-to-file
|
||||||
args))
|
(string-join new-list "\n" #:after-last "\n")
|
||||||
(file->string-list path))])
|
path
|
||||||
(display-to-file
|
#:mode 'text
|
||||||
(string-join new-list "\n" #:after-last "\n")
|
#:exists 'replace))
|
||||||
path
|
(d-hash-ref messages 'item-removed-prefix)
|
||||||
#:mode 'text
|
(quote-item removed-item)
|
||||||
#:exists 'replace)))
|
(d-hash-ref messages 'item-removed-suffix)))
|
||||||
|
|
||||||
(define (remove-item args)
|
(define (remove-item args)
|
||||||
(cond
|
(cond
|
||||||
|
|
Loading…
Reference in New Issue