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