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