(module dr-fuzzy-gui scheme/gui
(provide start-drfuzzy)
(require "dr-fuzzy.scm"
framework/gui-utils)
(define (create-dr-fuzzy-dialog function-to-use-with-files)
(local
[ (define (fill-list-with-search-result query)
(local [(define (fill list-of-match-results)
(cond
[(empty? list-of-match-results) (void)]
[else
(begin
(send list-of-hits append
(match-result-tagged-path
(first list-of-match-results))
(match-result-path
(first list-of-match-results)))
(fill (rest list-of-match-results)))]))]
(begin (send list-of-hits set empty)
(fill (search query)))))
(define (open-files)
(local [(define (open-the-selection selected-files)
(cond
[(empty? selected-files) (void)]
[else
(begin
(function-to-use-with-files
(path->string (send list-of-hits
get-data
(first selected-files))))
(open-the-selection (rest selected-files)))]))]
(open-the-selection (send list-of-hits get-selections))))
(define (clean-list)
(send list-of-hits set empty))
(define (clean-all)
(begin (send (send search-field
get-editor)
erase)
(clean-list)))
(define main-dialog (new dialog%
[label "DrFuzzy"]
[width 500]
[height 400]))
(define search-field (new text-field%
[parent main-dialog]
[label "&Search for:"]
[callback
(λ (a-text-field event)
(fill-list-with-search-result
(send (send a-text-field
get-editor)
get-text)))]))
(define list-of-hits (new list-box%
[label "&Results:"]
[choices empty]
[parent main-dialog]
[style '(multiple vertical-label)]))
(define panel (new horizontal-panel%
[parent main-dialog]
[alignment '(right bottom)]
[stretchable-height #f]))
(define-values (button-ok button-cancel)
(gui-utils:ok/cancel-buttons panel
(lambda (button event)
(begin (open-files)
(send main-dialog show #f)))
(lambda (button event)
(send main-dialog show #f))))]
(begin
(clean-all)
(send search-field focus)
(send main-dialog show #t))))
(define (start-drfuzzy do-with-files)
(with-handlers ((exn:fail?
(λ (exception)
(message-box "Error starting dr-fuzzy"
(exn-message exception)
#f
'(ok stop)))))
(begin
(load-files!)
(create-dr-fuzzy-dialog do-with-files)))))