Tools__ViewTreeModel.st
author Claus Gittinger <cg@exept.de>
Wed, 21 Oct 2009 15:33:24 +0200
changeset 2656 491471c26771
parent 2457 04459d76932e
permissions -rw-r--r--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
     1
"{ Package: 'stx:libtool2' }"
eef25c370979 initial checkin
ca
parents:
diff changeset
     2
eef25c370979 initial checkin
ca
parents:
diff changeset
     3
"{ NameSpace: Tools }"
eef25c370979 initial checkin
ca
parents:
diff changeset
     4
eef25c370979 initial checkin
ca
parents:
diff changeset
     5
ValueModel subclass:#ViewTreeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
     6
	instanceVariableNames:'lockSema selectedSuperItems selection hiddenLevel listOfItems
eef25c370979 initial checkin
ca
parents:
diff changeset
     7
		inputEventAction mappedViewAction beforeSelectionChangedAction
2457
ca
parents: 2453
diff changeset
     8
		icons timedUpdateTask selectOnClickHolder testModeChannel
ca
parents: 2453
diff changeset
     9
		hasTargetWidgetChannel'
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
    10
	classVariableNames:''
eef25c370979 initial checkin
ca
parents:
diff changeset
    11
	poolDictionaries:''
eef25c370979 initial checkin
ca
parents:
diff changeset
    12
	category:'A-Views-Support'
eef25c370979 initial checkin
ca
parents:
diff changeset
    13
!
eef25c370979 initial checkin
ca
parents:
diff changeset
    14
eef25c370979 initial checkin
ca
parents:
diff changeset
    15
HierarchicalList subclass:#ItemList
2453
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
    16
	instanceVariableNames:'treeModel eventHook eventHookInitialized showWidgetNames'
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
    17
	classVariableNames:''
eef25c370979 initial checkin
ca
parents:
diff changeset
    18
	poolDictionaries:''
eef25c370979 initial checkin
ca
parents:
diff changeset
    19
	privateIn:ViewTreeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
    20
!
eef25c370979 initial checkin
ca
parents:
diff changeset
    21
eef25c370979 initial checkin
ca
parents:
diff changeset
    22
!ViewTreeModel class methodsFor:'documentation'!
eef25c370979 initial checkin
ca
parents:
diff changeset
    23
eef25c370979 initial checkin
ca
parents:
diff changeset
    24
documentation
eef25c370979 initial checkin
ca
parents:
diff changeset
    25
"
eef25c370979 initial checkin
ca
parents:
diff changeset
    26
    Instances of ViewTreeModel can be used as model on a View and all
eef25c370979 initial checkin
ca
parents:
diff changeset
    27
    it contained subviews for a HierarchicalListView.
eef25c370979 initial checkin
ca
parents:
diff changeset
    28
    The model keeps two values, the hierarchical representation of the views
eef25c370979 initial checkin
ca
parents:
diff changeset
    29
    and subviews (ViewTreeItems) and the selection, a list of selected ViewTreeItems's.
eef25c370979 initial checkin
ca
parents:
diff changeset
    30
    It shows the selected items highlighted.
eef25c370979 initial checkin
ca
parents:
diff changeset
    31
eef25c370979 initial checkin
ca
parents:
diff changeset
    32
eef25c370979 initial checkin
ca
parents:
diff changeset
    33
    [Instance variables:]
eef25c370979 initial checkin
ca
parents:
diff changeset
    34
        lockSema            <Semaphore>         lock selection notifications and redraws
eef25c370979 initial checkin
ca
parents:
diff changeset
    35
2457
ca
parents: 2453
diff changeset
    36
        testModeChannel     <ValueHolder>       true, than running in test mode.
ca
parents: 2453
diff changeset
    37
ca
parents: 2453
diff changeset
    38
        hasTargetWidgetChannel <ValueHolder>    true, than any target view is grapped
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
    39
eef25c370979 initial checkin
ca
parents:
diff changeset
    40
        selection           <Sequence or nil>   selected items or nil
eef25c370979 initial checkin
ca
parents:
diff changeset
    41
eef25c370979 initial checkin
ca
parents:
diff changeset
    42
        hiddenLevel         <Integer>           internal use; redrawing the selection
eef25c370979 initial checkin
ca
parents:
diff changeset
    43
                                                only is done if the counter is 0.
eef25c370979 initial checkin
ca
parents:
diff changeset
    44
eef25c370979 initial checkin
ca
parents:
diff changeset
    45
        listOfItems         <HierarchicalList>  hiearchical list build from existing items.
eef25c370979 initial checkin
ca
parents:
diff changeset
    46
eef25c370979 initial checkin
ca
parents:
diff changeset
    47
        selectedSuperItems  <Sequence>          list of selected super items; items selected
eef25c370979 initial checkin
ca
parents:
diff changeset
    48
                                                but not contained in another selected item.
eef25c370979 initial checkin
ca
parents:
diff changeset
    49
eef25c370979 initial checkin
ca
parents:
diff changeset
    50
        inputEventAction    <Action>            called for each InputEvent
eef25c370979 initial checkin
ca
parents:
diff changeset
    51
eef25c370979 initial checkin
ca
parents:
diff changeset
    52
        mappedViewAction    <Action>            called for a new mapped view which
eef25c370979 initial checkin
ca
parents:
diff changeset
    53
                                                can not be found in the current item list.
eef25c370979 initial checkin
ca
parents:
diff changeset
    54
eef25c370979 initial checkin
ca
parents:
diff changeset
    55
        beforeSelectionChangedAction <Action>   called before the selection changed
eef25c370979 initial checkin
ca
parents:
diff changeset
    56
eef25c370979 initial checkin
ca
parents:
diff changeset
    57
    [author:]
eef25c370979 initial checkin
ca
parents:
diff changeset
    58
        Claus Atzkern
eef25c370979 initial checkin
ca
parents:
diff changeset
    59
eef25c370979 initial checkin
ca
parents:
diff changeset
    60
    [see also:]
eef25c370979 initial checkin
ca
parents:
diff changeset
    61
        ViewTreeItem
eef25c370979 initial checkin
ca
parents:
diff changeset
    62
"
eef25c370979 initial checkin
ca
parents:
diff changeset
    63
!
eef25c370979 initial checkin
ca
parents:
diff changeset
    64
eef25c370979 initial checkin
ca
parents:
diff changeset
    65
examples
eef25c370979 initial checkin
ca
parents:
diff changeset
    66
"
eef25c370979 initial checkin
ca
parents:
diff changeset
    67
    example 1: pick any window and show views and contained views
eef25c370979 initial checkin
ca
parents:
diff changeset
    68
                                                                                [exBegin]
eef25c370979 initial checkin
ca
parents:
diff changeset
    69
    |top sel model panel|
eef25c370979 initial checkin
ca
parents:
diff changeset
    70
eef25c370979 initial checkin
ca
parents:
diff changeset
    71
    model := ViewTreeModel new.
eef25c370979 initial checkin
ca
parents:
diff changeset
    72
    top   := StandardSystemView new; extent:440@400.
eef25c370979 initial checkin
ca
parents:
diff changeset
    73
    sel   := ScrollableView for:HierarchicalListView miniScroller:true origin:0.0@0.0 corner:1.0@1.0 in:top.
eef25c370979 initial checkin
ca
parents:
diff changeset
    74
    sel bottomInset:24.
eef25c370979 initial checkin
ca
parents:
diff changeset
    75
eef25c370979 initial checkin
ca
parents:
diff changeset
    76
    panel := HorizontalPanelView origin:0.0@1.0 corner:1.0@1.0 in:top.
eef25c370979 initial checkin
ca
parents:
diff changeset
    77
    panel topInset:-24.
eef25c370979 initial checkin
ca
parents:
diff changeset
    78
    panel horizontalLayout:#fitSpace.
eef25c370979 initial checkin
ca
parents:
diff changeset
    79
eef25c370979 initial checkin
ca
parents:
diff changeset
    80
    Button label:'Exit'       action:[model rootItem:nil. top destroy] in:panel.
eef25c370979 initial checkin
ca
parents:
diff changeset
    81
    Button label:'Pick Views' action:[  |win|
eef25c370979 initial checkin
ca
parents:
diff changeset
    82
                                        (     (win := Screen current viewFromUser) notNil
eef25c370979 initial checkin
ca
parents:
diff changeset
    83
                                         and:[(win := win topView) ~~ Screen current rootView
eef25c370979 initial checkin
ca
parents:
diff changeset
    84
                                         and:[win ~~ top]]
eef25c370979 initial checkin
ca
parents:
diff changeset
    85
                                        ) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
    86
                                            model rootItem:(ViewTreeItem buildViewsFrom:win)
eef25c370979 initial checkin
ca
parents:
diff changeset
    87
                                        ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
    88
                                            model rootItem:nil
eef25c370979 initial checkin
ca
parents:
diff changeset
    89
                                        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
    90
                                     ] in:panel.
eef25c370979 initial checkin
ca
parents:
diff changeset
    91
eef25c370979 initial checkin
ca
parents:
diff changeset
    92
    sel  multipleSelectOk:true.
eef25c370979 initial checkin
ca
parents:
diff changeset
    93
    sel              list:model listOfItems.
eef25c370979 initial checkin
ca
parents:
diff changeset
    94
    sel             model:model.
eef25c370979 initial checkin
ca
parents:
diff changeset
    95
    sel          useIndex:false.
eef25c370979 initial checkin
ca
parents:
diff changeset
    96
eef25c370979 initial checkin
ca
parents:
diff changeset
    97
    sel doubleClickAction:[:i| |el|
eef25c370979 initial checkin
ca
parents:
diff changeset
    98
        el := model listOfItems at:i.
eef25c370979 initial checkin
ca
parents:
diff changeset
    99
        el spec notNil ifTrue:[ el spec   inspect ] ifFalse:[ el widget inspect ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   100
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   101
    sel indicatorAction:[:i| (model listOfItems at:i) toggleExpand ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   102
eef25c370979 initial checkin
ca
parents:
diff changeset
   103
    model inputEventAction:[:anEvent| |item|
eef25c370979 initial checkin
ca
parents:
diff changeset
   104
        anEvent isButtonEvent ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   105
            anEvent isButtonPressEvent ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   106
                model selectedItem:(model listOfItems detectItemRespondsToView:(anEvent view)).
eef25c370979 initial checkin
ca
parents:
diff changeset
   107
            ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   108
                anEvent type == #'buttonMultiPress:x:y:' ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   109
                    (item := model selectedItem) notNil ifTrue:[item widget inspect]
eef25c370979 initial checkin
ca
parents:
diff changeset
   110
                ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   111
            ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   112
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   113
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   114
eef25c370979 initial checkin
ca
parents:
diff changeset
   115
    top openAndWait.
eef25c370979 initial checkin
ca
parents:
diff changeset
   116
    [[top shown] whileTrue:[Delay waitForSeconds:0.5]. model rootItem:nil] forkAt:8
eef25c370979 initial checkin
ca
parents:
diff changeset
   117
eef25c370979 initial checkin
ca
parents:
diff changeset
   118
                                                                                [exEnd]
eef25c370979 initial checkin
ca
parents:
diff changeset
   119
"
eef25c370979 initial checkin
ca
parents:
diff changeset
   120
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   121
eef25c370979 initial checkin
ca
parents:
diff changeset
   122
!ViewTreeModel methodsFor:'accessing'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   123
eef25c370979 initial checkin
ca
parents:
diff changeset
   124
application:anApplication
eef25c370979 initial checkin
ca
parents:
diff changeset
   125
    listOfItems application:anApplication.
eef25c370979 initial checkin
ca
parents:
diff changeset
   126
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   127
eef25c370979 initial checkin
ca
parents:
diff changeset
   128
rootItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   129
    "get the rootItem the event viewer is established on
eef25c370979 initial checkin
ca
parents:
diff changeset
   130
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   131
    ^ listOfItems root
eef25c370979 initial checkin
ca
parents:
diff changeset
   132
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   133
eef25c370979 initial checkin
ca
parents:
diff changeset
   134
rootItem:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   135
    "set the rootItem the event viewer is established on
eef25c370979 initial checkin
ca
parents:
diff changeset
   136
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   137
    |expanded|
eef25c370979 initial checkin
ca
parents:
diff changeset
   138
eef25c370979 initial checkin
ca
parents:
diff changeset
   139
    timedUpdateTask := nil.
2457
ca
parents: 2453
diff changeset
   140
    self deselect.
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   141
eef25c370979 initial checkin
ca
parents:
diff changeset
   142
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   143
        anItem notNil ifTrue:[ expanded := anItem isExpanded ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   144
                     ifFalse:[ expanded := false ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   145
eef25c370979 initial checkin
ca
parents:
diff changeset
   146
        self value:nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   147
        listOfItems root:anItem.
eef25c370979 initial checkin
ca
parents:
diff changeset
   148
eef25c370979 initial checkin
ca
parents:
diff changeset
   149
        anItem notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   150
            timedUpdateTask := Process for:[ self timedUpdateTaskCycle ] priority:8.
eef25c370979 initial checkin
ca
parents:
diff changeset
   151
            timedUpdateTask name:'Update'.
eef25c370979 initial checkin
ca
parents:
diff changeset
   152
            timedUpdateTask resume.
eef25c370979 initial checkin
ca
parents:
diff changeset
   153
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   154
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   155
eef25c370979 initial checkin
ca
parents:
diff changeset
   156
    (expanded and:[anItem notNil]) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   157
        anItem expand
eef25c370979 initial checkin
ca
parents:
diff changeset
   158
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   159
    ^ anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   160
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   161
eef25c370979 initial checkin
ca
parents:
diff changeset
   162
rootView
eef25c370979 initial checkin
ca
parents:
diff changeset
   163
    "get the top widget the event viewer is established on, a View
eef25c370979 initial checkin
ca
parents:
diff changeset
   164
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   165
    ^ listOfItems rootView
eef25c370979 initial checkin
ca
parents:
diff changeset
   166
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   167
eef25c370979 initial checkin
ca
parents:
diff changeset
   168
!ViewTreeModel methodsFor:'accessing actions'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   169
eef25c370979 initial checkin
ca
parents:
diff changeset
   170
beforeSelectionChangedAction
eef25c370979 initial checkin
ca
parents:
diff changeset
   171
    "none argument action which is called before
eef25c370979 initial checkin
ca
parents:
diff changeset
   172
     the selection changed
eef25c370979 initial checkin
ca
parents:
diff changeset
   173
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   174
    ^ beforeSelectionChangedAction
eef25c370979 initial checkin
ca
parents:
diff changeset
   175
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   176
eef25c370979 initial checkin
ca
parents:
diff changeset
   177
beforeSelectionChangedAction:aNoneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   178
    "none argument action which is called before
eef25c370979 initial checkin
ca
parents:
diff changeset
   179
     the selection changed
eef25c370979 initial checkin
ca
parents:
diff changeset
   180
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   181
    beforeSelectionChangedAction := aNoneArgBlock.
eef25c370979 initial checkin
ca
parents:
diff changeset
   182
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   183
eef25c370979 initial checkin
ca
parents:
diff changeset
   184
inputEventAction
eef25c370979 initial checkin
ca
parents:
diff changeset
   185
    "called for each input event; the argument to the action is the WindowEvent
eef25c370979 initial checkin
ca
parents:
diff changeset
   186
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   187
    ^ inputEventAction
eef25c370979 initial checkin
ca
parents:
diff changeset
   188
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   189
eef25c370979 initial checkin
ca
parents:
diff changeset
   190
inputEventAction:aOneArgActionTheEvent
eef25c370979 initial checkin
ca
parents:
diff changeset
   191
    "called for each input event; the argument to the action is the WindowEvent
eef25c370979 initial checkin
ca
parents:
diff changeset
   192
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   193
    inputEventAction := aOneArgActionTheEvent.
eef25c370979 initial checkin
ca
parents:
diff changeset
   194
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   195
eef25c370979 initial checkin
ca
parents:
diff changeset
   196
mappedViewAction
eef25c370979 initial checkin
ca
parents:
diff changeset
   197
    "called for a new mapped view which can not be found
eef25c370979 initial checkin
ca
parents:
diff changeset
   198
     in the current item list
eef25c370979 initial checkin
ca
parents:
diff changeset
   199
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   200
    ^ mappedViewAction
eef25c370979 initial checkin
ca
parents:
diff changeset
   201
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   202
eef25c370979 initial checkin
ca
parents:
diff changeset
   203
mappedViewAction:aOneArgBlockTheMappedView
eef25c370979 initial checkin
ca
parents:
diff changeset
   204
    "called for a new mapped view which can not be found
eef25c370979 initial checkin
ca
parents:
diff changeset
   205
     in the current item list
eef25c370979 initial checkin
ca
parents:
diff changeset
   206
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   207
    mappedViewAction := aOneArgBlockTheMappedView
eef25c370979 initial checkin
ca
parents:
diff changeset
   208
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   209
eef25c370979 initial checkin
ca
parents:
diff changeset
   210
!ViewTreeModel methodsFor:'accessing look'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   211
eef25c370979 initial checkin
ca
parents:
diff changeset
   212
iconAt:aKey ifNonePut:aNoneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   213
    |icon view|
eef25c370979 initial checkin
ca
parents:
diff changeset
   214
eef25c370979 initial checkin
ca
parents:
diff changeset
   215
    icon := icons at:aKey ifAbsent:nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   216
    icon notNil ifTrue:[^ icon].
eef25c370979 initial checkin
ca
parents:
diff changeset
   217
eef25c370979 initial checkin
ca
parents:
diff changeset
   218
    icon := aNoneArgBlock value.
eef25c370979 initial checkin
ca
parents:
diff changeset
   219
    icon isNil ifTrue:[^ nil].
eef25c370979 initial checkin
ca
parents:
diff changeset
   220
eef25c370979 initial checkin
ca
parents:
diff changeset
   221
    view := self rootView.
eef25c370979 initial checkin
ca
parents:
diff changeset
   222
    view isNil ifTrue:[^ icon].
eef25c370979 initial checkin
ca
parents:
diff changeset
   223
eef25c370979 initial checkin
ca
parents:
diff changeset
   224
    icon := icon copy onDevice:(view device).
eef25c370979 initial checkin
ca
parents:
diff changeset
   225
    icon isImage ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   226
        icon clearMaskedPixels.
eef25c370979 initial checkin
ca
parents:
diff changeset
   227
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   228
    icons at:aKey put:icon.
eef25c370979 initial checkin
ca
parents:
diff changeset
   229
    ^ icon
eef25c370979 initial checkin
ca
parents:
diff changeset
   230
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   231
eef25c370979 initial checkin
ca
parents:
diff changeset
   232
!ViewTreeModel methodsFor:'accessing visibility'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   233
eef25c370979 initial checkin
ca
parents:
diff changeset
   234
signalHiddenLevel
eef25c370979 initial checkin
ca
parents:
diff changeset
   235
    "show the selection if signaled; increments hiddenLevel
eef25c370979 initial checkin
ca
parents:
diff changeset
   236
     see: #waitHiddenLevel
eef25c370979 initial checkin
ca
parents:
diff changeset
   237
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   238
    (hiddenLevel := hiddenLevel - 1) < 1 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   239
        hiddenLevel := 0.
eef25c370979 initial checkin
ca
parents:
diff changeset
   240
        self invalidateSelection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   241
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   242
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   243
eef25c370979 initial checkin
ca
parents:
diff changeset
   244
waitHiddenLevel
eef25c370979 initial checkin
ca
parents:
diff changeset
   245
    "hide the selection until signaled; increments hiddenLevel
eef25c370979 initial checkin
ca
parents:
diff changeset
   246
     see: #signalHiddenLevel
eef25c370979 initial checkin
ca
parents:
diff changeset
   247
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   248
    self redrawUnselected:selection andLock:true
eef25c370979 initial checkin
ca
parents:
diff changeset
   249
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   250
eef25c370979 initial checkin
ca
parents:
diff changeset
   251
withSelectionHiddenDo:aNoneArgumentBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   252
    "apply block with selection hidden
eef25c370979 initial checkin
ca
parents:
diff changeset
   253
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   254
eef25c370979 initial checkin
ca
parents:
diff changeset
   255
    [   self waitHiddenLevel.
eef25c370979 initial checkin
ca
parents:
diff changeset
   256
eef25c370979 initial checkin
ca
parents:
diff changeset
   257
        aNoneArgumentBlock value
eef25c370979 initial checkin
ca
parents:
diff changeset
   258
eef25c370979 initial checkin
ca
parents:
diff changeset
   259
    ] valueNowOrOnUnwindDo:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   260
        self signalHiddenLevel.
eef25c370979 initial checkin
ca
parents:
diff changeset
   261
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   262
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   263
2457
ca
parents: 2453
diff changeset
   264
!ViewTreeModel methodsFor:'aspects'!
ca
parents: 2453
diff changeset
   265
ca
parents: 2453
diff changeset
   266
hasTargetWidgetChannel
ca
parents: 2453
diff changeset
   267
    "answer the channel which is set to true if a target widget exists"
ca
parents: 2453
diff changeset
   268
ca
parents: 2453
diff changeset
   269
    ^ hasTargetWidgetChannel
ca
parents: 2453
diff changeset
   270
!
ca
parents: 2453
diff changeset
   271
ca
parents: 2453
diff changeset
   272
listOfItems
ca
parents: 2453
diff changeset
   273
    "hiearchical list build from existing items"
ca
parents: 2453
diff changeset
   274
ca
parents: 2453
diff changeset
   275
    ^ listOfItems
ca
parents: 2453
diff changeset
   276
!
ca
parents: 2453
diff changeset
   277
ca
parents: 2453
diff changeset
   278
selectOnClickHolder
ca
parents: 2453
diff changeset
   279
    "boolean holder, which indicates whether the selection will change on click
ca
parents: 2453
diff changeset
   280
    "
ca
parents: 2453
diff changeset
   281
    ^ selectOnClickHolder
ca
parents: 2453
diff changeset
   282
!
ca
parents: 2453
diff changeset
   283
ca
parents: 2453
diff changeset
   284
testModeChannel
ca
parents: 2453
diff changeset
   285
    "answer a boolean channel which describes the behaviour how to process
ca
parents: 2453
diff changeset
   286
     events on the target view.
ca
parents: 2453
diff changeset
   287
ca
parents: 2453
diff changeset
   288
     false: all input events are eaten and the selection is shown on the target view.
ca
parents: 2453
diff changeset
   289
     true:  no  input events are eaten and no  selection is shown on the target view."
ca
parents: 2453
diff changeset
   290
ca
parents: 2453
diff changeset
   291
    ^ testModeChannel
ca
parents: 2453
diff changeset
   292
! !
ca
parents: 2453
diff changeset
   293
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   294
!ViewTreeModel methodsFor:'change & update'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   295
2457
ca
parents: 2453
diff changeset
   296
targetWidgetChanged
ca
parents: 2453
diff changeset
   297
    hasTargetWidgetChannel value:(self rootItem notNil).
ca
parents: 2453
diff changeset
   298
!
ca
parents: 2453
diff changeset
   299
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   300
timedUpdateTaskCycle
eef25c370979 initial checkin
ca
parents:
diff changeset
   301
    |view myTaskId|
eef25c370979 initial checkin
ca
parents:
diff changeset
   302
eef25c370979 initial checkin
ca
parents:
diff changeset
   303
    myTaskId := timedUpdateTask.
eef25c370979 initial checkin
ca
parents:
diff changeset
   304
eef25c370979 initial checkin
ca
parents:
diff changeset
   305
    listOfItems root notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   306
        view := listOfItems root widget.
eef25c370979 initial checkin
ca
parents:
diff changeset
   307
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   308
eef25c370979 initial checkin
ca
parents:
diff changeset
   309
    [ view notNil ] whileTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   310
        Delay waitForSeconds:0.5.
eef25c370979 initial checkin
ca
parents:
diff changeset
   311
        
eef25c370979 initial checkin
ca
parents:
diff changeset
   312
        (myTaskId == timedUpdateTask and:[view id notNil]) ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   313
            view := nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   314
        ] ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   315
            (view sensor hasUserEvent:#updateChildren for:self) ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   316
                view sensor pushUserEvent:#updateChildren for:self.
eef25c370979 initial checkin
ca
parents:
diff changeset
   317
            ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   318
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   319
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   320
    timedUpdateTask == myTaskId ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   321
        timedUpdateTask := nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   322
        listOfItems root:nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   323
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   324
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   325
2457
ca
parents: 2453
diff changeset
   326
update:something with:someArgument from:aModel
ca
parents: 2453
diff changeset
   327
ca
parents: 2453
diff changeset
   328
    aModel == testModeChannel ifTrue:[
ca
parents: 2453
diff changeset
   329
        (hiddenLevel == 0 and:[selection size > 0]) ifTrue:[
ca
parents: 2453
diff changeset
   330
            testModeChannel value ifTrue:[
ca
parents: 2453
diff changeset
   331
                self redrawUnselected:selection andLock:false checkTestMode:false.
ca
parents: 2453
diff changeset
   332
            ] ifFalse:[
ca
parents: 2453
diff changeset
   333
                self invalidateSelection.
ca
parents: 2453
diff changeset
   334
            ].
ca
parents: 2453
diff changeset
   335
        ].
ca
parents: 2453
diff changeset
   336
        ^ self
ca
parents: 2453
diff changeset
   337
    ].
ca
parents: 2453
diff changeset
   338
    super update:something with:someArgument from:aModel.
ca
parents: 2453
diff changeset
   339
!
ca
parents: 2453
diff changeset
   340
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   341
updateChildren
eef25c370979 initial checkin
ca
parents:
diff changeset
   342
    |rootItem|
eef25c370979 initial checkin
ca
parents:
diff changeset
   343
eef25c370979 initial checkin
ca
parents:
diff changeset
   344
    rootItem := listOfItems root.
eef25c370979 initial checkin
ca
parents:
diff changeset
   345
    rootItem isNil ifTrue:[^ self].
eef25c370979 initial checkin
ca
parents:
diff changeset
   346
eef25c370979 initial checkin
ca
parents:
diff changeset
   347
    rootItem exists ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   348
        listOfItems root:nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   349
    ] ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   350
        rootItem updateChildren.
eef25c370979 initial checkin
ca
parents:
diff changeset
   351
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   352
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   353
eef25c370979 initial checkin
ca
parents:
diff changeset
   354
!ViewTreeModel methodsFor:'event processing'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   355
eef25c370979 initial checkin
ca
parents:
diff changeset
   356
processEvent:anEvent
eef25c370979 initial checkin
ca
parents:
diff changeset
   357
    "catch and process all WindowEvents for the rootComponent and its contained
eef25c370979 initial checkin
ca
parents:
diff changeset
   358
     widgets; redraw selection in case of damage ....
eef25c370979 initial checkin
ca
parents:
diff changeset
   359
    "
2457
ca
parents: 2453
diff changeset
   360
    |evView item rootView testMode|
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   361
eef25c370979 initial checkin
ca
parents:
diff changeset
   362
    evView := anEvent view.
eef25c370979 initial checkin
ca
parents:
diff changeset
   363
    evView isNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   364
        (anEvent isMessageSendEvent and:[anEvent receiver == self]) ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   365
            ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
   366
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   367
        anEvent value.
eef25c370979 initial checkin
ca
parents:
diff changeset
   368
        ^ true.
eef25c370979 initial checkin
ca
parents:
diff changeset
   369
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   370
    rootView := listOfItems rootView.
eef25c370979 initial checkin
ca
parents:
diff changeset
   371
    rootView isNil ifTrue:[ ^ false ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   372
eef25c370979 initial checkin
ca
parents:
diff changeset
   373
    anEvent isConfigureEvent ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   374
        hiddenLevel == 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   375
            self redrawUnselected:selection andLock:false.
eef25c370979 initial checkin
ca
parents:
diff changeset
   376
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   377
        ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
   378
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   379
eef25c370979 initial checkin
ca
parents:
diff changeset
   380
    "/ check whether view is contained within the rootView
eef25c370979 initial checkin
ca
parents:
diff changeset
   381
    (evView == rootView or:[evView isComponentOf:rootView]) ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   382
        ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
   383
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   384
eef25c370979 initial checkin
ca
parents:
diff changeset
   385
    anEvent isInputEvent ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   386
        anEvent isDamage ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   387
            hiddenLevel == 0 ifTrue:[self invalidateSelection].
eef25c370979 initial checkin
ca
parents:
diff changeset
   388
            ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
   389
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   390
eef25c370979 initial checkin
ca
parents:
diff changeset
   391
        anEvent isMapEvent ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   392
            mappedViewAction notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   393
                item := listOfItems recursiveDetect:[:el| el widget == evView].
eef25c370979 initial checkin
ca
parents:
diff changeset
   394
                item isNil ifTrue:[ mappedViewAction value:evView ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   395
            ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   396
            ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
   397
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   398
eef25c370979 initial checkin
ca
parents:
diff changeset
   399
        anEvent type == #terminate ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   400
            item := listOfItems recursiveDetect:[:el| el widget == evView].
eef25c370979 initial checkin
ca
parents:
diff changeset
   401
            item notNil ifTrue:[ self processTerminateForItem:item ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   402
            ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
   403
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   404
        ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
   405
    ].
2457
ca
parents: 2453
diff changeset
   406
    testMode := testModeChannel value.
ca
parents: 2453
diff changeset
   407
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   408
    anEvent isFocusEvent ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   409
        evView == rootView ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   410
            self invalidateSelection
eef25c370979 initial checkin
ca
parents:
diff changeset
   411
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   412
        ^ testMode not.
eef25c370979 initial checkin
ca
parents:
diff changeset
   413
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   414
    anEvent isPointerEnterLeaveEvent ifTrue:[ ^ testMode not ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   415
eef25c370979 initial checkin
ca
parents:
diff changeset
   416
    testMode ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   417
        inputEventAction notNil ifTrue:[ inputEventAction value:anEvent ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   418
    ] ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   419
        anEvent isButtonPressEvent ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   420
            selectOnClickHolder value ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   421
                self selectItem:(listOfItems detectItemRespondsToView:evView).
eef25c370979 initial checkin
ca
parents:
diff changeset
   422
            ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   423
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   424
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   425
eef25c370979 initial checkin
ca
parents:
diff changeset
   426
    (hiddenLevel ~~ 0 and:[anEvent isButtonReleaseEvent]) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   427
        hiddenLevel := 1.
eef25c370979 initial checkin
ca
parents:
diff changeset
   428
        self signalHiddenLevel.
eef25c370979 initial checkin
ca
parents:
diff changeset
   429
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   430
eef25c370979 initial checkin
ca
parents:
diff changeset
   431
    ^ testMode not
eef25c370979 initial checkin
ca
parents:
diff changeset
   432
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   433
eef25c370979 initial checkin
ca
parents:
diff changeset
   434
processTerminateForItem:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   435
    "received terminate for an item
eef25c370979 initial checkin
ca
parents:
diff changeset
   436
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   437
    anItem remove.
eef25c370979 initial checkin
ca
parents:
diff changeset
   438
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   439
eef25c370979 initial checkin
ca
parents:
diff changeset
   440
!ViewTreeModel methodsFor:'initialization'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   441
eef25c370979 initial checkin
ca
parents:
diff changeset
   442
initialize
eef25c370979 initial checkin
ca
parents:
diff changeset
   443
    "setup the default attributes
eef25c370979 initial checkin
ca
parents:
diff changeset
   444
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   445
    super initialize.
eef25c370979 initial checkin
ca
parents:
diff changeset
   446
2457
ca
parents: 2453
diff changeset
   447
    hiddenLevel           := 0.
ca
parents: 2453
diff changeset
   448
    lockSema              := RecursionLock new.
ca
parents: 2453
diff changeset
   449
    listOfItems           := ItemList new on:self.
ca
parents: 2453
diff changeset
   450
    selectedSuperItems    := #().
ca
parents: 2453
diff changeset
   451
    icons                 := IdentityDictionary new.
ca
parents: 2453
diff changeset
   452
ca
parents: 2453
diff changeset
   453
    hasTargetWidgetChannel := false asValue.
ca
parents: 2453
diff changeset
   454
    selectOnClickHolder    := true asValue.
ca
parents: 2453
diff changeset
   455
ca
parents: 2453
diff changeset
   456
    testModeChannel := false asValue.
ca
parents: 2453
diff changeset
   457
    testModeChannel addDependent:self.
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   458
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   459
eef25c370979 initial checkin
ca
parents:
diff changeset
   460
!ViewTreeModel methodsFor:'private selection'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   461
eef25c370979 initial checkin
ca
parents:
diff changeset
   462
invalidateSelection
eef25c370979 initial checkin
ca
parents:
diff changeset
   463
    "invalidate the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   464
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   465
    |topView|
eef25c370979 initial checkin
ca
parents:
diff changeset
   466
2457
ca
parents: 2453
diff changeset
   467
    testModeChannel value ifTrue:[ ^ self ]. "/ test whether running testMode
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   468
eef25c370979 initial checkin
ca
parents:
diff changeset
   469
    (     hiddenLevel == 0
eef25c370979 initial checkin
ca
parents:
diff changeset
   470
     and:[selection notNil
eef25c370979 initial checkin
ca
parents:
diff changeset
   471
     and:[(topView := listOfItems rootView) notNil
eef25c370979 initial checkin
ca
parents:
diff changeset
   472
     and:[topView shown]]]
eef25c370979 initial checkin
ca
parents:
diff changeset
   473
    ) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   474
        topView sensor pushUserEvent:#redrawSelection for:self withArguments:#()
eef25c370979 initial checkin
ca
parents:
diff changeset
   475
    ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   476
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   477
eef25c370979 initial checkin
ca
parents:
diff changeset
   478
recursiveRepair:theDamages startIn:aView relativeTo:aRootView
eef25c370979 initial checkin
ca
parents:
diff changeset
   479
    "repair all views and contained views, which intersects the damage.
eef25c370979 initial checkin
ca
parents:
diff changeset
   480
     !!!! all damages repaired are removed from the list of damages !!!!
eef25c370979 initial checkin
ca
parents:
diff changeset
   481
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   482
    |color relOrg damage subViews repaired
eef25c370979 initial checkin
ca
parents:
diff changeset
   483
     bwWidth    "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   484
     x          "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   485
     y          "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   486
     w          "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   487
     h          "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   488
     relOrgX    "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   489
     relOrgY    "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   490
     width      "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   491
     height     "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   492
     size       "{ Class:SmallInteger }"
eef25c370979 initial checkin
ca
parents:
diff changeset
   493
    |
eef25c370979 initial checkin
ca
parents:
diff changeset
   494
    (aView shown and:[theDamages notEmpty]) ifFalse:[ ^ self ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   495
eef25c370979 initial checkin
ca
parents:
diff changeset
   496
    subViews := aView subViews.
eef25c370979 initial checkin
ca
parents:
diff changeset
   497
eef25c370979 initial checkin
ca
parents:
diff changeset
   498
    subViews size ~~ 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   499
        subViews reverseDo:[:v| self recursiveRepair:theDamages startIn:v relativeTo:aRootView ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   500
        theDamages isEmpty ifTrue:[ ^ self ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   501
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   502
eef25c370979 initial checkin
ca
parents:
diff changeset
   503
    relOrg  := aView originRelativeTo:aRootView.
eef25c370979 initial checkin
ca
parents:
diff changeset
   504
    bwWidth := aView borderWidth.
eef25c370979 initial checkin
ca
parents:
diff changeset
   505
    size    := theDamages size.
eef25c370979 initial checkin
ca
parents:
diff changeset
   506
eef25c370979 initial checkin
ca
parents:
diff changeset
   507
    "/ compute relative origin starting from border left@top
eef25c370979 initial checkin
ca
parents:
diff changeset
   508
    relOrgX := relOrg x - bwWidth.
eef25c370979 initial checkin
ca
parents:
diff changeset
   509
    relOrgY := relOrg y - bwWidth.
eef25c370979 initial checkin
ca
parents:
diff changeset
   510
    width   := aView width  + bwWidth + bwWidth.
eef25c370979 initial checkin
ca
parents:
diff changeset
   511
    height  := aView height + bwWidth + bwWidth.
eef25c370979 initial checkin
ca
parents:
diff changeset
   512
eef25c370979 initial checkin
ca
parents:
diff changeset
   513
    size to:1 by:-1 do:[:anIndex|
eef25c370979 initial checkin
ca
parents:
diff changeset
   514
        repaired := damage := theDamages at:anIndex.
eef25c370979 initial checkin
ca
parents:
diff changeset
   515
eef25c370979 initial checkin
ca
parents:
diff changeset
   516
        "/ compute the rectangle into the view
eef25c370979 initial checkin
ca
parents:
diff changeset
   517
        y := damage top  - relOrgY.
eef25c370979 initial checkin
ca
parents:
diff changeset
   518
        x := damage left - relOrgX.
eef25c370979 initial checkin
ca
parents:
diff changeset
   519
        w := damage width.
eef25c370979 initial checkin
ca
parents:
diff changeset
   520
        h := damage height.
eef25c370979 initial checkin
ca
parents:
diff changeset
   521
eef25c370979 initial checkin
ca
parents:
diff changeset
   522
        x     < 0      ifTrue:[ w := w + x. x := 0. repaired := nil ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   523
        y     < 0      ifTrue:[ h := h + y. y := 0. repaired := nil ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   524
        x + w > width  ifTrue:[ w := width  - x.    repaired := nil ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   525
        y + h > height ifTrue:[ h := height - y.    repaired := nil ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   526
eef25c370979 initial checkin
ca
parents:
diff changeset
   527
        (w > 0 and:[h > 0]) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   528
            bwWidth ~~ 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   529
                color isNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   530
                    "/ must force redraw of border
eef25c370979 initial checkin
ca
parents:
diff changeset
   531
                    color := aView borderColor.
eef25c370979 initial checkin
ca
parents:
diff changeset
   532
                    aView borderColor:(Color colorId:1).
eef25c370979 initial checkin
ca
parents:
diff changeset
   533
                    aView borderColor:color.
eef25c370979 initial checkin
ca
parents:
diff changeset
   534
                ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   535
                w := w - bwWidth.
eef25c370979 initial checkin
ca
parents:
diff changeset
   536
                h := h - bwWidth.
eef25c370979 initial checkin
ca
parents:
diff changeset
   537
eef25c370979 initial checkin
ca
parents:
diff changeset
   538
                (x := x - bwWidth) < 0 ifTrue:[w := w + x. x := 0].
eef25c370979 initial checkin
ca
parents:
diff changeset
   539
                (y := y - bwWidth) < 0 ifTrue:[h := h + y. y := 0].
eef25c370979 initial checkin
ca
parents:
diff changeset
   540
eef25c370979 initial checkin
ca
parents:
diff changeset
   541
                h > 0 ifFalse:[w := 0].         "/ later testing on width only
eef25c370979 initial checkin
ca
parents:
diff changeset
   542
            ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   543
eef25c370979 initial checkin
ca
parents:
diff changeset
   544
            w > 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   545
                aView clearRectangleX:x y:y width:w height:h.
eef25c370979 initial checkin
ca
parents:
diff changeset
   546
                aView exposeX:x y:y width:w height:h
eef25c370979 initial checkin
ca
parents:
diff changeset
   547
            ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   548
            repaired notNil ifTrue:[ theDamages removeFromIndex:anIndex toIndex:anIndex ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   549
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   550
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   551
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   552
eef25c370979 initial checkin
ca
parents:
diff changeset
   553
redrawSelection
eef25c370979 initial checkin
ca
parents:
diff changeset
   554
    "redraw all items selected
eef25c370979 initial checkin
ca
parents:
diff changeset
   555
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   556
    |topView size|
eef25c370979 initial checkin
ca
parents:
diff changeset
   557
2457
ca
parents: 2453
diff changeset
   558
    testModeChannel value ifTrue:[ ^ self ]. "/ test whether running testMode
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   559
eef25c370979 initial checkin
ca
parents:
diff changeset
   560
    (     hiddenLevel == 0
eef25c370979 initial checkin
ca
parents:
diff changeset
   561
     and:[(size := selection size) > 0
eef25c370979 initial checkin
ca
parents:
diff changeset
   562
     and:[(topView := listOfItems rootView) notNil
eef25c370979 initial checkin
ca
parents:
diff changeset
   563
     and:[topView shown
eef25c370979 initial checkin
ca
parents:
diff changeset
   564
     and:[(topView sensor hasEvent:#redrawSelection for:self) not]]]]
eef25c370979 initial checkin
ca
parents:
diff changeset
   565
    ) ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   566
        ^ self
eef25c370979 initial checkin
ca
parents:
diff changeset
   567
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   568
eef25c370979 initial checkin
ca
parents:
diff changeset
   569
    lockSema critical:[
2457
ca
parents: 2453
diff changeset
   570
        |list|
ca
parents: 2453
diff changeset
   571
ca
parents: 2453
diff changeset
   572
        list := selection.
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   573
2457
ca
parents: 2453
diff changeset
   574
        list size > 0 ifTrue:[
ca
parents: 2453
diff changeset
   575
            topView paint:(Color black).
ca
parents: 2453
diff changeset
   576
            topView clippedByChildren:false.
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   577
2457
ca
parents: 2453
diff changeset
   578
            list keysAndValuesReverseDo:[:anIndex :anItem|
ca
parents: 2453
diff changeset
   579
                (anIndex == 1 and:[size > 1]) ifTrue:[ topView paint:(Color red) ].
ca
parents: 2453
diff changeset
   580
ca
parents: 2453
diff changeset
   581
                anItem handlesDo:[:aRect :what|
ca
parents: 2453
diff changeset
   582
                    what isNil ifTrue:[topView displayRectangle:aRect]
ca
parents: 2453
diff changeset
   583
                              ifFalse:[topView    fillRectangle:aRect]
ca
parents: 2453
diff changeset
   584
                ]
ca
parents: 2453
diff changeset
   585
            ].
ca
parents: 2453
diff changeset
   586
            topView clippedByChildren:true.
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   587
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   588
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   589
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   590
eef25c370979 initial checkin
ca
parents:
diff changeset
   591
redrawUnselected:aList andLock:doLock
eef25c370979 initial checkin
ca
parents:
diff changeset
   592
    "redraw all items unselected; if doLock is true, the hiddenLevel
eef25c370979 initial checkin
ca
parents:
diff changeset
   593
     is incremented and thus the select mechanism is locked.
eef25c370979 initial checkin
ca
parents:
diff changeset
   594
    "
2457
ca
parents: 2453
diff changeset
   595
    self redrawUnselected:aList andLock:doLock checkTestMode:true.
ca
parents: 2453
diff changeset
   596
!
ca
parents: 2453
diff changeset
   597
ca
parents: 2453
diff changeset
   598
redrawUnselected:aList andLock:doLock checkTestMode:checkTestMode
ca
parents: 2453
diff changeset
   599
    "redraw all items unselected; if doLock is true, the hiddenLevel
ca
parents: 2453
diff changeset
   600
     is incremented and thus the select mechanism is locked.
ca
parents: 2453
diff changeset
   601
    "
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   602
    |rootView damages subViews x y w h|
eef25c370979 initial checkin
ca
parents:
diff changeset
   603
eef25c370979 initial checkin
ca
parents:
diff changeset
   604
    doLock ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   605
        hiddenLevel := hiddenLevel + 1.
eef25c370979 initial checkin
ca
parents:
diff changeset
   606
        hiddenLevel ~~ 1 ifTrue:[^ self].
eef25c370979 initial checkin
ca
parents:
diff changeset
   607
    ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   608
        hiddenLevel ~~ 0 ifTrue:[^ self].
eef25c370979 initial checkin
ca
parents:
diff changeset
   609
    ].
2457
ca
parents: 2453
diff changeset
   610
    checkTestMode ifTrue:[
ca
parents: 2453
diff changeset
   611
        testModeChannel value ifTrue:[ ^ self ]. "/ test whether running testMode
ca
parents: 2453
diff changeset
   612
    ].
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   613
eef25c370979 initial checkin
ca
parents:
diff changeset
   614
    (     aList size ~~ 0
eef25c370979 initial checkin
ca
parents:
diff changeset
   615
     and:[(rootView := listOfItems rootView) notNil
eef25c370979 initial checkin
ca
parents:
diff changeset
   616
     and:[rootView shown]]
eef25c370979 initial checkin
ca
parents:
diff changeset
   617
    ) ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   618
        ^ self
eef25c370979 initial checkin
ca
parents:
diff changeset
   619
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   620
eef25c370979 initial checkin
ca
parents:
diff changeset
   621
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   622
        damages := OrderedCollection new:(8 * aList size).
eef25c370979 initial checkin
ca
parents:
diff changeset
   623
eef25c370979 initial checkin
ca
parents:
diff changeset
   624
        aList do:[:item|
eef25c370979 initial checkin
ca
parents:
diff changeset
   625
            item handlesDo:[:handle :what|
eef25c370979 initial checkin
ca
parents:
diff changeset
   626
                damages reverseDo:[:el|
eef25c370979 initial checkin
ca
parents:
diff changeset
   627
                    (el intersects:handle) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   628
                        damages removeIdentical:el.
eef25c370979 initial checkin
ca
parents:
diff changeset
   629
eef25c370979 initial checkin
ca
parents:
diff changeset
   630
                        handle left:(handle left   min:el left)
eef25c370979 initial checkin
ca
parents:
diff changeset
   631
                              right:(handle right  max:el right)
eef25c370979 initial checkin
ca
parents:
diff changeset
   632
                                top:(handle top    min:el top)
eef25c370979 initial checkin
ca
parents:
diff changeset
   633
                             bottom:(handle bottom max:el bottom)
eef25c370979 initial checkin
ca
parents:
diff changeset
   634
                    ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   635
                ].                        
eef25c370979 initial checkin
ca
parents:
diff changeset
   636
                damages add:handle
eef25c370979 initial checkin
ca
parents:
diff changeset
   637
            ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   638
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   639
eef25c370979 initial checkin
ca
parents:
diff changeset
   640
        damages do:[:el|
eef25c370979 initial checkin
ca
parents:
diff changeset
   641
            x := el left.
eef25c370979 initial checkin
ca
parents:
diff changeset
   642
            y := el top.
eef25c370979 initial checkin
ca
parents:
diff changeset
   643
            w := el width.
eef25c370979 initial checkin
ca
parents:
diff changeset
   644
            h := el height.
eef25c370979 initial checkin
ca
parents:
diff changeset
   645
eef25c370979 initial checkin
ca
parents:
diff changeset
   646
            rootView clearRectangleX:x y:y width:w height:h.
eef25c370979 initial checkin
ca
parents:
diff changeset
   647
            rootView         exposeX:x y:y width:w height:h.
eef25c370979 initial checkin
ca
parents:
diff changeset
   648
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   649
eef25c370979 initial checkin
ca
parents:
diff changeset
   650
        (subViews := rootView subViews) notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   651
            subViews reverseDo:[:v| self recursiveRepair:damages startIn:v relativeTo:rootView ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   652
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   653
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   654
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   655
2457
ca
parents: 2453
diff changeset
   656
!ViewTreeModel methodsFor:'queries'!
ca
parents: 2453
diff changeset
   657
ca
parents: 2453
diff changeset
   658
isInTestMode
ca
parents: 2453
diff changeset
   659
    "answer false, all input events are eaten and the selection is shown on the target view.
ca
parents: 2453
diff changeset
   660
     answer true,  no  input events are eaten and no  selection is shown on the target view."
ca
parents: 2453
diff changeset
   661
ca
parents: 2453
diff changeset
   662
    ^ testModeChannel value
ca
parents: 2453
diff changeset
   663
! !
ca
parents: 2453
diff changeset
   664
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
   665
!ViewTreeModel methodsFor:'selection accessing'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   666
eef25c370979 initial checkin
ca
parents:
diff changeset
   667
at:anIndex
eef25c370979 initial checkin
ca
parents:
diff changeset
   668
    "returns the selected item at an index or nil
eef25c370979 initial checkin
ca
parents:
diff changeset
   669
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   670
    selection notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   671
        ^ selection at:anIndex ifAbsent:nil
eef25c370979 initial checkin
ca
parents:
diff changeset
   672
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   673
    ^ nil
eef25c370979 initial checkin
ca
parents:
diff changeset
   674
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   675
eef25c370979 initial checkin
ca
parents:
diff changeset
   676
at:anIndex ifAbsent:aBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   677
    "returns the selected item at an index or the result of the block
eef25c370979 initial checkin
ca
parents:
diff changeset
   678
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   679
    selection notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   680
        ^ selection at:anIndex ifAbsent:aBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   681
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   682
    ^ aBlock value
eef25c370979 initial checkin
ca
parents:
diff changeset
   683
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   684
eef25c370979 initial checkin
ca
parents:
diff changeset
   685
first
eef25c370979 initial checkin
ca
parents:
diff changeset
   686
    "returns the first selected item or nil
eef25c370979 initial checkin
ca
parents:
diff changeset
   687
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   688
    ^ self at:1
eef25c370979 initial checkin
ca
parents:
diff changeset
   689
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   690
eef25c370979 initial checkin
ca
parents:
diff changeset
   691
last
eef25c370979 initial checkin
ca
parents:
diff changeset
   692
    "returns the last selected item or nil
eef25c370979 initial checkin
ca
parents:
diff changeset
   693
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   694
    ^ selection notNil ifTrue:[selection last] ifFalse:[nil]
eef25c370979 initial checkin
ca
parents:
diff changeset
   695
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   696
eef25c370979 initial checkin
ca
parents:
diff changeset
   697
selectedItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   698
    "returns the single selected item or nil (size ~~ 1 nil is returned)
eef25c370979 initial checkin
ca
parents:
diff changeset
   699
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   700
    ^ selection size == 1 ifTrue:[selection at:1] ifFalse:[nil]
eef25c370979 initial checkin
ca
parents:
diff changeset
   701
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   702
eef25c370979 initial checkin
ca
parents:
diff changeset
   703
selectedSuperItems
eef25c370979 initial checkin
ca
parents:
diff changeset
   704
    "returs the list of selected superItems; items selected
eef25c370979 initial checkin
ca
parents:
diff changeset
   705
     but not contained in another selected item.
eef25c370979 initial checkin
ca
parents:
diff changeset
   706
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   707
    ^ selectedSuperItems
eef25c370979 initial checkin
ca
parents:
diff changeset
   708
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   709
eef25c370979 initial checkin
ca
parents:
diff changeset
   710
size
eef25c370979 initial checkin
ca
parents:
diff changeset
   711
    "returns the number of items selected
eef25c370979 initial checkin
ca
parents:
diff changeset
   712
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   713
    ^ selection size
eef25c370979 initial checkin
ca
parents:
diff changeset
   714
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   715
eef25c370979 initial checkin
ca
parents:
diff changeset
   716
!ViewTreeModel methodsFor:'selection adding & removing'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   717
eef25c370979 initial checkin
ca
parents:
diff changeset
   718
add:item
eef25c370979 initial checkin
ca
parents:
diff changeset
   719
    "add an item to the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   720
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   721
    |newSelect|
eef25c370979 initial checkin
ca
parents:
diff changeset
   722
eef25c370979 initial checkin
ca
parents:
diff changeset
   723
    item isNil ifTrue:[^ item].
eef25c370979 initial checkin
ca
parents:
diff changeset
   724
eef25c370979 initial checkin
ca
parents:
diff changeset
   725
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   726
        selection isNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   727
            newSelect := Array with:item.
eef25c370979 initial checkin
ca
parents:
diff changeset
   728
        ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   729
            (self includes:item) ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   730
                newSelect := selection copyWith:item
eef25c370979 initial checkin
ca
parents:
diff changeset
   731
            ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   732
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   733
eef25c370979 initial checkin
ca
parents:
diff changeset
   734
        newSelect size ~~ selection size ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   735
            item makeVisible.
eef25c370979 initial checkin
ca
parents:
diff changeset
   736
            self value:newSelect
eef25c370979 initial checkin
ca
parents:
diff changeset
   737
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   738
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   739
    ^ item
eef25c370979 initial checkin
ca
parents:
diff changeset
   740
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   741
eef25c370979 initial checkin
ca
parents:
diff changeset
   742
addAll:aCollectionOfItems
eef25c370979 initial checkin
ca
parents:
diff changeset
   743
    "add a collection of items to the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   744
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   745
    |newSelect|
eef25c370979 initial checkin
ca
parents:
diff changeset
   746
eef25c370979 initial checkin
ca
parents:
diff changeset
   747
    aCollectionOfItems size == 0 ifTrue:[ ^ aCollectionOfItems ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   748
eef25c370979 initial checkin
ca
parents:
diff changeset
   749
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   750
        selection isNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   751
            newSelect := Array withAll:aCollectionOfItems.
eef25c370979 initial checkin
ca
parents:
diff changeset
   752
        ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   753
            newSelect := OrderedCollection withAll:selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   754
eef25c370979 initial checkin
ca
parents:
diff changeset
   755
            aCollectionOfItems do:[:el|
eef25c370979 initial checkin
ca
parents:
diff changeset
   756
                (selection includesIdentical:el) ifFalse:[newSelect add:el]
eef25c370979 initial checkin
ca
parents:
diff changeset
   757
            ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   758
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   759
        self value:newSelect.
eef25c370979 initial checkin
ca
parents:
diff changeset
   760
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   761
    ^ aCollectionOfItems
eef25c370979 initial checkin
ca
parents:
diff changeset
   762
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   763
eef25c370979 initial checkin
ca
parents:
diff changeset
   764
deselect
eef25c370979 initial checkin
ca
parents:
diff changeset
   765
    "clear the selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   766
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   767
    self value:nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   768
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   769
eef25c370979 initial checkin
ca
parents:
diff changeset
   770
remove:item
eef25c370979 initial checkin
ca
parents:
diff changeset
   771
    "remove the item from the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   772
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   773
    |newSelect|
eef25c370979 initial checkin
ca
parents:
diff changeset
   774
eef25c370979 initial checkin
ca
parents:
diff changeset
   775
    item isNil ifTrue:[^ nil].
eef25c370979 initial checkin
ca
parents:
diff changeset
   776
eef25c370979 initial checkin
ca
parents:
diff changeset
   777
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   778
        (selection notNil and:[selection includesIdentical:item]) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   779
            selection size == 1 ifTrue:[ newSelect := nil ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   780
                               ifFalse:[ newSelect := selection copyWithout:item ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   781
eef25c370979 initial checkin
ca
parents:
diff changeset
   782
            self value:newSelect
eef25c370979 initial checkin
ca
parents:
diff changeset
   783
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   784
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   785
    ^ item
eef25c370979 initial checkin
ca
parents:
diff changeset
   786
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   787
eef25c370979 initial checkin
ca
parents:
diff changeset
   788
removeAll
eef25c370979 initial checkin
ca
parents:
diff changeset
   789
    "clear the selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   790
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   791
    self deselect.
eef25c370979 initial checkin
ca
parents:
diff changeset
   792
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   793
eef25c370979 initial checkin
ca
parents:
diff changeset
   794
removeAll:loItems
eef25c370979 initial checkin
ca
parents:
diff changeset
   795
    "remove all items of the collection from the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   796
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   797
    |newSelect|
eef25c370979 initial checkin
ca
parents:
diff changeset
   798
eef25c370979 initial checkin
ca
parents:
diff changeset
   799
    selection   isNil ifTrue:[ ^ loItems ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   800
    loItems size == 0 ifTrue:[ ^ loItems ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   801
eef25c370979 initial checkin
ca
parents:
diff changeset
   802
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   803
        selection notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   804
            newSelect := selection select:[:el| (loItems includesIdentical:el) not ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   805
            self value:newSelect.
eef25c370979 initial checkin
ca
parents:
diff changeset
   806
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   807
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   808
    ^ loItems
eef25c370979 initial checkin
ca
parents:
diff changeset
   809
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   810
eef25c370979 initial checkin
ca
parents:
diff changeset
   811
selectAll
eef25c370979 initial checkin
ca
parents:
diff changeset
   812
    "select all items
eef25c370979 initial checkin
ca
parents:
diff changeset
   813
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   814
    |root newSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
   815
eef25c370979 initial checkin
ca
parents:
diff changeset
   816
    root := listOfItems root.
eef25c370979 initial checkin
ca
parents:
diff changeset
   817
eef25c370979 initial checkin
ca
parents:
diff changeset
   818
    root isNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   819
        newSelection := nil
eef25c370979 initial checkin
ca
parents:
diff changeset
   820
    ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   821
        newSelection := OrderedCollection new.
eef25c370979 initial checkin
ca
parents:
diff changeset
   822
        root recursiveDo:[:el| newSelection add:el ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   823
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   824
    self value:newSelection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   825
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   826
eef25c370979 initial checkin
ca
parents:
diff changeset
   827
selectItem:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   828
    "set the current selection to the item
eef25c370979 initial checkin
ca
parents:
diff changeset
   829
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   830
    self value:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   831
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   832
eef25c370979 initial checkin
ca
parents:
diff changeset
   833
selectRootItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   834
    "set the current selection to the root item
eef25c370979 initial checkin
ca
parents:
diff changeset
   835
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   836
    self value:(self rootItem).
eef25c370979 initial checkin
ca
parents:
diff changeset
   837
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   838
eef25c370979 initial checkin
ca
parents:
diff changeset
   839
selectedItem:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   840
    "set the current selection to the item
eef25c370979 initial checkin
ca
parents:
diff changeset
   841
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   842
    self selectItem:anItem.
eef25c370979 initial checkin
ca
parents:
diff changeset
   843
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   844
eef25c370979 initial checkin
ca
parents:
diff changeset
   845
toggleSelectItem:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   846
    "toggle selection-state of the item; add or remove the item from the
eef25c370979 initial checkin
ca
parents:
diff changeset
   847
     current selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   848
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   849
    anItem notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   850
        (self includes:anItem) ifTrue:[self remove:anItem]
eef25c370979 initial checkin
ca
parents:
diff changeset
   851
                              ifFalse:[self add:anItem]
eef25c370979 initial checkin
ca
parents:
diff changeset
   852
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   853
    ^ anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
   854
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   855
eef25c370979 initial checkin
ca
parents:
diff changeset
   856
!ViewTreeModel methodsFor:'selection enumerating'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   857
eef25c370979 initial checkin
ca
parents:
diff changeset
   858
collect:aBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   859
    "for each element in the selection, evaluate the argument, aBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   860
     and return a new collection with the results
eef25c370979 initial checkin
ca
parents:
diff changeset
   861
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   862
    |res|
eef25c370979 initial checkin
ca
parents:
diff changeset
   863
eef25c370979 initial checkin
ca
parents:
diff changeset
   864
    res := OrderedCollection new.
eef25c370979 initial checkin
ca
parents:
diff changeset
   865
    self do:[:el| res add:(aBlock value:el)].
eef25c370979 initial checkin
ca
parents:
diff changeset
   866
  ^ res
eef25c370979 initial checkin
ca
parents:
diff changeset
   867
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   868
eef25c370979 initial checkin
ca
parents:
diff changeset
   869
do:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   870
    "evaluate the argument, aBlock for each item in the selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   871
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   872
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
   873
eef25c370979 initial checkin
ca
parents:
diff changeset
   874
    cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   875
    cashedSelection isNil ifTrue:[^ nil].
eef25c370979 initial checkin
ca
parents:
diff changeset
   876
  ^ cashedSelection do:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   877
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   878
eef25c370979 initial checkin
ca
parents:
diff changeset
   879
from:start do:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   880
    "evaluate the argument, aBlock for the items starting at index start
eef25c370979 initial checkin
ca
parents:
diff changeset
   881
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   882
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
   883
eef25c370979 initial checkin
ca
parents:
diff changeset
   884
    cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   885
    cashedSelection isNil ifTrue:[^ nil].
eef25c370979 initial checkin
ca
parents:
diff changeset
   886
  ^ cashedSelection from:start do:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   887
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   888
eef25c370979 initial checkin
ca
parents:
diff changeset
   889
from:start to:stop do:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   890
    "evaluate the argument, aBlock for the items with index start to
eef25c370979 initial checkin
ca
parents:
diff changeset
   891
     stop in the selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   892
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   893
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
   894
eef25c370979 initial checkin
ca
parents:
diff changeset
   895
    cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   896
    cashedSelection isNil ifTrue:[^ nil].
eef25c370979 initial checkin
ca
parents:
diff changeset
   897
  ^ cashedSelection from:start to:stop do:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   898
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   899
eef25c370979 initial checkin
ca
parents:
diff changeset
   900
reverseDo:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   901
    "evaluate the argument, aBlock for each item in the selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   902
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   903
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
   904
eef25c370979 initial checkin
ca
parents:
diff changeset
   905
    cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   906
    cashedSelection isNil ifTrue:[^ nil].
eef25c370979 initial checkin
ca
parents:
diff changeset
   907
  ^ cashedSelection reverseDo:aOneArgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   908
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   909
eef25c370979 initial checkin
ca
parents:
diff changeset
   910
select:aBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
   911
    "return a new collection with all elements from the selection, for which
eef25c370979 initial checkin
ca
parents:
diff changeset
   912
     the argument aBlock evaluates to true.
eef25c370979 initial checkin
ca
parents:
diff changeset
   913
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   914
    |res|
eef25c370979 initial checkin
ca
parents:
diff changeset
   915
eef25c370979 initial checkin
ca
parents:
diff changeset
   916
    res := OrderedCollection new.
eef25c370979 initial checkin
ca
parents:
diff changeset
   917
    self do:[:el| (aBlock value:el) ifTrue:[res add:el] ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   918
  ^ res
eef25c370979 initial checkin
ca
parents:
diff changeset
   919
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
   920
eef25c370979 initial checkin
ca
parents:
diff changeset
   921
!ViewTreeModel methodsFor:'selection protocol'!
eef25c370979 initial checkin
ca
parents:
diff changeset
   922
eef25c370979 initial checkin
ca
parents:
diff changeset
   923
changed:aParameter with:oldSelection
eef25c370979 initial checkin
ca
parents:
diff changeset
   924
    "update the visibility staus of the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   925
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   926
    |unselected rootView rootItem selSize|
eef25c370979 initial checkin
ca
parents:
diff changeset
   927
eef25c370979 initial checkin
ca
parents:
diff changeset
   928
    selSize := selection size.
eef25c370979 initial checkin
ca
parents:
diff changeset
   929
eef25c370979 initial checkin
ca
parents:
diff changeset
   930
    selSize == 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   931
        selectedSuperItems := #().
eef25c370979 initial checkin
ca
parents:
diff changeset
   932
    ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   933
        selSize == 1 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   934
            selectedSuperItems := Array with:(selection at:1).
eef25c370979 initial checkin
ca
parents:
diff changeset
   935
        ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   936
            rootItem := listOfItems root.
eef25c370979 initial checkin
ca
parents:
diff changeset
   937
eef25c370979 initial checkin
ca
parents:
diff changeset
   938
            (selection includesIdentical:rootItem) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   939
                selectedSuperItems := Array with:rootItem.
eef25c370979 initial checkin
ca
parents:
diff changeset
   940
            ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   941
                selectedSuperItems := OrderedCollection new:selSize.
eef25c370979 initial checkin
ca
parents:
diff changeset
   942
eef25c370979 initial checkin
ca
parents:
diff changeset
   943
                selection do:[:anItem|
eef25c370979 initial checkin
ca
parents:
diff changeset
   944
                    anItem parentsDetect:[:el| selection includesIdentical:el ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   945
                                  ifNone:[ selectedSuperItems add:anItem ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   946
                ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   947
            ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   948
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   949
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   950
eef25c370979 initial checkin
ca
parents:
diff changeset
   951
    (     hiddenLevel == 0
eef25c370979 initial checkin
ca
parents:
diff changeset
   952
     and:[(rootView := listOfItems rootView) notNil
eef25c370979 initial checkin
ca
parents:
diff changeset
   953
     and:[rootView shown]]
eef25c370979 initial checkin
ca
parents:
diff changeset
   954
    ) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   955
        selSize == 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   956
            "/ must redraw the old selection unselected
eef25c370979 initial checkin
ca
parents:
diff changeset
   957
            self redrawUnselected:oldSelection andLock:false
eef25c370979 initial checkin
ca
parents:
diff changeset
   958
        ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   959
            self invalidateSelection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   960
eef25c370979 initial checkin
ca
parents:
diff changeset
   961
            oldSelection size ~~ 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   962
                "/ must redraw all elements no longer in the selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   963
                unselected := oldSelection select:[:el| (selection includesIdentical:el) not ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   964
                self redrawUnselected:unselected andLock:false.
eef25c370979 initial checkin
ca
parents:
diff changeset
   965
            ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   966
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   967
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   968
    super changed:aParameter with:oldSelection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   969
!
eef25c370979 initial checkin
ca
parents:
diff changeset
   970
eef25c370979 initial checkin
ca
parents:
diff changeset
   971
setValue:aNewSelection 
eef25c370979 initial checkin
ca
parents:
diff changeset
   972
    "set the selection without notifying
eef25c370979 initial checkin
ca
parents:
diff changeset
   973
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
   974
    |newSelect idx|
eef25c370979 initial checkin
ca
parents:
diff changeset
   975
eef25c370979 initial checkin
ca
parents:
diff changeset
   976
    newSelect := nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
   977
eef25c370979 initial checkin
ca
parents:
diff changeset
   978
    aNewSelection notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   979
        lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   980
            aNewSelection isCollection ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   981
                (selection size == 1 and:[selection first == aNewSelection]) ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   982
                    newSelect := selection
eef25c370979 initial checkin
ca
parents:
diff changeset
   983
                ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   984
                    newSelect := Array with:aNewSelection.
eef25c370979 initial checkin
ca
parents:
diff changeset
   985
                ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   986
            ] ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   987
                aNewSelection notEmpty ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   988
                    aNewSelection size ~~ selection size ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   989
                        newSelect := aNewSelection copy.
eef25c370979 initial checkin
ca
parents:
diff changeset
   990
                    ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
   991
                        idx := selection findFirst:[:el| (aNewSelection includesIdentical:el) not ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   992
eef25c370979 initial checkin
ca
parents:
diff changeset
   993
                        idx ~~ 0 ifTrue:[newSelect := aNewSelection copy]
eef25c370979 initial checkin
ca
parents:
diff changeset
   994
                                ifFalse:[newSelect := selection ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   995
                    ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   996
                ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   997
            ]
eef25c370979 initial checkin
ca
parents:
diff changeset
   998
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
   999
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1000
    newSelect ~~ selection ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1001
        beforeSelectionChangedAction value.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1002
        selection := newSelect.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1003
        selection notNil ifTrue:[selection do:[:el| el makeVisible]]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1004
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1005
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1006
eef25c370979 initial checkin
ca
parents:
diff changeset
  1007
triggerValue:aValue
eef25c370979 initial checkin
ca
parents:
diff changeset
  1008
    "set my value & send change notifications to my dependents.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1009
     Send the change message even if the value didn't change.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1010
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1011
    |oldSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1012
eef25c370979 initial checkin
ca
parents:
diff changeset
  1013
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1014
        oldSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1015
        self setValue:aValue.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1016
        self changed:#value with:oldSelection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1017
    ]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1018
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1019
eef25c370979 initial checkin
ca
parents:
diff changeset
  1020
value
eef25c370979 initial checkin
ca
parents:
diff changeset
  1021
    "returns the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1022
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1023
    ^ selection ? #()
eef25c370979 initial checkin
ca
parents:
diff changeset
  1024
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1025
eef25c370979 initial checkin
ca
parents:
diff changeset
  1026
value:aValue
eef25c370979 initial checkin
ca
parents:
diff changeset
  1027
    "change the current selection and send change notifications to my
eef25c370979 initial checkin
ca
parents:
diff changeset
  1028
     dependents if it changed.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1029
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1030
    |oldSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1031
eef25c370979 initial checkin
ca
parents:
diff changeset
  1032
    lockSema critical:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1033
        oldSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1034
        self setValue:aValue.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1035
eef25c370979 initial checkin
ca
parents:
diff changeset
  1036
        oldSelection == selection ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1037
            self changed:#value with:oldSelection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1038
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1039
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1040
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1041
eef25c370979 initial checkin
ca
parents:
diff changeset
  1042
!ViewTreeModel methodsFor:'selection searching'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1043
eef25c370979 initial checkin
ca
parents:
diff changeset
  1044
detect:aBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1045
    "evaluate the argument, aBlock for each item in the selection until
eef25c370979 initial checkin
ca
parents:
diff changeset
  1046
     the block returns true; in this case return the element which caused
eef25c370979 initial checkin
ca
parents:
diff changeset
  1047
     the true evaluation.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1048
     If none of the evaluations returns true, an error is raised
eef25c370979 initial checkin
ca
parents:
diff changeset
  1049
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1050
    ^ self detect:aBlock ifNone:[self errorNotFound]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1051
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1052
eef25c370979 initial checkin
ca
parents:
diff changeset
  1053
detect:aBlock ifNone:exceptionBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1054
    "evaluate the argument, aBlock for each item in the selection until the
eef25c370979 initial checkin
ca
parents:
diff changeset
  1055
     block returns true; in this case return the element which caused the
eef25c370979 initial checkin
ca
parents:
diff changeset
  1056
     true evaluation.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1057
     If none of the evaluations returns true, the result of the evaluation
eef25c370979 initial checkin
ca
parents:
diff changeset
  1058
     of the exceptionBlock is returned
eef25c370979 initial checkin
ca
parents:
diff changeset
  1059
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1060
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1061
eef25c370979 initial checkin
ca
parents:
diff changeset
  1062
    cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1063
    cashedSelection isNil ifTrue:[ ^ exceptionBlock value ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1064
  ^ cashedSelection detect:aBlock ifNone:exceptionBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1065
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1066
eef25c370979 initial checkin
ca
parents:
diff changeset
  1067
detectLast:aBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1068
    "evaluate the argument, aBlock for each item in the selection until
eef25c370979 initial checkin
ca
parents:
diff changeset
  1069
     the block returns true; in this case return the element which caused
eef25c370979 initial checkin
ca
parents:
diff changeset
  1070
     the true evaluation. The items are processed in reverse order.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1071
     If none of the evaluations returns true, an error is raised
eef25c370979 initial checkin
ca
parents:
diff changeset
  1072
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1073
    ^ self detectLast:aBlock ifNone:[self errorNotFound]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1074
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1075
eef25c370979 initial checkin
ca
parents:
diff changeset
  1076
detectLast:aBlock ifNone:exceptionBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1077
    "evaluate the argument, aBlock for each item in the selection until
eef25c370979 initial checkin
ca
parents:
diff changeset
  1078
     the block returns true; in this case return the element which caused
eef25c370979 initial checkin
ca
parents:
diff changeset
  1079
     the true evaluation. The items are processed in reverse order.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1080
     If none of the evaluations returns true, the result of the evaluation
eef25c370979 initial checkin
ca
parents:
diff changeset
  1081
     of the exceptionBlock is returned
eef25c370979 initial checkin
ca
parents:
diff changeset
  1082
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1083
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1084
eef25c370979 initial checkin
ca
parents:
diff changeset
  1085
    cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1086
    cashedSelection isNil ifTrue:[ ^ exceptionBlock value ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1087
  ^ cashedSelection detectLast:aBlock ifNone:exceptionBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1088
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1089
eef25c370979 initial checkin
ca
parents:
diff changeset
  1090
!ViewTreeModel methodsFor:'selection testing'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1091
eef25c370979 initial checkin
ca
parents:
diff changeset
  1092
includes:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
  1093
    "returns true if the item is in the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1094
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1095
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1096
eef25c370979 initial checkin
ca
parents:
diff changeset
  1097
    cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1098
    cashedSelection isNil ifTrue:[^ false].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1099
 ^  cashedSelection includesIdentical:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
  1100
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1101
eef25c370979 initial checkin
ca
parents:
diff changeset
  1102
includesAll:aCollection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1103
    "return true, if all items of the collection are included in the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1104
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1105
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1106
eef25c370979 initial checkin
ca
parents:
diff changeset
  1107
    aCollection size ~~ 0 ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1108
        cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1109
        cashedSelection isNil ifTrue:[ ^ false ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1110
eef25c370979 initial checkin
ca
parents:
diff changeset
  1111
        aCollection do:[:el|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1112
            (cashedSelection includesIdentical:el) ifFalse:[^ false]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1113
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1114
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1115
    ^ true
eef25c370979 initial checkin
ca
parents:
diff changeset
  1116
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1117
eef25c370979 initial checkin
ca
parents:
diff changeset
  1118
includesAny:aCollection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1119
    "return true, if the any item of the collection is in the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1120
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1121
    |cashedSelection|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1122
eef25c370979 initial checkin
ca
parents:
diff changeset
  1123
    aCollection notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1124
        cashedSelection := selection.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1125
eef25c370979 initial checkin
ca
parents:
diff changeset
  1126
        cashedSelection notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1127
            aCollection do:[:el|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1128
                (cashedSelection includesIdentical:el) ifTrue:[^ true]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1129
            ]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1130
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1131
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1132
    ^ false
eef25c370979 initial checkin
ca
parents:
diff changeset
  1133
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1134
eef25c370979 initial checkin
ca
parents:
diff changeset
  1135
includesIdentical:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
  1136
    "returns true if the item is in the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1137
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1138
    ^ self includes:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
  1139
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1140
eef25c370979 initial checkin
ca
parents:
diff changeset
  1141
isEmpty
eef25c370979 initial checkin
ca
parents:
diff changeset
  1142
    "returns true if the current selection is empty
eef25c370979 initial checkin
ca
parents:
diff changeset
  1143
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1144
    ^ selection size == 0
eef25c370979 initial checkin
ca
parents:
diff changeset
  1145
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1146
eef25c370979 initial checkin
ca
parents:
diff changeset
  1147
isSelected:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
  1148
    "returns true if the item is in the current selection
eef25c370979 initial checkin
ca
parents:
diff changeset
  1149
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1150
    ^ self includes:anItem
eef25c370979 initial checkin
ca
parents:
diff changeset
  1151
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1152
eef25c370979 initial checkin
ca
parents:
diff changeset
  1153
notEmpty
eef25c370979 initial checkin
ca
parents:
diff changeset
  1154
    "returns true if the current selection is not empty
eef25c370979 initial checkin
ca
parents:
diff changeset
  1155
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1156
    ^ selection size ~~ 0
eef25c370979 initial checkin
ca
parents:
diff changeset
  1157
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1158
eef25c370979 initial checkin
ca
parents:
diff changeset
  1159
!ViewTreeModel::ItemList class methodsFor:'documentation'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1160
eef25c370979 initial checkin
ca
parents:
diff changeset
  1161
documentation
eef25c370979 initial checkin
ca
parents:
diff changeset
  1162
"
eef25c370979 initial checkin
ca
parents:
diff changeset
  1163
    Kind of HierarchicalList class which contains all the visible
eef25c370979 initial checkin
ca
parents:
diff changeset
  1164
    ViewTreeItem's and the root, the anchor of the hierarchical list.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1165
eef25c370979 initial checkin
ca
parents:
diff changeset
  1166
    [Instance variables:]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1167
        treeModel       <ViewTreeModel>         all events are delegated to
eef25c370979 initial checkin
ca
parents:
diff changeset
  1168
        eventHook       <BlockValue>            save and resore the pre/post -EventHook
eef25c370979 initial checkin
ca
parents:
diff changeset
  1169
eef25c370979 initial checkin
ca
parents:
diff changeset
  1170
eef25c370979 initial checkin
ca
parents:
diff changeset
  1171
    [author:]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1172
        Claus Atzkern
eef25c370979 initial checkin
ca
parents:
diff changeset
  1173
eef25c370979 initial checkin
ca
parents:
diff changeset
  1174
    [see also:]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1175
        HierarchicalList
eef25c370979 initial checkin
ca
parents:
diff changeset
  1176
        ViewTreeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
  1177
        ViewTreeItem
eef25c370979 initial checkin
ca
parents:
diff changeset
  1178
"
eef25c370979 initial checkin
ca
parents:
diff changeset
  1179
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1180
eef25c370979 initial checkin
ca
parents:
diff changeset
  1181
!ViewTreeModel::ItemList methodsFor:'accessing'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1182
eef25c370979 initial checkin
ca
parents:
diff changeset
  1183
root:theRoot
eef25c370979 initial checkin
ca
parents:
diff changeset
  1184
    "set the root item; delegate events to my treeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
  1185
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1186
    |rootView|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1187
eef25c370979 initial checkin
ca
parents:
diff changeset
  1188
    theRoot == root ifTrue:[^ self].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1189
eef25c370979 initial checkin
ca
parents:
diff changeset
  1190
    rootView := self rootView.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1191
    super root:theRoot.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1192
eef25c370979 initial checkin
ca
parents:
diff changeset
  1193
    rootView notNil ifTrue:[ |wgrp|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1194
        wgrp := rootView windowGroup.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1195
eef25c370979 initial checkin
ca
parents:
diff changeset
  1196
        wgrp notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1197
           wgrp removePreEventHook:treeModel.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1198
           wgrp removePostEventHook:self.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1199
        ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1200
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1201
eef25c370979 initial checkin
ca
parents:
diff changeset
  1202
    super root:theRoot.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1203
    rootView := self rootView.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1204
eef25c370979 initial checkin
ca
parents:
diff changeset
  1205
    rootView notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1206
        "must setup a task because there might not exist a windowGroup at the moment
eef25c370979 initial checkin
ca
parents:
diff changeset
  1207
        "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1208
        [   |wgrp|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1209
eef25c370979 initial checkin
ca
parents:
diff changeset
  1210
            [rootView == self rootView] whileTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1211
                wgrp := rootView windowGroup.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1212
                wgrp notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1213
                    rootView := nil.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1214
                    wgrp addPreEventHook:treeModel.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1215
                    wgrp addPostEventHook:self.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1216
                ] ifFalse:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1217
                    Delay waitForMilliseconds:100.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1218
                ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1219
            ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1220
eef25c370979 initial checkin
ca
parents:
diff changeset
  1221
        ] forkAt:(Processor userSchedulingPriority + 2).
eef25c370979 initial checkin
ca
parents:
diff changeset
  1222
    ].
2457
ca
parents: 2453
diff changeset
  1223
    treeModel notNil ifTrue:[
ca
parents: 2453
diff changeset
  1224
        treeModel targetWidgetChanged.
ca
parents: 2453
diff changeset
  1225
    ].
ca
parents: 2453
diff changeset
  1226
    
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
  1227
    ^ root.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1228
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1229
eef25c370979 initial checkin
ca
parents:
diff changeset
  1230
rootView
eef25c370979 initial checkin
ca
parents:
diff changeset
  1231
    "returns the widget assigned to the root or nil
eef25c370979 initial checkin
ca
parents:
diff changeset
  1232
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1233
    ^ root notNil ifTrue:[root widget] ifFalse:[nil]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1234
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1235
eef25c370979 initial checkin
ca
parents:
diff changeset
  1236
treeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
  1237
    "returne the treeModel, a ViewTreeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
  1238
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1239
    ^ treeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
  1240
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1241
2453
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1242
!ViewTreeModel::ItemList methodsFor:'accessing look'!
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1243
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1244
additionalLabelForItem:anItem
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1245
    "answer the additional lable for an item or nil"
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1246
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1247
    |applClass|
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1248
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1249
    showWidgetNames == true ifTrue:[
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1250
        ^ '[', anItem widget name, ']'
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1251
    ].
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1252
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1253
    anItem isApplicationClass ifTrue:[
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1254
        applClass := anItem applicationClass.
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1255
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1256
        applClass notNil ifTrue:[
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1257
            ^ ('[', applClass name, ']')
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1258
        ].
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1259
    ].
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1260
    ^ nil
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1261
!
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1262
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1263
showWidgetNames
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1264
    "answer true if the additional text is the widget name
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1265
     otherwise the name of the application"
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1266
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1267
    ^ showWidgetNames ? false
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1268
!
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1269
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1270
showWidgetNames:aBoolean
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1271
    "set true if the additional text is the widget name
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1272
     otherwise the name of the application"
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1273
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1274
    self showWidgetNames == aBoolean ifFalse:[
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1275
        showWidgetNames := aBoolean.
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1276
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1277
        root notNil ifTrue:[
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1278
            root recursiveAdditionalNameBehaviourChanged.
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1279
            self changed.
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1280
        ].
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1281
    ].
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1282
! !
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1283
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
  1284
!ViewTreeModel::ItemList methodsFor:'event processing'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1285
eef25c370979 initial checkin
ca
parents:
diff changeset
  1286
processEvent:anEvent
eef25c370979 initial checkin
ca
parents:
diff changeset
  1287
    "post process event
eef25c370979 initial checkin
ca
parents:
diff changeset
  1288
    "
2457
ca
parents: 2453
diff changeset
  1289
    ^ treeModel isInTestMode not
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
  1290
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1291
eef25c370979 initial checkin
ca
parents:
diff changeset
  1292
!ViewTreeModel::ItemList methodsFor:'instance creation'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1293
eef25c370979 initial checkin
ca
parents:
diff changeset
  1294
on:aModel
eef25c370979 initial checkin
ca
parents:
diff changeset
  1295
    "set the model, a ViewTreeModel
eef25c370979 initial checkin
ca
parents:
diff changeset
  1296
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1297
    treeModel := aModel.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1298
    showRoot  := true.
2453
cc98051589bb *** empty log message ***
ca
parents: 2404
diff changeset
  1299
    showWidgetNames := false.
2176
eef25c370979 initial checkin
ca
parents:
diff changeset
  1300
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1301
eef25c370979 initial checkin
ca
parents:
diff changeset
  1302
!ViewTreeModel::ItemList methodsFor:'searching'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1303
eef25c370979 initial checkin
ca
parents:
diff changeset
  1304
detectItemRespondsToView:aView
eef25c370979 initial checkin
ca
parents:
diff changeset
  1305
    "returns the bottom-most item which contains the view
eef25c370979 initial checkin
ca
parents:
diff changeset
  1306
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1307
    |view item topView|
eef25c370979 initial checkin
ca
parents:
diff changeset
  1308
eef25c370979 initial checkin
ca
parents:
diff changeset
  1309
    root notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1310
        view    := aView.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1311
        topView := root widget.
eef25c370979 initial checkin
ca
parents:
diff changeset
  1312
eef25c370979 initial checkin
ca
parents:
diff changeset
  1313
        [ view notNil ] whileTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1314
            topView == view ifTrue:[^ root].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1315
            item := root recursiveDetect:[:el| el widget == view ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1316
            item notNil ifTrue:[^ item].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1317
            view := view superView
eef25c370979 initial checkin
ca
parents:
diff changeset
  1318
        ]
eef25c370979 initial checkin
ca
parents:
diff changeset
  1319
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1320
    ^ nil
eef25c370979 initial checkin
ca
parents:
diff changeset
  1321
!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1322
eef25c370979 initial checkin
ca
parents:
diff changeset
  1323
recursiveDetect:aOneOrgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1324
    "recursive find the first child, for which evaluation 
eef25c370979 initial checkin
ca
parents:
diff changeset
  1325
     of the block returns true; if none nil is returned
eef25c370979 initial checkin
ca
parents:
diff changeset
  1326
    "
eef25c370979 initial checkin
ca
parents:
diff changeset
  1327
    root notNil ifTrue:[
eef25c370979 initial checkin
ca
parents:
diff changeset
  1328
        (aOneOrgBlock value:root) ifTrue:[ ^ root ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1329
      ^ root recursiveDetect:aOneOrgBlock
eef25c370979 initial checkin
ca
parents:
diff changeset
  1330
    ].
eef25c370979 initial checkin
ca
parents:
diff changeset
  1331
    ^ nil
eef25c370979 initial checkin
ca
parents:
diff changeset
  1332
! !
eef25c370979 initial checkin
ca
parents:
diff changeset
  1333
eef25c370979 initial checkin
ca
parents:
diff changeset
  1334
!ViewTreeModel class methodsFor:'documentation'!
eef25c370979 initial checkin
ca
parents:
diff changeset
  1335
eef25c370979 initial checkin
ca
parents:
diff changeset
  1336
version
eef25c370979 initial checkin
ca
parents:
diff changeset
  1337
    ^ '$Header$'
eef25c370979 initial checkin
ca
parents:
diff changeset
  1338
! !