InspectorListView.st
changeset 39 03af455029eb
parent 34 0f083a268b66
child 327 0040d47658c6
equal deleted inserted replaced
38:7b75ce74d9e1 39:03af455029eb
     1 "{ NameSpace: NewInspector }"
     1 "{ NameSpace: NewInspector }"
     2 
     2 
     3 SelectionInListView subclass:#InspectorListView
     3 SelectionInListView subclass:#InspectorListView
     4 	instanceVariableNames:'actionHolder listHolder includesSelf'
     4 	instanceVariableNames:'actionHolder inspectorList includesSelf'
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'Inspector'
     7 	category:'Inspector'
     8 !
     8 !
     9 
     9 
    10 !InspectorListView class methodsFor:'documentation'!
    10 !InspectorListView class methodsFor:'documentation'!
    11 
    11 
    12 examples
    12 examples
    13 "
    13 "
    14 
    14         open a list view on an instance
       
    15                                                                         [exBegin]
    15         |top slv a|
    16         |top slv a|
    16 
    17 
    17         a := OrderedCollection new.
    18         a := OrderedCollection new.
    18         a add:1.
    19         a add:1.
    19 
    20 
    25         slv origin:0.0@0.0 corner:1.0@1.0.
    26         slv origin:0.0@0.0 corner:1.0@1.0.
    26         slv := slv scrolledView.
    27         slv := slv scrolledView.
    27         slv inspect:top.
    28         slv inspect:top.
    28         slv action:[:el|Transcript showCR:(el printString)].
    29         slv action:[:el|Transcript showCR:(el printString)].
    29         top open
    30         top open
       
    31                                                                         [exEnd]
    30 "
    32 "
    31 ! !
    33 ! !
    32 
    34 
    33 !InspectorListView methodsFor:'accessing actions'!
    35 !InspectorListView methodsFor:'accessing'!
    34 
       
    35 action:aOneArgAction
       
    36     "set the single click action block.
       
    37      If non-nil, that one is evaluated on single click, passing the
       
    38      selected instance as argument
       
    39     "
       
    40     actionHolder := aOneArgAction
       
    41 ! !
       
    42 
       
    43 !InspectorListView methodsFor:'accessing attributes'!
       
    44 
       
    45 includesSelf
       
    46     ^ includesSelf
       
    47 !
       
    48 
    36 
    49 includesSelf:aBool
    37 includesSelf:aBool
    50     includesSelf := aBool
    38     includesSelf := aBool
    51 !
    39 !
    52 
    40 
    53 inspectedObject
    41 list
    54     ^ listHolder inspectedObject
    42     ^ inspectorList
    55 !
    43 !
    56 
    44 
    57 isEmpty
    45 list:aList
    58     "returns true if view is empty
    46     "set the lists contents from another list
    59     "
    47     "
    60     ^ listHolder size == 0
    48     |list selNr|
    61 !
    49 
    62 
    50     aList notNil ifTrue:[inspectorList := aList list]
    63 listHolder
    51                 ifFalse:[inspectorList := InspectorList new].
    64     ^ listHolder
    52 
    65 !
    53     inspectorList includesSelf:includesSelf.
    66 
    54     super list:(inspectorList instanceNames).
    67 notEmpty
    55 !
    68     "returns true if view is empty
    56 
    69     "
    57 update
    70     ^ listHolder size ~~ 0
    58     "update the current list
    71 ! !
    59     "
    72 
    60     inspectorList update.
    73 !InspectorListView methodsFor:'accessing contents'!
    61     super list:(inspectorList instanceNames).
    74 
    62 
    75 updateFromList:aListHolder
    63 ! !
    76     "set the lists contents from a list
    64 
    77     "
    65 !InspectorListView methodsFor:'accessing actions'!
    78     listHolder := aListHolder.
    66 
    79     listHolder includesSelf:includesSelf.
    67 action:aOneArgAction
    80 
    68     "set the single click action block. If non-nil, that one is evaluated on single
    81     super list:(listHolder instanceNames).
    69      click, passing the selected instance as argument
    82     self setSelection:(listHolder selection).
    70     "
    83 
    71     actionHolder := aOneArgAction
    84 !
       
    85 
       
    86 updateFromView:aInspectorListView
       
    87     "update contents from other view
       
    88     "
       
    89     self updateFromList:(aInspectorListView listHolder)
       
    90 !
       
    91 
       
    92 updateList 
       
    93     "set the lists contents dependant on the object
       
    94     "
       
    95     self updateList:(listHolder inspectedObject) selection:selection.
       
    96 ! !
       
    97 
       
    98 !InspectorListView methodsFor:'actions'!
       
    99 
       
   100 accept:aText notifying:aView
       
   101     "on error #Error is returned otherwise the inspected object instance
       
   102     "
       
   103     |res|
       
   104 
       
   105     res := listHolder accept:aText notifying:aView.
       
   106 
       
   107     res ~~ #Error ifTrue:[
       
   108         super list:(listHolder instanceNames).
       
   109         self setSelection:(listHolder selection)
       
   110     ].
       
   111     ^ res
       
   112 !
       
   113 
       
   114 doIt:aCode notifying:aView
       
   115     "on success the value returned from parser is returned otherwise #Error
       
   116     "
       
   117     |res|
       
   118 
       
   119     res := listHolder doIt:aCode notifying:aView.
       
   120 
       
   121     res ~~ #Error ifTrue:[
       
   122         super list:(listHolder instanceNames).
       
   123         self setSelection:(listHolder selection)
       
   124     ].
       
   125     ^ res
       
   126 
       
   127 !
       
   128 
       
   129 inspect:anObject
       
   130     "inspect an object
       
   131     "
       
   132     ^ self inspect:anObject selection:nil
       
   133 !
       
   134 
       
   135 inspect:anObject selection:aNumber
       
   136     "inspect an object and set the selection
       
   137     "
       
   138     aNumber notNil ifTrue:[
       
   139         selection := aNumber
       
   140     ] ifFalse:[
       
   141         (listHolder inspectedObject) ~~ anObject ifTrue:[
       
   142             selection := nil
       
   143         ]
       
   144     ].
       
   145     self updateList:anObject selection:selection
       
   146 ! !
    72 ! !
   147 
    73 
   148 !InspectorListView methodsFor:'drawing'!
    74 !InspectorListView methodsFor:'drawing'!
   149 
    75 
   150 drawVisibleLineSelected:visLineNr with:fg and:bg
    76 drawVisibleLineSelected:visLineNr with:fg and:bg
   151     "redraw a single line as selected."
    77     "redraw a single line as selected.
   152 
    78     "
   153     |nr| 
    79     |nr| 
   154 
    80 
   155     (nr := self visibleLineToListLine:visLineNr) notNil ifTrue:[
    81     (nr := self visibleLineToListLine:visLineNr) notNil ifTrue:[
   156         ^ self drawVisibleLine:visLineNr with:fg and:bg.
    82         ^ self drawVisibleLine:visLineNr with:fg and:bg.
   157     ].
    83     ].
   158     ^ super drawVisibleLine:visLineNr with:fg and:bg
    84     ^ super drawVisibleLine:visLineNr with:fg and:bg
   159 
    85 
   160 !
    86 !
   161 
    87 
   162 redrawArrowVisibleLine:visLineNr
    88 redrawArrowVisibleLine:visLineNr
   163     "draw a right arrow for visible line"
    89     "draw a right arrow for visible line
   164 
    90     "
   165     |nr|
    91     |nr|
   166 
    92 
   167     nr := self visibleLineToListLine:visLineNr.
    93     nr := self visibleLineToListLine:visLineNr.
   168 
    94 
   169     (listHolder instanceTypeAt:nr) == #directory ifTrue:[
    95     (inspectorList instanceTypeAt:nr) == #directory ifTrue:[
   170         self drawRightArrowInVisibleLine:visLineNr
    96         self drawRightArrowInVisibleLine:visLineNr
   171     ]
    97     ]
   172 
    98 
   173 
    99 
   174 !
   100 !
   189     super redrawVisibleLine:visLineNr.
   115     super redrawVisibleLine:visLineNr.
   190     self  redrawArrowVisibleLine:visLineNr.
   116     self  redrawArrowVisibleLine:visLineNr.
   191 !
   117 !
   192 
   118 
   193 visibleLineNeedsSpecialCare:visLineNr
   119 visibleLineNeedsSpecialCare:visLineNr
       
   120     "returns true if the visible line needs special care
       
   121     "
   194     |nr|
   122     |nr|
   195 
   123 
   196     (listHolder instanceTypeAt:nr) == #directory ifTrue:[
   124     (inspectorList instanceTypeAt:nr) == #directory ifTrue:[
   197         ^ true
   125         ^ true
   198     ].
   126     ].
   199     ^ super visibleLineNeedsSpecialCare:visLineNr
   127     ^ super visibleLineNeedsSpecialCare:visLineNr
   200 
   128 
   201 !
   129 !
   210 ! !
   138 ! !
   211 
   139 
   212 !InspectorListView methodsFor:'event handling'!
   140 !InspectorListView methodsFor:'event handling'!
   213 
   141 
   214 sizeChanged:how
   142 sizeChanged:how
   215     "redraw marks"
   143     "redraw marks
   216 
   144     "
   217     super sizeChanged:how.
   145     super sizeChanged:how.
   218     shown ifTrue:[self invalidate]
   146     shown ifTrue:[self invalidate]
   219 
   147 
   220 ! !
   148 ! !
   221 
   149 
   227     super initialize.
   155     super initialize.
   228 
   156 
   229     ignoreReselect := false.
   157     ignoreReselect := false.
   230     includesSelf   := false.
   158     includesSelf   := false.
   231     actionHolder   := [:el|].
   159     actionHolder   := [:el|].
   232     listHolder     := InspectorList for:nil.
   160     inspectorList  := InspectorList new.
   233 
   161 
   234     actionBlock := [:dummy|
   162     actionBlock := [:dummy|
   235         self setSelection:selection.
   163         self setSelection:selection.
   236         actionHolder value:(self selectedInstanceVar)
   164         actionHolder value:(self selectedInstanceVar)
   237     ].
   165     ].
   238 ! !
   166 ! !
   239 
   167 
   240 !InspectorListView methodsFor:'private'!
   168 !InspectorListView methodsFor:'private'!
   241 
   169 
   242 updateList:inspObject selection:aSelection
   170 doesNotUnderstand:aMessage
   243     "set the lists contents dependant on the object
   171     "forward a message to the inspectorList
   244     "
   172     "
   245     listHolder := InspectorList for:inspObject.
   173     (inspectorList respondsTo:(aMessage selector)) ifTrue:[
   246     listHolder includesSelf:includesSelf.
   174         ^ aMessage sendTo:inspectorList
   247     super list:(listHolder instanceNames).
   175     ].
   248 
   176     ^ super doesNotUnderstand:aMessage
   249     aSelection notNil ifTrue:[
   177 
   250         self setSelection:aSelection
   178 
   251     ] ifFalse:[
   179 !
   252         includesSelf ifTrue:[
   180 
   253             self setSelection:1
   181 list:aCollection keepSelection:aBoolean
   254         ]
   182     "set the list - redefined, since setting the list implies unselecting
   255     ]
   183      and clearing attributes."
       
   184 
       
   185     |oldSelection|
       
   186 
       
   187     "somewhat of a kludge: if selection is first line,
       
   188      we have to remove the highlight frame by hand here"
       
   189 
       
   190     (shown and:[hilightLevel ~~ 0]) ifTrue:[
       
   191         selection == firstLineShown ifTrue:[
       
   192            self paint:bgColor.
       
   193            self fillRectangleX:margin y:margin
       
   194                           width:(width - (margin * 2)) 
       
   195                          height:(hilightLevel abs).
       
   196         ].
       
   197     ].
       
   198     listAttributes := nil.
       
   199     super list:aCollection expandTabs:false.
       
   200     super setSelection:(inspectorList selection).
       
   201 
       
   202 
       
   203 
       
   204 
   256 ! !
   205 ! !
   257 
   206 
   258 !InspectorListView methodsFor:'selections'!
   207 !InspectorListView methodsFor:'selections'!
   259 
       
   260 selectedInstanceName
       
   261     "returns the name assigned to the selected instance or nil
       
   262     "
       
   263     ^ listHolder instanceNameAt:selection
       
   264 
       
   265 !
       
   266 
       
   267 selectedInstanceType
       
   268     "returns the type of the selected instance or nil
       
   269      known types are: #directory #normal or:#self
       
   270     "
       
   271     ^ listHolder instanceTypeAt:selection
       
   272 !
       
   273 
       
   274 selectedInstanceVar
       
   275     "returns the value assigned to the selected instance or nil
       
   276     "
       
   277     ^ listHolder instanceVarAt:selection
       
   278 
       
   279 !
       
   280 
   208 
   281 setSelection:aNumberOrNil
   209 setSelection:aNumberOrNil
   282     "select line, aNumber or deselect if argument is nil
   210     "select line, aNumber or deselect if argument is nil
   283     "
   211     "
   284     |type|
   212     |oldSize|
   285 
   213 
   286     aNumberOrNil notNil ifTrue:[
   214     oldSize := inspectorList size.
   287         type := listHolder instanceTypeAt:aNumberOrNil.
   215     inspectorList setSelection:aNumberOrNil.
   288         listHolder selection:aNumberOrNil.
   216     oldSize == inspectorList size ifTrue:[super setSelection:(inspectorList selection)]
   289 
   217                                  ifFalse:[super list:(inspectorList instanceNames)].
   290         type == #grow ifTrue:[
   218 ! !
   291             super list:(listHolder instanceNames)
   219 
   292         ]
   220 !InspectorListView methodsFor:'user interaction'!
   293     ].
   221 
   294     super setSelection:aNumberOrNil
   222 accept:aText notifying:aView
   295 
   223     "evaluating aText on the selected instance var; if an error occurs #Error
       
   224      is returned otherwise the inspected object instance. On success the list
       
   225      will be updated.
       
   226     "
       
   227     |res|
       
   228 
       
   229     res := inspectorList accept:aText notifying:aView.
       
   230 
       
   231     res ~~ #Error ifTrue:[
       
   232         super list:(inspectorList instanceNames)
       
   233     ].
       
   234     ^ res
       
   235 !
       
   236 
       
   237 doIt:aCode notifying:aView
       
   238     "evaluating aCode on the selected instance var; if an error occurs #Error
       
   239      is returned otherwise the result returned from the evaluator. On success
       
   240      the list will be updated.
       
   241     "
       
   242     |res|
       
   243 
       
   244     res := inspectorList doIt:aCode notifying:aView.
       
   245 
       
   246     res ~~ #Error ifTrue:[
       
   247         super list:(inspectorList instanceNames)
       
   248     ].
       
   249     ^ res
       
   250 
       
   251 !
       
   252 
       
   253 inspect:anObject
       
   254     "inspect a new instance; update contents
       
   255     "
       
   256     (inspectorList inspectedObject) == anObject ifTrue:[
       
   257         ^ self update
       
   258     ].
       
   259     inspectorList := InspectorList for:anObject.
       
   260     inspectorList includesSelf:includesSelf.
       
   261 
       
   262     super list:(inspectorList instanceNames).
   296 ! !
   263 ! !
   297 
   264 
   298 !InspectorListView class methodsFor:'documentation'!
   265 !InspectorListView class methodsFor:'documentation'!
   299 
   266 
   300 version
   267 version