| 
									
										
										
										
											2008-07-11 01:01:22 -04:00
										 |  |  | ! Copyright (C) 2006, 2008 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  | USING: accessors arrays definitions kernel sequences strings | 
					
						
							| 
									
										
										
										
											2012-07-19 12:50:09 -04:00
										 |  |  | math assocs words generic make quotations splitting | 
					
						
							|  |  |  | ui.gestures unicode.case unicode.categories tr fry ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | IN: ui.commands | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: +nullary+ | 
					
						
							|  |  |  | SYMBOL: +listener+ | 
					
						
							|  |  |  | SYMBOL: +description+ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-26 19:23:19 -04:00
										 |  |  | PREDICATE: listener-command < word +listener+ word-prop ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | GENERIC: invoke-command ( target command -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: command-name ( command -- str )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-11 01:01:22 -04:00
										 |  |  | TUPLE: command-map blurb commands ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | GENERIC: command-description ( command -- str/f )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: command-word ( command -- word )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : <command-map> ( blurb commands -- command-map )
 | 
					
						
							| 
									
										
										
										
											2008-07-11 01:01:22 -04:00
										 |  |  |     { } like \ command-map boa ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : commands ( class -- hash )
 | 
					
						
							|  |  |  |     dup "commands" word-prop [ ] [ | 
					
						
							|  |  |  |         H{ } clone [ "commands" set-word-prop ] keep
 | 
					
						
							|  |  |  |     ] ?if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-21 03:03:27 -04:00
										 |  |  | : get-command-at ( group class -- command-map )
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     commands at ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : command-gestures ( class -- hash )
 | 
					
						
							|  |  |  |     commands values [ | 
					
						
							|  |  |  |         [ | 
					
						
							| 
									
										
										
										
											2008-07-11 01:01:22 -04:00
										 |  |  |             commands>> | 
					
						
							| 
									
										
										
										
											2012-08-24 01:36:10 -04:00
										 |  |  |             sift-keys
 | 
					
						
							| 
									
										
										
										
											2012-07-19 12:50:09 -04:00
										 |  |  |             [ '[ _ invoke-command ] swap ,, ] assoc-each
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |         ] each
 | 
					
						
							| 
									
										
										
										
											2012-07-19 12:50:09 -04:00
										 |  |  |     ] H{ } make ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : update-gestures ( class -- )
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:46:01 -04:00
										 |  |  |     dup command-gestures set-gestures ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : define-command-map ( class group blurb pairs -- )
 | 
					
						
							|  |  |  |     <command-map> | 
					
						
							|  |  |  |     swap pick commands set-at
 | 
					
						
							|  |  |  |     update-gestures ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 20:43:46 -04:00
										 |  |  | TR: convert-command-name "-" " " ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | : (command-name) ( string -- newstring )
 | 
					
						
							| 
									
										
										
										
											2008-07-09 20:43:46 -04:00
										 |  |  |     convert-command-name >title ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: word command-name ( word -- str )
 | 
					
						
							| 
									
										
										
										
											2008-06-28 03:36:20 -04:00
										 |  |  |     name>>  | 
					
						
							| 
									
										
										
										
											2009-01-31 00:52:02 -05:00
										 |  |  |     "com-" ?head drop "." ?tail drop
 | 
					
						
							| 
									
										
										
										
											2008-04-26 03:01:43 -04:00
										 |  |  |     dup first Letter? [ rest ] unless
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     (command-name) ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: word command-description ( word -- str )
 | 
					
						
							|  |  |  |     +description+ word-prop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : default-flags ( -- assoc )
 | 
					
						
							|  |  |  |     H{ { +nullary+ f } { +listener+ f } { +description+ f } } ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : define-command ( word hash -- )
 | 
					
						
							| 
									
										
										
										
											2010-02-03 08:55:00 -05:00
										 |  |  |     default-flags swap assoc-union
 | 
					
						
							|  |  |  |     '[ _ assoc-union ] change-props drop ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : command-quot ( target command -- quot )
 | 
					
						
							| 
									
										
										
										
											2009-02-21 17:42:57 -05:00
										 |  |  |     [ 1quotation ] [ +nullary+ word-prop ] bi
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  |     [ nip ] [ curry ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | M: word invoke-command ( target command -- )
 | 
					
						
							| 
									
										
										
										
											2009-02-09 01:49:48 -05:00
										 |  |  |     command-quot call( -- ) ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: word command-word ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-18 20:46:01 -04:00
										 |  |  | M: f invoke-command ( target command -- ) 2drop ;
 |