extend 'open collection path' menu item to support local files,

when the dialog's content starts with an open quote, ala a require
This commit is contained in:
Robby Findler 2014-07-29 20:45:34 -05:00
parent 565fb07064
commit ee533c898c
8 changed files with 52 additions and 21 deletions

View File

@ -16,7 +16,7 @@
(provide
(contract-out
[alternate-racket-clcl/clcp (-> path-string? (values lcl/c lcp/c))]
[find-completions (->* (string?)
[find-completions (->* (string? path-string?)
(#:alternate-racket (or/c #f
path-string?
(list/c lcl/c lcp/c)))
@ -26,13 +26,32 @@
(or (member x '("compiled"))
(regexp-match #rx"~$" x)))
(define (find-completions string #:alternate-racket [alternate-racket #f])
(find-completions/internal string
(find-all-collection-dirs alternate-racket)
directory-list
directory-exists?))
(define (find-completions str the-current-directory #:alternate-racket [alternate-racket #f])
(cond
[(and (not (equal? str "")) (equal? (string-ref str 0) #\"))
(define no-quotes-string
(cond
[(equal? (string-ref str (- (string-length str) 1)) #\")
(define no-last-quote (substring str 0 (- (string-length str) 1)))
(cond
[(equal? "" no-last-quote)
no-last-quote]
[else
(substring no-last-quote 1 (string-length no-last-quote))])]
[else
(substring str 1 (string-length str))]))
(define segments (regexp-split #rx"/" no-quotes-string))
(find-completions/internal segments
(list (list "" the-current-directory))
directory-list
directory-exists?)]
[else
(find-completions-collection/internal str
(find-all-collection-dirs alternate-racket)
directory-list
directory-exists?)]))
(define (find-completions/internal string collection-dirs dir->content is-dir?)
(define (find-completions-collection/internal string collection-dirs dir->content is-dir?)
(define segments (regexp-split #rx"/" string))
(define first-candidates
(cond
@ -41,8 +60,11 @@
(define reg (regexp (string-append "^" (regexp-quote (car segments)))))
(filter (λ (line) (regexp-match reg (list-ref line 0)))
collection-dirs)]))
(find-completions/internal (cdr segments) first-candidates dir->content is-dir?))
(define (find-completions/internal segments first-candidates dir->content is-dir?)
(define unsorted
(let loop ([segments (cdr segments)]
(let loop ([segments segments]
[candidates first-candidates])
(cond
[(null? segments) candidates]
@ -178,7 +200,7 @@
(define/contract find-completions/c
(-> string? (listof (list/c string? path?)) (-> path? (listof path?)) (-> path? boolean?)
(listof (list/c string? path?)))
find-completions/internal)
find-completions-collection/internal)
(define coll-table
`(("racket" ,(string->path "/plt/pkgs/compatibility-pkgs/compatibility-lib/racket"))

View File

@ -819,7 +819,7 @@
(handler:open-file)
#t)))
(new menu-item%
[label (string-constant open-collection-path)]
[label (string-constant open-require-path)]
[shortcut #\o]
[shortcut-prefix (cons 'shift (get-default-shortcut-prefix))]
[parent file-menu]

View File

@ -12,7 +12,8 @@
(->i ()
(#:init [init string?]
#:pref [pref symbol?]
#:dir? [dir? boolean?])
#:dir? [dir? boolean?]
#:current-directory [current-directory (or/c path-string? #f)])
[res (dir?)
(if (or (not dir?)
(unsupplied-arg? dir?))
@ -21,8 +22,10 @@
(define (get-module-path-from-user #:init [init-value ""]
#:pref [pref-sym #f]
#:dir? [dir? #f])
#:dir? [dir? #f]
#:current-directory
[_the-current-directory #f])
(define the-current-directory (or _the-current-directory (current-directory)))
(define dlg%
(class dialog%
(define/override (on-subwindow-char receiver event)
@ -144,6 +147,7 @@
(get-clcl/clcp)))
(define the-completions
(find-completions (send tf get-value)
the-current-directory
#:alternate-racket alt-racket-info))
(for ([i (in-list (if dir?
(filter (λ (i) (directory-exists? (list-ref i 1)))

View File

@ -3752,7 +3752,7 @@
[define/override file-menu:between-open-and-revert
(lambda (file-menu)
(new menu:can-restore-menu-item%
[label (string-constant open-collection-path)]
[label (string-constant open-require-path)]
[shortcut (if (member 'shift (get-default-shortcut-prefix)) #f #\o)]
[shortcut-prefix (if (member 'shift (get-default-shortcut-prefix))
(get-default-shortcut-prefix)
@ -3776,7 +3776,11 @@
(get-module-path-from-user
#:init (or editing-module-path
(preferences:get 'drracket:open-module-path-last-used))
#:pref 'drracket:open-module-path-last-used))
#:pref 'drracket:open-module-path-last-used
#:current-directory
(and editing-path
(let-values ([(base name dir?) (split-path editing-path)])
base))))
(when pth (handler:edit-file pth)))])
(super file-menu:between-open-and-revert file-menu)
(make-object separator-menu-item% file-menu))]

View File

@ -24,11 +24,12 @@
@item{@defmenuitem{Open Recent} Lists recently opened
files. Choosing one of them opens that file for editing.}
@item{@defmenuitem{Open Collection Path...} Opens a dialog where you
@item{@defmenuitem{Open Require Path...} Opens a dialog where you
can enter in a @racket[require]-like module path (e.g.,
@litchar{racket/base.rkt} or @litchar{data/splay-tree.rkt})
@litchar{racket/base.rkt} or @litchar{data/splay-tree.rkt}
or @litchar{"x.rkt"})
and edit the corresponding files in the @tech{definitions window}.}
@item{@defmenuitem{Install PLT File...} Opens a dialog asking for the
location of the @filepath{.plt} file (either on the local disk or
on the web) and installs the contents of the file.}

View File

@ -1900,7 +1900,7 @@ please adhere to these guidelines:
" either abort the current one or wait for it to finish.")
;; open a file via a collection path (new "Open" menu item in DrRacket)
(open-collection-path "Open Collection Path...")
(open-require-path "Open Require Path...")
(enter-subcollection "Enter subcollection") ; button in new dialog
(path-to-racket-binary "Path to binary")
(use-a-different-racket "Use a different racket")

View File

@ -1893,7 +1893,7 @@
" abandonnez l'installation ou la mise à jour actuelle, ou attendez-en la fin.")
;; open a file via a collection path (new "Open" menu item in DrRacket)
(open-collection-path "Ouvrir un chemin de répertoires pour une collection...")
;; now obsolete; replaced by open-require-path (open-collection-path "Ouvrir un chemin de répertoires pour une collection...")
(enter-subcollection "Spécifier une sous-collection") ; button in new dialog
(path-to-racket-binary "Chemin de répertoires vers le fichier binaire")
(use-a-different-racket "Utiliser une version de racket différente")

View File

@ -1777,7 +1777,7 @@
" Brechen Sie entweder den laufenden Prozess ab oder warten, bis er fertig ist.")
;; open a file via a collection path (new "Open" menu item in DrRacket)
(open-collection-path "Collection-Pfad öffnen...")
;; now obsolete; replaced by open-require-path (open-collection-path "Collection-Pfad öffnen...")
(enter-subcollection "Sub-Collection betreten") ; button in new dialog
(path-to-racket-binary "Pfad zur Programmdatei")