! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: gadgets-presentations USING: arrays compiler gadgets gadgets-borders gadgets-buttons gadgets-labels gadgets-layouts gadgets-menus gadgets-outliner gadgets-panes gadgets-theme generic hashtables inference inspector io jedit kernel lists memory namespaces parser prettyprint sequences strings styles words ; SYMBOL: commands V{ } clone commands global set-hash : forget-command ( name -- ) commands [ [ second = not ] subset-with ] change ; : define-command ( class name quot -- ) over forget-command 3array commands get push ; : applicable ( object -- seq ) commands get [ first call ] subset-with ; : command-quot ( presented quot -- quot ) [ \ drop , curry , [ pane get pane-call ] % ] [ ] make ; TUPLE: command-button object ; : command-menu ( command-button -- ) command-button-object dup applicable [ [ third command-quot ] keep second swons ] map-with show-hand-menu ; C: command-button ( gadget object -- button ) [ set-command-button-object [ command-menu ] ] keep [ set-gadget-delegate ] keep dup menu-button-actions ; M: command-button gadget-help ( button -- string ) command-button-object dup word? [ synopsis ] [ summary ] if ; : init-commands ( style gadget -- gadget ) presented rot hash [ ] when* ; : style-font ( style -- font ) [ font swap hash [ "Monospaced" ] unless* ] keep [ font-style swap hash [ plain ] unless* ] keep font-size swap hash [ 12 ] unless* 3array ; : ( style text -- label )