UIHelpTool.st
changeset 196 56f63eb42a34
parent 172 10e8e0510baa
child 204 8dcd7f22e4d1
equal deleted inserted replaced
195:350f95af5d9d 196:56f63eb42a34
   126               )
   126               )
   127           )
   127           )
   128       )
   128       )
   129 ! !
   129 ! !
   130 
   130 
       
   131 !UIHelpTool class methodsFor:'misc'!
       
   132 
       
   133 applicationClassAssociatedWith:aClass
       
   134     "get application class keeping the associated help text or nil
       
   135     "
       
   136     |cls|
       
   137 
       
   138     aClass notNil ifTrue:[
       
   139         aClass isBehavior ifFalse:[cls := Smalltalk at:aClass asSymbol]
       
   140                            ifTrue:[cls := aClass].
       
   141 
       
   142         (cls notNil and:[cls includesBehavior:UISpecification]) ifTrue:[
       
   143             ^ UISpecificationTool
       
   144         ]
       
   145     ].
       
   146   ^ cls
       
   147 
       
   148 ! !
       
   149 
   131 !UIHelpTool methodsFor:'accessing'!
   150 !UIHelpTool methodsFor:'accessing'!
   132 
   151 
   133 dictionary
   152 dictionary
   134     "return the value of the instance variable 'dictionary' (automatically generated)"
   153     "return the value of the instance variable 'dictionary' (automatically generated)"
   135 
   154 
   141     (dictionary := aDictionary) notNil ifTrue:[
   160     (dictionary := aDictionary) notNil ifTrue:[
   142         list := dictionary keys asOrderedCollection
   161         list := dictionary keys asOrderedCollection
   143     ] ifFalse:[
   162     ] ifFalse:[
   144         list := nil
   163         list := nil
   145     ].
   164     ].
       
   165 !
       
   166 
       
   167 helpSpecFrom:aClass
       
   168     "read help text from an application associated with the class
       
   169     "
       
   170     |help cls|
       
   171 
       
   172     cls := self class applicationClassAssociatedWith:aClass.
       
   173 
       
   174     (cls respondsTo:#helpSpec) ifTrue:[
       
   175         help := cls helpSpec
       
   176     ].
       
   177     self dictionary:help
   146 !
   178 !
   147 
   179 
   148 key
   180 key
   149     "get the key from the edit field as symbol or nil
   181     "get the key from the edit field as symbol or nil
   150     "
   182     "
   198     ].
   230     ].
   199 
   231 
   200     model notNil ifTrue:[
   232     model notNil ifTrue:[
   201         model value:key
   233         model value:key
   202     ]
   234     ]
       
   235 !
       
   236 
       
   237 installHelpSpecInto:aClass
       
   238     "install help text
       
   239     "
       
   240     |cls src|
       
   241 
       
   242     cls := self class applicationClassAssociatedWith:aClass.
       
   243 
       
   244     cls isNil ifTrue:[
       
   245         ^ self information:'no application class defined'.
       
   246     ].
       
   247     dictionary isEmpty ifTrue:[
       
   248         ^ self information:'no help text defined'
       
   249     ].
       
   250     src  := '' writeStream.
       
   251 
       
   252     src nextPutAll:
       
   253 
       
   254 'helpSpec
       
   255     "return a dictionary filled with helpKey -> helptext associations.
       
   256      These are used by the activeHelp tool.
       
   257     "
       
   258   ^ super helpSpec addPairsFrom:#(
       
   259 
       
   260 '.
       
   261 
       
   262     dictionary keysAndValuesDo:[:key :txt|
       
   263         |t|
       
   264         src nextPutLine:key storeString.
       
   265 
       
   266         t := txt asString.
       
   267         (t endsWith:Character cr) ifTrue:[
       
   268             t := t copyWithoutLast:1
       
   269         ].
       
   270         src nextPutLine:t storeString; cr.
       
   271     ].
       
   272     src nextPutLine:')'.
       
   273 
       
   274     Compiler compile:(src contents)
       
   275             forClass:cls class 
       
   276           inCategory:'help specs'
       
   277 
   203 ! !
   278 ! !
   204 
   279 
   205 !UIHelpTool methodsFor:'aspects'!
   280 !UIHelpTool methodsFor:'aspects'!
   206 
   281 
   207 listChannel
   282 listChannel
   209 
   284 
   210     |holder|
   285     |holder|
   211 
   286 
   212     (holder := builder bindingAt:#listChannel) isNil ifTrue:[
   287     (holder := builder bindingAt:#listChannel) isNil ifTrue:[
   213         builder aspectAt:#listChannel put:(holder :=  ValueHolder new).
   288         builder aspectAt:#listChannel put:(holder :=  ValueHolder new).
   214         holder value:list
   289         holder value:list.
   215     ].
   290     ].
   216     ^ holder
   291     ^ holder
   217 !
   292 !
   218 
   293 
   219 textChannel
   294 textChannel