racket/draw: add #:eventspace' argument to
open-output-text-editor'
The argument is `(curent-eventspace)' by default, which makes ports work better with threads. Closes PR 12749
This commit is contained in:
parent
48f7ddafe4
commit
b30374824a
|
@ -10,7 +10,7 @@
|
|||
(provide open-input-text-editor
|
||||
open-input-graphical-file
|
||||
text-editor-load-handler
|
||||
open-output-text-editor )
|
||||
open-output-text-editor)
|
||||
|
||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
@ -312,7 +312,8 @@
|
|||
p))
|
||||
|
||||
(define open-output-text-editor
|
||||
(lambda (text [start 'end] [special-filter values] [port-name text])
|
||||
(lambda (text [start 'end] [special-filter values] [port-name text]
|
||||
#:eventspace [eventspace (wx:current-eventspace)])
|
||||
(define pos (if (eq? start 'end)
|
||||
(send text last-position)
|
||||
(min start
|
||||
|
@ -322,9 +323,16 @@
|
|||
(define raw-buffer (make-bytes 128))
|
||||
(define utf8-buffer (make-bytes 128))
|
||||
(define (show s)
|
||||
(send text begin-edit-sequence)
|
||||
(send text insert s pos)
|
||||
(send text end-edit-sequence)
|
||||
(define (insert)
|
||||
(send text begin-edit-sequence)
|
||||
(send text insert s pos)
|
||||
(send text end-edit-sequence))
|
||||
(if (and eventspace
|
||||
(and (not (eq? (current-thread)
|
||||
(wx:eventspace-handler-thread eventspace)))))
|
||||
(parameterize ([wx:current-eventspace eventspace])
|
||||
(wx:queue-callback insert #f))
|
||||
(insert))
|
||||
(set! pos (+ (string-length s) pos)))
|
||||
(define (flush-text)
|
||||
(let ([cnt (peek-bytes-avail!* raw-buffer 0 #f in)])
|
||||
|
|
|
@ -266,7 +266,8 @@ if using those methods are always safe.)
|
|||
@defproc[(open-output-text-editor [text-editor (is-a?/c text%)]
|
||||
[start-position (or/c exact-nonnegative-integer? (one/of 'end)) 'end]
|
||||
[special-filter (any/c . -> . any/c) (lambda (x) x)]
|
||||
[port-name any/c text-editor])
|
||||
[port-name any/c text-editor]
|
||||
[#:eventspace eventspace (or/c eventspace? #f) (current-eventspace)])
|
||||
output-port]{
|
||||
|
||||
Creates an output port that delivers its content to @racket[text-editor].
|
||||
|
@ -284,9 +285,20 @@ If line counting is enabled for the resulting output port, then the
|
|||
port will report the line, offset from the line's start, and position
|
||||
within the editor at which the port writes data.
|
||||
|
||||
If @racket[eventspace] is not @racket[#f], then when the output port
|
||||
is used in a thread other than @racket[eventspace]'s handler thread,
|
||||
content is delivered to @racket[text-editor] through a low-priority
|
||||
callback in @racket[eventspace]. Thus, if @racket[eventspace]
|
||||
corresponds to the eventspace for the editor's @tech{displays},
|
||||
writing to the output port is safe from any thread.
|
||||
|
||||
If @racket[eventspace] is @racket[#f], beware that the port is only
|
||||
weakly thread-safe. Content is delivered to @racket[text-editor] in
|
||||
an @tech{edit sequence}, but an edit sequence is not enough
|
||||
synchronization if, for example, the editor is displayed in an
|
||||
enabled @racket[editor-canvas%]. See @secref["editorthreads"] for
|
||||
more information.}
|
||||
|
||||
}
|
||||
|
||||
@defproc[(read-editor-global-footer [in (is-a?/c editor-stream-in%)])
|
||||
boolean?]{
|
||||
|
|
|
@ -735,7 +735,7 @@ An editor supports certain concurrent patterns
|
|||
@itemize[
|
||||
|
||||
@item{When an editor's @method[editor<%> refresh] method is
|
||||
called during an edit sequence (which is started by
|
||||
called during an @deftech{edit sequence} (which is started by
|
||||
@method[editor<%> begin-edit-sequence] and ended with
|
||||
@method[editor<%> end-edit-sequence]), the requested refresh
|
||||
region is recorded, but the refresh is not performed. Instead, the
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
Version 5.3.0.5
|
||||
Added box-cas!
|
||||
racket/gui: changed open-output-text-editor to by default deliver
|
||||
content via the current eventspace's handler thread; also
|
||||
added an #:eventspace optional argument
|
||||
|
||||
Version 5.3.0.4
|
||||
racket/draw: added make-color, make-brush, make-pen
|
||||
|
|
Loading…
Reference in New Issue
Block a user