Skip to content

Commit

Permalink
FranzCross,mixin: select item on right click of mix-context-event
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Oct 13, 2023
1 parent 92ee3e1 commit f11ccb1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
23 changes: 14 additions & 9 deletions FranzCross/config-table.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
[@pending null])
(define/obs @buttons-enabled?
(@pending . ~> . (compose1 not null?)))
(define/obs @entries
(let-observable ([configs @configs]
[revealed @revealed-names])
(for/vector ([c (in-list configs)])
(if (and (ResourceConfig-is-sensitive c)
(not (hash-has-key? revealed (ResourceConfig-name c))))
(set-ResourceConfig-value c "********")
c))))
(define (push-pending entry)
(update-observable [configs @configs]
(for/list ([c (in-list configs)])
Expand Down Expand Up @@ -62,17 +70,14 @@
(if (ResourceConfig-is-default c)
"yes"
"no")))
(let-observable ([configs @configs]
[revealed @revealed-names])
(for/vector ([c (in-list configs)])
(if (and (ResourceConfig-is-sensitive c)
(not (hash-has-key? revealed (ResourceConfig-name c))))
(set-ResourceConfig-value c "********")
c)))
@entries
#:mixin
(mix-context-event
(lambda (event)
(define entry ^@selection)
(lambda (event maybe-index)
(when maybe-index
(@selection:= (vector-ref (obs-peek @entries) maybe-index)))
(define entry
^@selection)
(when entry
(define name (ResourceConfig-name entry))
(render-popup-menu*
Expand Down
12 changes: 9 additions & 3 deletions FranzCross/group-detail.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
[#f (spacer)]
[`(#f) (text "No committed offsets.")]
[`(,topic . ,topics)
(define entries
(list->vector
(GroupTopic-partitions topic)))
(vpanel
#:alignment '(left top)
(hpanel
Expand Down Expand Up @@ -138,7 +141,7 @@
(3 150)
(4 150)
(5 150))
(list->vector (GroupTopic-partitions topic))
entries
#:entry->row
(lambda (p)
(vector
Expand All @@ -151,8 +154,11 @@
(~optional-str (GroupPartitionOffset-client-host p))))
#:mixin
(mix-context-event
(lambda (event)
(define poffset ^@poffset)
(lambda (event maybe-index)
(when maybe-index
(@poffset:= (vector-ref entries maybe-index)))
(define poffset
^@poffset)
(when poffset
(render-popup-menu*
(get-parent-renderer)
Expand Down
16 changes: 15 additions & 1 deletion FranzCross/mixin.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,23 @@
(define/override (on-subwindow-event receiver event)
(case (send event get-event-type)
[(right-down)
(define maybe-item-index
(cond
[(is-a? receiver gui:list-box%)
(define item-height
(quotient
(send receiver get-height)
(send receiver number-of-visible-items)))
(define item-index
(let ([index (quotient (send event get-y) item-height)])
(and (< index (send receiver get-number)) index)))
(begin0 item-index
(when item-index
(send receiver select item-index #t)))]
[else #f]))
(make-mouse-event-positions-absolute receiver event)
(begin0 #t
(proc event))]
(proc event maybe-item-index))]
[else #f]))))

(define (mix-initial-focus %)
Expand Down

0 comments on commit f11ccb1

Please sign in to comment.