NewInspectorListView.st
author Patrik Svestka <patrik.svestka@gmail.com>
Wed, 14 Nov 2018 12:07:51 +0100
branchjv
changeset 3630 5e718e0a754e
parent 2621 285fa261cbcb
child 3613 5b03d091c507
permissions -rw-r--r--
Issue #239: Fix all Smalltak/X source files to be in unicode (UTF8 without BOM) and prefixed by "{ Encoding: utf8 }" when any unicode character is present

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