Clean up menu code

db4
Slava Pestov 2009-01-16 16:39:32 -06:00
parent 21f81ab57d
commit 0e1e92ba92
4 changed files with 26 additions and 16 deletions

View File

@ -34,5 +34,5 @@ IN: ui.gadgets.menus
: <operations-menu> ( target hook -- menu ) : <operations-menu> ( target hook -- menu )
over object-operations <commands-menu> ; over object-operations <commands-menu> ;
: show-operations-menu ( gadget target -- ) : show-operations-menu ( gadget target hook -- )
[ ] <operations-menu> show-menu ; <operations-menu> show-menu ;

View File

@ -35,12 +35,12 @@ M: presentation ungraft*
dup hand-gadget get-global child? [ dup hide-status ] when dup hand-gadget get-global child? [ dup hide-status ] when
call-next-method ; call-next-method ;
: show-operations-menu ( presentation -- ) : show-presentation-menu ( presentation -- )
[ ] [ object>> ] [ dup hook>> curry ] tri [ ] [ object>> ] [ dup hook>> curry ] tri
<operations-menu> show-menu ; show-operations-menu ;
presentation H{ presentation H{
{ T{ button-down f f 3 } [ show-operations-menu ] } { T{ button-down f f 3 } [ show-presentation-menu ] }
{ T{ mouse-leave } [ [ hide-status ] [ button-update ] bi ] } { T{ mouse-leave } [ [ hide-status ] [ button-update ] bi ] }
{ T{ mouse-enter } [ show-mouse-help ] } { T{ mouse-enter } [ show-mouse-help ] }
! Responding to motion too allows nested presentations to ! Responding to motion too allows nested presentations to

View File

@ -25,12 +25,21 @@ TUPLE: search-field < track field ;
TUPLE: search-table < track table field ; TUPLE: search-table < track table field ;
! We don't want to delegate all slots, just a few setters ! A protocol with customizable slots
PROTOCOL: table-protocol SLOT-PROTOCOL: table-protocol
renderer>> (>>renderer) renderer
filled-column>> (>>filled-column) filled-column
selected-value>> (>>selected-value) column-alignment
column-alignment>> (>>column-alignment) ; action
hook
font
text-color
selection-color
focus-border-color
mouse-color
column-line-color
selection-required?
selected-value ;
CONSULT: table-protocol search-table table>> ; CONSULT: table-protocol search-table table>> ;

View File

@ -17,7 +17,7 @@ M: trivial-renderer row-columns drop ;
M: object row-value drop ; M: object row-value drop ;
TUPLE: table < gadget TUPLE: table < gadget
renderer filled-column column-alignment action renderer filled-column column-alignment action hook
column-widths total-width column-widths total-width
font text-color selection-color focus-border-color font text-color selection-color focus-border-color
mouse-color column-line-color selection-required? mouse-color column-line-color selection-required?
@ -30,6 +30,7 @@ focused? ;
swap >>model swap >>model
trivial-renderer >>renderer trivial-renderer >>renderer
[ drop ] >>action [ drop ] >>action
[ ] >>hook
f <model> >>selected-value f <model> >>selected-value
sans-serif-font >>font sans-serif-font >>font
selection-color >>selection-color selection-color >>selection-color
@ -289,10 +290,10 @@ PRIVATE>
2bi 2bi
] [ hide-mouse-help ] if-mouse-row ; ] [ hide-mouse-help ] if-mouse-row ;
: table-operations-menu ( table -- ) : show-table-menu ( table -- )
[ [
[ nth-row drop ] keep [ renderer>> row-value ] keep tuck [ nth-row drop ] [ renderer>> row-value ] [ hook>> ] tri
swap show-operations-menu show-operations-menu
] [ drop ] if-mouse-row ; ] [ drop ] if-mouse-row ;
table H{ table H{
@ -300,7 +301,7 @@ table H{
{ T{ mouse-leave } [ hide-mouse-help ] } { T{ mouse-leave } [ hide-mouse-help ] }
{ T{ motion } [ show-mouse-help ] } { T{ motion } [ show-mouse-help ] }
{ T{ button-down } [ table-button-down ] } { T{ button-down } [ table-button-down ] }
{ T{ button-down f f 3 } [ table-operations-menu ] } { T{ button-down f f 3 } [ show-table-menu ] }
{ T{ button-up } [ table-button-up ] } { T{ button-up } [ table-button-up ] }
{ T{ gain-focus } [ t >>focused? drop ] } { T{ gain-focus } [ t >>focused? drop ] }
{ T{ lose-focus } [ f >>focused? drop ] } { T{ lose-focus } [ f >>focused? drop ] }