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)
(check-label-string '(method list-control<%> 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)
(set! content (append content (list i))))]
[-set-list-string (lambda (i s)
@ -843,10 +846,6 @@
(set! column-labels (append column-labels (list 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-label-font (lambda () (send wx get-label-font))]
[get-selections (entry-point (lambda () (send wx get-selections)))]

View File

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

View File

@ -78,9 +78,12 @@
(set! ignore-clicked? #t)
(gtk_combo_box_set_active gtk i)
(set! ignore-clicked? #f)))
(define/public (get-selection)
(gtk_combo_box_get_active gtk))
(define/public (number) count)
(define/public (clear)
(atomically
(set! ignore-clicked? #t)
@ -88,6 +91,7 @@
(gtk_combo_box_remove_text gtk 0))
(set! count 0)
(set! ignore-clicked? #f)))
(public [-append append])
(define (-append l)
(atomically
@ -96,5 +100,7 @@
(gtk_combo_box_append_text gtk l)
(when (= count 1)
(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)
(set! num-choices 0)))
(public [append* append])
(define (append* str)
(atomically
(SendMessageW/str hwnd CB_ADDSTRING 0 str)
(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_GETCURSEL #x0147)
(define CB_ADDSTRING #x0143)
(define CB_DELETESTRING #x0144)
(define CB_RESETCONTENT #x014B)
(define CBN_SELENDOK 9)

View File

@ -113,7 +113,8 @@
(get-selection)
(number)
(clear)
(append lbl))
(append lbl)
(delete i))
(stretchable-in-y #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.}
@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?])
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?])
(or/c exact-nonnegative-integer? #f)]{
Finds a user-selectable item matching the given string. If no matching
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)
(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
selections, @racket[#f] is returned. If multiple selections are
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?])
(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
the list control, @|MismatchExn|.
@ -81,7 +92,7 @@ Returns the currently selected item. If the control currently
@defmethod[(set-selection [n exact-nonnegative-integer?])
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
list control, @|MismatchExn|.

View File

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