#lang racket/base
(require racket/gui framework/gui-utils)
(provide item-callback)
(define (item-callback str)
(define str-out #f)
(define f (new dialog% [label "Regexp Replace"]
[min-width 500]))
(define hp1 (new horizontal-panel% [parent f]))
(define t1 (new text-field% [parent hp1] [label "Replace:"]))
(define cb1 (new check-box% [parent hp1] [label "protect?"]))
(define hp2 (new horizontal-panel% [parent f]))
(define t2 (new text-field% [parent hp2] [label "\tBy:"]))
(define cb2 (new check-box% [parent hp2] [label "protect?"]))
(define (ok-pressed b ev)
(send f show #f)
(define t1-re ((if (send cb1 get-value) regexp-quote pregexp)
(send t1 get-value)))
(define t2-re ((if (send cb2 get-value) regexp-replace-quote values)
(send t2 get-value)))
(define new-lines
(for/list ([line (regexp-split #rx"\n" str)])
(regexp-replace* t1-re line t2-re)))
(set! str-out (string-join new-lines "\n"))
)
(define (cancel-pressed b ev)
(send f show #f)
)
(gui-utils:ok/cancel-buttons f ok-pressed cancel-pressed)
(send f show #t)
str-out)