add a find-from-selection menu item that grabs the selection and puts

it directly into the find window

related to PR 12978
This commit is contained in:
Robby Findler 2012-08-06 16:58:29 -05:00
parent 0bd53a3549
commit b16843a908
5 changed files with 68 additions and 8 deletions

View File

@ -2169,6 +2169,15 @@
(define/override (edit-menu:find-callback menu evt) (unhide-search-and-toggle-focus) #t)
(define/override (edit-menu:create-find?) #t)
(define/override (edit-menu:find-from-selection-callback menu evt)
(unhide-search-and-toggle-focus #:new-search-string-from-selection? #t)
#t)
(define/override (edit-menu:find-from-selection-on-demand item)
(define t (get-text-to-search))
(send item enable (and t (not (= (send t get-start-position)
(send t get-end-position))))))
(define/override (edit-menu:create-find-from-selection?) #t)
(define/override (edit-menu:find-next-callback menu evt) (search 'forward) #t)
(define/override (edit-menu:create-find-next?) #t)
@ -2280,26 +2289,47 @@
(when canvas
(send canvas focus))))))
(define/public (unhide-search focus?)
(define/public (unhide-search focus? #:new-search-string-from-selection? [new-search-string-from-selection? #f])
(when hidden?
(set! hidden? #f)
(build-search-gui-in-frame)
(unless (memq search/replace-panel (send super-root get-children))
(send super-root add-child search/replace-panel))
(search-parameters-changed)
(send find-edit begin-edit-sequence)
(when new-search-string-from-selection?
(update-search-string-from-selection))
(when focus?
(send find-edit set-position 0 (send find-edit last-position))
(send (send find-edit get-canvas) focus))))
(send (send find-edit get-canvas) focus))
(send find-edit end-edit-sequence)))
(define/public (unhide-search-and-toggle-focus)
(define/public (unhide-search-and-toggle-focus #:new-search-string-from-selection? [new-search-string-from-selection? #f])
(if hidden?
(unhide-search #t)
(unhide-search #t #:new-search-string-from-selection? new-search-string-from-selection?)
(let ([canvas (and text-to-search (send text-to-search get-canvas))])
(cond
[(or (not text-to-search) (and canvas (send canvas has-focus?)))
(send find-edit begin-edit-sequence)
(when new-search-string-from-selection?
(update-search-string-from-selection))
(send find-edit set-position 0 (send find-edit last-position))
(send find-canvas focus)]
[canvas (send canvas focus)]))))
(send find-canvas focus)
(send find-edit end-edit-sequence)]
[canvas
(send canvas focus)]))))
(define/private (update-search-string-from-selection)
(when (and text-to-search
(not (= (send text-to-search get-start-position)
(send text-to-search get-end-position))))
(send find-edit delete 0 (send find-edit last-position))
(send text-to-search move/copy-to-edit
find-edit
(send text-to-search get-start-position)
(send text-to-search get-end-position)
0
#:try-to-move? #f)))
(define/public (search searching-direction)
(unhide-search #f)

View File

@ -360,6 +360,14 @@
'(string-constant find-menu-item)
edit-menu:edit-target-on-demand
#f)
(make-an-item 'edit-menu 'find-from-selection
'(string-constant find-info)
'(λ (item control) (void))
#\f
'(cons 'shift (get-default-shortcut-prefix))
'(string-constant find-from-selection-menu-item)
edit-menu:edit-target-on-demand
#f)
(make-an-item 'edit-menu 'find-next
'(string-constant find-next-info)

View File

@ -124,13 +124,20 @@ blinking caret. Each window maintains its own Undo and Redo history.
@item{@defmenuitem{Wrap Text} Toggles between wrapped text and
unwrapped text in the window.}
@item{@defmenuitem{Find...} Opens an interactive search
@item{@defmenuitem{Find} Opens an interactive search
window at the bottom of the frame and moves the insertion
point to the search string editor (or out of it, if the
insertion point is already there).
See also @secref["Searching"].}
@item{@defmenuitem{Find From Selection}
Just like @onscreen{Find}, except that it
copies the current selection into the search
window (but without using the clipboard, so
paste will paste whatever was last copied,
not the new search string)}
@item{@defmenuitem{Find Again} Finds the next occurrence of the text
in the search window.}

View File

@ -821,12 +821,26 @@
This method hides the searching information on the bottom of the frame.
}
@defmethod[(unhide-search [move-focus? boolean?]) void?]{
@defmethod[(unhide-search [move-focus? boolean?]
[#:new-search-string-from-selection? new-search-string-from-selection? boolean? #f])
void?]{
When the searching sub window is hidden, makes it visible. If
@racket[move-focus?] is @racket[#f], the focus is not moved, but if it is
any other value, the focus is moved to the find window.
If @racket[new-search-string-from-selection?] is a true value and the selection
in the result of @method[frame:searchable<%> get-text-to-search] is not empty,
then the search editor is replaced with the selection.
}
@defmethod[(unhide-search-and-toggle-focus
[#:new-search-string-from-selection? new-search-string-from-selection? boolean? #f])
void?]{
Like @method[frame:searchable<%> unhide-search], except it also moves the focus into the
text to be searched, or into the search string text, depending on where it
currently is.
}
@defmethod[(get-case-sensitive-search?) boolean?]{
Returns @racket[#t] if the search is currently case-sensitive. (This
method's value depends on the preference

View File

@ -733,6 +733,7 @@ please adhere to these guidelines:
(select-all-menu-item "Select A&ll")
(find-menu-item "Find") ;; menu item
(find-from-selection-menu-item "Find From Selection")
(find-info "Toggles the keyboard focus between the window being searched and the search bar")
(find-next-info "Skip to the next occurrence of the string in the find window")