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