diff --git a/collects/framework/main.ss b/collects/framework/main.ss index f61cf6b7..91615efd 100644 --- a/collects/framework/main.ss +++ b/collects/framework/main.ss @@ -909,7 +909,10 @@ (parameter-doc keymap:add-to-right-button-menu (parameter/c - (-> (is-a?/c popup-menu%) (is-a?/c editor<%>) (is-a?/c event%) void?)) + (-> (is-a?/c popup-menu%) + (is-a?/c editor<%>) + (is-a?/c event%) + void?)) proc @{When the keymap that @scheme[keymap:get-global] returns is installed into an editor, this parameter's value is used for right button diff --git a/collects/framework/private/editor.ss b/collects/framework/private/editor.ss index e3b9283e..d4887ea9 100644 --- a/collects/framework/private/editor.ss +++ b/collects/framework/private/editor.ss @@ -38,7 +38,9 @@ on-close can-close? close - get-filename/untitled-name)) + get-filename/untitled-name + + get-pos/text)) (define basic-mixin (mixin (editor<%>) (basic<%>) @@ -49,6 +51,31 @@ (begin (on-close) #t) #f)) + (define/public (get-pos/text event) + (let ([event-x (send event get-x)] + [event-y (send event get-y)] + [on-it? (box #f)]) + (let loop ([editor this]) + (let-values ([(x y) (send editor dc-location-to-editor-location event-x event-y)]) + (cond + [(is-a? editor text%) + (let ([pos (send editor find-position x y #f on-it?)]) + (cond + [(not (unbox on-it?)) (values #f #f)] + [else + (let ([snip (send editor find-snip pos 'after-or-none)]) + (if (and snip + (is-a? snip editor-snip%)) + (loop (send snip get-editor)) + (values pos editor)))]))] + [(is-a? editor pasteboard%) + (let ([snip (send editor find-snip x y)]) + (if (and snip + (is-a? snip editor-snip%)) + (loop (send snip get-editor)) + (values editor #f)))] + [else (values #f #f)]))))) + ;; get-filename/untitled-name : -> string ;; returns a string representing the visible name for this file, ;; or "Untitled " for some n. @@ -291,8 +318,7 @@ (get-top-level-window)]) (finder:put-file f d))) - - (super-instantiate ()))) + (super-new))) (define standard-style-list (new style-list%)) (define (get-standard-style-list) standard-style-list) diff --git a/collects/scribblings/framework/editor.scrbl b/collects/scribblings/framework/editor.scrbl index ea0bd0f2..04755375 100644 --- a/collects/scribblings/framework/editor.scrbl +++ b/collects/scribblings/framework/editor.scrbl @@ -116,6 +116,21 @@ returns a symbolic name (something like "Untitled"). } + + @defmethod[(get-pos/text [event (is-a?/c mouse-event%)]) + (values (or/c false/c (is-a?/c editor<%>)) + (or/c false/c number?))]{ + + This method's first result is @scheme[#f] when the mouse + event does not correspond to a location in the editor. + + If the first result is an @scheme[text%] object, then the + second result will be a position in the editor and + otherwise the second result will be @scheme[#f]. + + The @scheme[editor<%>] object will always be the nearest + enclosing editor containing the mouse click. + } } @defmixin[editor:basic-mixin (editor<%>) (editor:basic<%>)]{ This provides the basic editor services required by the rest of the