]> gitweb.factorcode.org Git - factor.git/commitdiff
better presentations in UI
authorSlava Pestov <slava@factorcode.org>
Wed, 6 Jul 2005 07:29:42 +0000 (07:29 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 6 Jul 2005 07:29:42 +0000 (07:29 +0000)
library/styles.factor
library/syntax/prettyprint.factor
library/tools/inspector.factor
library/tools/jedit-wire.factor
library/ui/frames.factor
library/ui/layouts.factor
library/ui/menus.factor
library/ui/panes.factor
library/ui/presentations.factor
library/ui/splitters.factor

index a26699b340d1bbb19ceeeb44102c69ab4402cd31..d24f0b561dc1c9f5361b95e8468b6b3a7ae74c2c 100644 (file)
@@ -28,3 +28,5 @@ SYMBOL: plain
 SYMBOL: bold
 SYMBOL: italic
 SYMBOL: bold-italic
+
+SYMBOL: presented
index 683316f761ac9b10754bade60f5f82e25f9cbf2c..715c3d835e8b402e8775f9d75a351297743f6e53 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2003, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: prettyprint
-USING: alien errors generic hashtables kernel lists math
-matrices memory namespaces parser presentation sequences io
-strings unparser vectors words ;
+USING: alien errors generic hashtables io kernel lists math
+matrices memory namespaces parser presentation sequences strings
+styles unparser vectors words ;
 
 SYMBOL: prettyprint-limit
 SYMBOL: one-line
@@ -15,43 +15,17 @@ GENERIC: prettyprint* ( indent obj -- indent )
 M: object prettyprint* ( indent obj -- indent )
     unparse write ;
 
-: word-link ( word -- link )
-    [
-        dup word-name unparse ,
-        " [ " ,
-        word-vocabulary unparse ,
-        " ] search" ,
-    ] make-string ;
-
-: word-actions ( -- list )
-    [
-        [[ "See"        "see"          ]]
-        [[ "Push"       ""             ]]
-        [[ "Execute"    "execute"      ]]
-        [[ "jEdit"      "jedit"        ]]
-        [[ "Usages"     "usages ."     ]]
-        [[ "Implements" "implements ." ]]
-    ] ;
-
-: browser-attrs ( word -- style )
+: word-attrs ( word -- style )
     #! Return the style values for the HTML word browser
-    dup word-vocabulary [ 
-        swap word-name "word" swons 
-        swap "vocab" swons 
-        2list
-    ] [
-        drop [ ]  
-    ] ifte* ;
-
-: word-attrs ( word -- attrs )
-    #! Words without a vocabulary do not get a link or an action
-    #! popup.
-    dup word-vocabulary [
-         dup word-link word-actions <actions> "actions" swons unit
-         swap browser-attrs append
-    ] [
-        drop [ ]
-    ] ifte ;
+    [
+        presented over cons ,
+        dup word-vocabulary [ 
+            "word" over word-name cons ,
+            "vocab" swap word-vocabulary cons ,
+        ] [
+            drop
+        ] ifte
+    ] make-list ;
 
 : word. ( word -- ) dup word-name swap word-attrs write-attr ;
 
index 6976292a7cadb6004cade05a13f0484fb27ff443..1a6994a0cdb18364fd59760ed21668aa6c7b3189 100644 (file)
@@ -29,13 +29,6 @@ M: hashtable sheet hash>alist unzip 2list ;
     [ [ length ] map 0 [ max ] reduce ] keep
     [ swap CHAR: \s pad-right ] map-with ;
 
-: describe ( obj -- list )
-    sheet dup first length count swons
-    dup peek over first zip [ uncons set ] each
-    [ column ] map
-    seq-transpose
-    [ " " join ] map ;
-
 : (join) ( list glue -- )
     over [
         over car % >r cdr dup
@@ -48,6 +41,13 @@ M: hashtable sheet hash>alist unzip 2list ;
     #! The new sequence is of the same type as glue.
     [ [ (join) ] make-vector ] keep like ;
 
+: describe ( obj -- list )
+    sheet dup first length count swons
+    dup peek over first zip [ uncons set ] each
+    [ column ] map
+    seq-transpose
+    [ " | " join ] map ;
+
 : a/an ( noun -- str )
     first "aeiouAEIOU" contains? "an " "a " ? ;
 
@@ -82,6 +82,8 @@ M: hashtable sheet hash>alist unzip 2list ;
         "The word is a uniquely generated symbol." print
     ] ifte ;
 
+GENERIC: extra-banner ( obj -- )
+
 M: word extra-banner ( obj -- )
     dup vocab-banner swap class-banner ;
 
@@ -92,14 +94,16 @@ M: object extra-banner ( obj -- ) drop ;
     "You are looking at " write dup class unparse a/an.
     " object with the following printed representation:" print
     "  " write dup unparse print
+    "The object has been placed in the inspecting variable." print
     "It is located at address " write dup address >hex write
     " and takes up " write dup size unparse write
     " bytes of memory." print
     "This object is referenced from " write r> unparse write
     " other objects in the heap." print
-    extra-banner ;
+    extra-banner
+    "The object's slots, if any, are stored in integer variables," print
+    "numbered starting from 0." print ;
 
 : inspect ( obj -- )
-    dup inspect-banner
     dup inspecting set
-    describe [ print ] each ;
+    dup inspect-banner describe [ print ] each ;
index 1501f8aa4666c24726f5f1452d4cefdd5685b770..3ca441483db96c168b10faae2b49cc831cc1f777 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: jedit
 USING: generic kernel listener lists namespaces parser
-prettyprint sequences io strings words ;
+prettyprint sequences io strings words styles ;
 
 ! Wire protocol for jEdit to evaluate Factor code.
 ! Packets are of the form:
@@ -39,7 +39,7 @@ prettyprint sequences io strings words ;
 ! remaining -- input
 : jedit-write-attr ( str style -- )
     CHAR: w write
-    [ swap . "USE: styles" print . ] string-out
+    [ swap . "USE: styles" print [ car presented = not ] subset . ] string-out
     dup write-len write ;
 
 TUPLE: jedit-stream ;
index 47d1b5496e8d87ff5b63f4d214134915490395e9..aba0a72f0977e82a46d9d6de274eb7a42b91dd39 100644 (file)
@@ -45,6 +45,11 @@ C: frame ( -- frame )
 : add-h pref-size nip height [ + ] change ;
 : add-w pref-size drop width [ + ] change ;
 
+: with-pref-size ( quot -- )
+    [
+        0 width set 0 height set call width get height get
+    ] with-scope ; inline
+
 M: frame pref-dim ( glue -- dim )
     [
         dup frame-major [ max-w ] each
index 9a6193252a9a718c43689652fd914ea784b6e74b..9b7ebfa851ffcf7a3d64de85839b6a8954f3f183 100644 (file)
@@ -19,6 +19,8 @@ namespaces sdl sequences ;
         drop
     ] ifte ;
 
+TUPLE: pack align fill vector ;
+
 : pref-dims ( gadget -- list )
     gadget-children [ pref-dim ] map ;
 
@@ -57,8 +59,6 @@ namespaces sdl sequences ;
 : packed-layout ( gadget sizes -- )
     2dup packed-locs packed-dims ;
 
-TUPLE: pack align fill vector ;
-
 C: pack ( align fill vector -- pack )
     #! align: 0 left aligns, 1/2 center, 1 right.
     #! gap: between each child.
index 4315a81a16aebc905140493929ba773053bcbe62..0c98419a7afe6b8f41bec6887fe5e46089eefa26 100644 (file)
@@ -36,7 +36,7 @@ TUPLE: menu ;
 C: menu ( assoc -- gadget )
     #! Given an association list mapping labels to quotations.
     [ f line-border swap set-delegate ] keep
-    <line-pile> [ swap add-gadget ] 2keep
+    0 1 <pile> [ swap add-gadget ] 2keep
     rot assoc>menu dup menu-actions ;
 
 ! While a menu is open, clicking anywhere sends the click to
index 2fc02ce4601d135231e4c61bf8ab21a6000575ec..7b660ad37ae0bf050be5842b513ff03041f0b1a3 100644 (file)
@@ -29,9 +29,11 @@ TUPLE: pane output active current input continuation ;
 : pop-continuation ( pane -- quot )
     dup pane-continuation f rot set-pane-continuation ;
 
-: pane-eval ( line pane -- )
-    2dup stream-write "\n" over stream-write
-    pop-continuation in-thread drop ;
+: pane-eval ( string pane -- )
+    2dup stream-print pop-continuation in-thread drop ;
+
+: pane-call ( quot pane -- )
+    [ "(Structured input) " write dup . call ] with-stream* ;
 
 : pane-return ( pane -- )
     [
@@ -49,7 +51,7 @@ TUPLE: pane output active current input continuation ;
 
 C: pane ( -- pane )
     <line-pile> over set-delegate
-    <line-pile> <incremental> over add-output
+    <line-pile> ( <incremental> ) over add-output
     <line-shelf> over set-pane-current
     "" <editor> over set-pane-input
     dup init-active-line
@@ -60,10 +62,10 @@ M: pane focusable-child* ( pane -- editor )
     pane-input ;
 
 : pane-write-1 ( style text pane -- )
-    [ <presentation> ] keep pane-current add-incremental ;
+    [ <presentation> ] keep pane-current add-gadget ;
 
 : pane-terpri ( pane -- )
-    dup pane-current over pane-output add-incremental
+    dup pane-current over pane-output ( add-incremental ) add-gadget
     <line-shelf> over set-pane-current init-active-line ;
 
 : pane-write ( style pane list -- )
index 1a41b7b9c36c5846c258bd780b4c5e72f8ca5de0..ad0f7b98efd42d6beacb620916ec280d3f327a24 100644 (file)
@@ -1,23 +1,45 @@
 ! Copyright (C) 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: gadgets
-USING: hashtables io kernel lists namespaces parser prettyprint
-sequences ;
+USING: generic hashtables inspector io jedit kernel lists memory
+namespaces parser prettyprint sequences styles vectors words ;
+
+SYMBOL: commands
+
+global [ 100 <vector> commands set ] bind
+
+: define-command ( class name quot -- )
+    3list commands get push ;
+
+: applicable ( object -- )
+    commands get >list
+    [ car "predicate" word-prop call ] subset-with ;
 
 DEFER: pane-eval
 
-: actions-menu ( pane actions -- menu )
-    [ uncons rot [ pane-eval ] cons cons cons ] map-with <menu> ;
+: command-menu ( pane -- menu )
+    presented get dup applicable [
+        3dup third [
+            [ swap literal, % ] make-list , , \ pane-call ,
+        ] make-list >r second r> cons
+    ] map 2nip ;
 
-: init-actions ( gadget pane -- )
-    over "actions" paint-prop dup [
-        actions-menu [ show-menu ] cons button-gestures
-    ] [
-        3drop
-    ] ifte ;
+: init-commands ( gadget pane -- )
+    over presented paint-prop
+    [ [ command-menu <menu> show-menu ] cons button-gestures ]
+    [ 2drop ] ifte ;
 
 : <styled-label> ( style text -- label )
     <label> swap alist>hash over set-gadget-paint ;
 
 : <presentation> ( style text pane -- presentation )
-    >r <styled-label> dup r> init-actions ;
+    >r <styled-label> dup r> init-commands ;
+
+object "Prettyprint" [ prettyprint ] define-command
+object "Inspect" [ inspect ] define-command
+object "References" [ references inspect ] define-command
+
+\ word "See" [ see ] define-command
+\ word "Execute" [ execute ] define-command
+\ word "Usage" [ usage . ] define-command
+\ word "jEdit" [ jedit ] define-command
index 1785369ebf89a6abd38176173f81ce918e96bbe2..895cc8840ad6849a419ac4a0394ed9e01f4e57e7 100644 (file)
@@ -17,7 +17,7 @@ TUPLE: splitter split ;
 
 : divider-motion ( splitter -- )
     dup hand>split
-    over shape-dim { 1 1 1 } vmax v/ over orientation v.
+    over shape-dim { 1 1 1 } vmax v/ over pack-vector v.
     0 max 1 min over set-splitter-split relayout ;
 
 : divider-actions ( thumb -- )