racket/gui: add delete' to choice%' and `list-control<%>'

Closes PR 13230
This commit is contained in:
Matthew Flatt 2012-11-04 07:36:36 -07:00
parent c6fc92915d
commit 0c82f54912
9 changed files with 41 additions and 33 deletions

View File

@ -600,7 +600,10 @@
[find-string (entry-point (lambda (x) [find-string (entry-point (lambda (x)
(check-label-string '(method list-control<%> find-string) x) (check-label-string '(method list-control<%> find-string) x)
(do-find-string x)))] (do-find-string x)))]
[delete (entry-point (lambda (n)
(check-item 'delete n)
(send this -delete-list-item n)
(send wx delete n)))]
[-append-list-string (lambda (i) [-append-list-string (lambda (i)
(set! content (append content (list i))))] (set! content (append content (list i))))]
[-set-list-string (lambda (i s) [-set-list-string (lambda (i s)
@ -843,10 +846,6 @@
(set! column-labels (append column-labels (list label))) (set! column-labels (append column-labels (list label)))
(send wx append-column label))))] (send wx append-column label))))]
[delete (entry-point (lambda (n)
(check-item 'delete n)
(send this -delete-list-item n)
(send wx delete n)))]
[get-data (entry-point (lambda (n) (check-item 'get-data n) (send wx get-data n)))] [get-data (entry-point (lambda (n) (check-item 'get-data n) (send wx get-data n)))]
[get-label-font (lambda () (send wx get-label-font))] [get-label-font (lambda () (send wx get-label-font))]
[get-selections (entry-point (lambda () (send wx get-selections)))] [get-selections (entry-point (lambda () (send wx get-selections)))]

View File

@ -68,6 +68,8 @@
(tellv (get-cocoa) (tellv (get-cocoa)
insertItemWithTitle: #:type _NSString lbl insertItemWithTitle: #:type _NSString lbl
atIndex: #:type _NSInteger (number))) atIndex: #:type _NSInteger (number)))
(define/public (delete i)
(tellv (get-cocoa) removeItemAtIndex: #:type _NSInteger i))
(define/override (maybe-register-as-child parent on?) (define/override (maybe-register-as-child parent on?)
(register-as-child parent on?))) (register-as-child parent on?)))

View File

@ -78,9 +78,12 @@
(set! ignore-clicked? #t) (set! ignore-clicked? #t)
(gtk_combo_box_set_active gtk i) (gtk_combo_box_set_active gtk i)
(set! ignore-clicked? #f))) (set! ignore-clicked? #f)))
(define/public (get-selection) (define/public (get-selection)
(gtk_combo_box_get_active gtk)) (gtk_combo_box_get_active gtk))
(define/public (number) count) (define/public (number) count)
(define/public (clear) (define/public (clear)
(atomically (atomically
(set! ignore-clicked? #t) (set! ignore-clicked? #t)
@ -88,6 +91,7 @@
(gtk_combo_box_remove_text gtk 0)) (gtk_combo_box_remove_text gtk 0))
(set! count 0) (set! count 0)
(set! ignore-clicked? #f))) (set! ignore-clicked? #f)))
(public [-append append]) (public [-append append])
(define (-append l) (define (-append l)
(atomically (atomically
@ -96,5 +100,7 @@
(gtk_combo_box_append_text gtk l) (gtk_combo_box_append_text gtk l)
(when (= count 1) (when (= count 1)
(set-selection 0)) (set-selection 0))
(set! ignore-clicked? #f)))) (set! ignore-clicked? #f)))
(define/public (delete i)
(gtk_combo_box_remove_text gtk i)))

View File

@ -102,13 +102,13 @@
(SendMessageW hwnd CB_RESETCONTENT 0 0) (SendMessageW hwnd CB_RESETCONTENT 0 0)
(set! num-choices 0))) (set! num-choices 0)))
(public [append* append]) (public [append* append])
(define (append* str) (define (append* str)
(atomically (atomically
(SendMessageW/str hwnd CB_ADDSTRING 0 str) (SendMessageW/str hwnd CB_ADDSTRING 0 str)
(set! num-choices (add1 num-choices)) (set! num-choices (add1 num-choices))
(when (= 1 num-choices) (set-selection 0)))))) (when (= 1 num-choices) (set-selection 0))))
(define/public (delete i)
(set! num-choices (sub1 num-choices))
(void (SendMessageW hwnd CB_DELETESTRING i 0)))))

View File

@ -617,6 +617,7 @@
(define CB_SETCURSEL #x014E) (define CB_SETCURSEL #x014E)
(define CB_GETCURSEL #x0147) (define CB_GETCURSEL #x0147)
(define CB_ADDSTRING #x0143) (define CB_ADDSTRING #x0143)
(define CB_DELETESTRING #x0144)
(define CB_RESETCONTENT #x014B) (define CB_RESETCONTENT #x014B)
(define CBN_SELENDOK 9) (define CBN_SELENDOK 9)

View File

@ -113,7 +113,8 @@
(get-selection) (get-selection)
(number) (number)
(clear) (clear)
(append lbl)) (append lbl)
(delete i))
(stretchable-in-y #f) (stretchable-in-y #f)
(stretchable-in-x #f))) (stretchable-in-x #f)))

View File

@ -157,16 +157,6 @@ style. The new column is logically the last column, and it is initially
displayed as the last column.} displayed as the last column.}
@defmethod[(delete [n exact-nonnegative-integer?])
void?]{
Deletes the item indexed by @racket[n]. @|lbnumnote| If @racket[n] is equal
to or larger than the number of items in the control, @|MismatchExn|.
Selected items that are not deleted remain selected, and no other
items are selected.}
@defmethod[(delete-column [n exact-nonnegative-integer?]) @defmethod[(delete-column [n exact-nonnegative-integer?])
void?]{ void?]{

View File

@ -36,11 +36,22 @@ Removes all user-selectable items from the control.
} }
@defmethod[(delete [n exact-nonnegative-integer?])
void?]{
Deletes the item indexed by @racket[n] (where items are indexed
from @racket[0]). If @racket[n] is equal
to or larger than the number of items in the control, @|MismatchExn|.
Selected items that are not deleted remain selected, and no other
items are selected.}
@defmethod[(find-string [s string?]) @defmethod[(find-string [s string?])
(or/c exact-nonnegative-integer? #f)]{ (or/c exact-nonnegative-integer? #f)]{
Finds a user-selectable item matching the given string. If no matching Finds a user-selectable item matching the given string. If no matching
choice is found, @racket[#f] is returned, otherwise the index of the choice is found, @racket[#f] is returned, otherwise the index of the
matching choice is returned (items are indexed from @racket[0]). matching choice is returned (where items are indexed from @racket[0]).
} }
@ -53,7 +64,7 @@ Returns the number of user-selectable items in the control (which is
@defmethod[(get-selection) @defmethod[(get-selection)
(or/c exact-nonnegative-integer? #f)]{ (or/c exact-nonnegative-integer? #f)]{
Returns the index of the currently selected item (items are indexed Returns the index of the currently selected item (where items are indexed
from @racket[0]). If the choice item currently contains no choices or no from @racket[0]). If the choice item currently contains no choices or no
selections, @racket[#f] is returned. If multiple selections are selections, @racket[#f] is returned. If multiple selections are
allowed and multiple items are selected, the index of the first allowed and multiple items are selected, the index of the first
@ -64,7 +75,7 @@ Returns the index of the currently selected item (items are indexed
@defmethod[(get-string [n exact-nonnegative-integer?]) @defmethod[(get-string [n exact-nonnegative-integer?])
(and/c immutable? label-string?)]{ (and/c immutable? label-string?)]{
Returns the item for the given index (items are indexed from Returns the item for the given index (where items are indexed from
@racket[0]). If the provided index is larger than the greatest index in @racket[0]). If the provided index is larger than the greatest index in
the list control, @|MismatchExn|. the list control, @|MismatchExn|.
@ -81,7 +92,7 @@ Returns the currently selected item. If the control currently
@defmethod[(set-selection [n exact-nonnegative-integer?]) @defmethod[(set-selection [n exact-nonnegative-integer?])
void?]{ void?]{
Selects the item specified by the given index (items are indexed from Selects the item specified by the given index (where items are indexed from
@racket[0]). If the given index larger than the greatest index in the @racket[0]). If the given index larger than the greatest index in the
list control, @|MismatchExn|. list control, @|MismatchExn|.

View File

@ -1556,13 +1556,11 @@
(when (<= 0 p (sub1 (length actual-content))) (when (<= 0 p (sub1 (length actual-content)))
(set! actual-content (gone actual-content p)) (set! actual-content (gone actual-content p))
(set! actual-user-data (gone actual-user-data p)))) (set! actual-user-data (gone actual-user-data p))))
(define db (if list? (define db (make-object button%
(make-object button% "Delete" cdp
"Delete" cdp (lambda (b e)
(lambda (b e) (let ([p (send c get-selection)])
(let ([p (send c get-selection)]) (delete p)))))
(delete p))))
null))
(define dab (if list? (define dab (if list?
(make-object button% (make-object button%
"Delete Above" cdp "Delete Above" cdp