UIHelpTool.st
changeset 148 785417b6955d
child 151 8768bf518383
equal deleted inserted replaced
147:060fc1ac8d82 148:785417b6955d
       
     1 ApplicationModel subclass:#UIHelpTool
       
     2 	instanceVariableNames:'dictionary list model'
       
     3 	classVariableNames:''
       
     4 	poolDictionaries:''
       
     5 	category:'Interface-UIPainter'
       
     6 !
       
     7 
       
     8 !UIHelpTool class methodsFor:'documentation'!
       
     9 
       
    10 documentation
       
    11 "
       
    12     used by the UIPainter to add help text to any component which will be shown
       
    13     during runing an application with enabled activeHelp mode.
       
    14 "
       
    15 ! !
       
    16 
       
    17 !UIHelpTool class methodsFor:'interface specs'!
       
    18 
       
    19 windowSpec
       
    20     "this window spec was automatically generated by the ST/X UIPainter"
       
    21 
       
    22     "do not manually edit this - the painter/builder may not be able to
       
    23      handle the specification if its corrupted."
       
    24 
       
    25     "
       
    26      UIPainter new openOnClass:ActiveHelpTool andSelector:#windowSpec
       
    27      ActiveHelpTool new openInterface:#windowSpec
       
    28     "
       
    29     "ActiveHelpTool open"
       
    30 
       
    31     <resource: #canvas>
       
    32 
       
    33     ^
       
    34      
       
    35        #(#FullSpec
       
    36           #'window:' 
       
    37            #(#WindowSpec
       
    38               #'name:' 'uIPainterView'
       
    39               #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
       
    40               #'label:' 'unnamed canvas'
       
    41               #'bounds:' #(#Rectangle 0 0 286 272)
       
    42           )
       
    43           #'component:' 
       
    44            #(#SpecCollection
       
    45               #'collection:' 
       
    46                #(
       
    47                  #(#TextEditorSpec
       
    48                     #'name:' 'textView'
       
    49                     #'layout:' #(#LayoutFrame 46 0 25 0.0 0 1.0 0 1.0)
       
    50                     #'model:' #textChannel
       
    51                     #'hasHorizontalScrollBar:' true
       
    52                     #'hasVerticalScrollBar:' true
       
    53                     #'miniScrollerHorizontal:' true
       
    54                     #'miniScrollerVertical:' true
       
    55                 )
       
    56                  #(#LabelSpec
       
    57                     #'name:' 'keyLabel'
       
    58                     #'layout:' #(#LayoutFrame 0 0.0 1 0.0 41 0 21 0)
       
    59                     #'label:' 'Key:'
       
    60                     #'adjust:' #left
       
    61                     #'resizeForLabel:' false
       
    62                 )
       
    63                  #(#ComboBoxSpec
       
    64                     #'name:' 'comboBox'
       
    65                     #'layout:' #(#LayoutFrame 46 0 1 0 0 1.0 21 0)
       
    66                     #'tabable:' true
       
    67                     #'comboList:' #listChannel
       
    68                 )
       
    69                  #(#LabelSpec
       
    70                     #'name:' 'textLabel'
       
    71                     #'layout:' #(#LayoutFrame 0 0.0 25 0.0 41 0 45 0)
       
    72                     #'label:' 'Text:'
       
    73                     #'adjust:' #left
       
    74                     #'resizeForLabel:' false
       
    75                 )
       
    76               )
       
    77           )
       
    78       )
       
    79 ! !
       
    80 
       
    81 !UIHelpTool methodsFor:'accessing'!
       
    82 
       
    83 key
       
    84     "get the key from the edit field as symbol or nil
       
    85     "
       
    86     |key|
       
    87 
       
    88     key := model value.
       
    89 
       
    90     (     key size ~~ 0
       
    91      and:[(key indexOfSeparatorStartingAt:1) == 0
       
    92       or:[(key := key withoutSeparators) notEmpty]]
       
    93     ) ifTrue:[
       
    94         ^ key asSymbol
       
    95     ].
       
    96   ^ nil
       
    97 !
       
    98 
       
    99 model:aKeyHolder
       
   100     "set the model on the edit field
       
   101     "
       
   102     model notNil ifTrue:[
       
   103         model removeDependent:self
       
   104     ].
       
   105     (model := aKeyHolder) notNil ifTrue:[
       
   106         model addDependent:self
       
   107     ].
       
   108     (builder componentAt:#comboBox) model:model.
       
   109 ! !
       
   110 
       
   111 !UIHelpTool methodsFor:'actions'!
       
   112 
       
   113 accept
       
   114     "accept the text
       
   115     "
       
   116     |key txt|
       
   117 
       
   118     key := self key.
       
   119     txt := self textChannel.
       
   120 
       
   121     key notNil ifTrue:[
       
   122         txt dependentsDo:[:edt| edt accept].
       
   123 
       
   124         (dictionary at:key ifAbsent:nil) isNil ifTrue:[
       
   125             list add:key.
       
   126             self listChannel value:list
       
   127         ].
       
   128         dictionary at:key put:(txt value)
       
   129     ] ifFalse:[
       
   130         key := nil.
       
   131         txt value:nil.
       
   132     ].
       
   133 
       
   134     model notNil ifTrue:[
       
   135         model value:key
       
   136     ]
       
   137 ! !
       
   138 
       
   139 !UIHelpTool methodsFor:'aspects'!
       
   140 
       
   141 listChannel
       
   142     "automatically generated by UIPainter ..."
       
   143 
       
   144     |holder|
       
   145 
       
   146     (holder := builder bindingAt:#listChannel) isNil ifTrue:[
       
   147         builder aspectAt:#listChannel put:(holder :=  ValueHolder new).
       
   148     ].
       
   149     ^ holder
       
   150 !
       
   151 
       
   152 textChannel
       
   153     "automatically generated by UIPainter ..."
       
   154 
       
   155     |holder|
       
   156 
       
   157     (holder := builder bindingAt:#textChannel) isNil ifTrue:[
       
   158         builder aspectAt:#textChannel put:(holder :=  ValueHolder new).
       
   159     ].
       
   160     ^ holder
       
   161 ! !
       
   162 
       
   163 !UIHelpTool methodsFor:'change & update'!
       
   164 
       
   165 update:something with:aParameter from:someObject
       
   166     "model might change
       
   167     "
       
   168     |text key|
       
   169 
       
   170     (key := self key) notNil ifTrue:[
       
   171         (text := dictionary at:key ifAbsent:nil) notNil ifTrue:[
       
   172             self textChannel value:text
       
   173         ]
       
   174     ]
       
   175 ! !
       
   176 
       
   177 !UIHelpTool methodsFor:'initialization'!
       
   178 
       
   179 initialize
       
   180     "setup instance attributes
       
   181     "
       
   182     super initialize.
       
   183     dictionary  := IdentityDictionary new.
       
   184     list        := OrderedCollection new.
       
   185 ! !
       
   186 
       
   187 !UIHelpTool class methodsFor:'documentation'!
       
   188 
       
   189 version
       
   190     ^ '$Header$'
       
   191 ! !