SelectionInTreeView.st
author ca
Thu, 26 Feb 1998 08:43:55 +0100
changeset 792 5a0af910519e
parent 785 6114a6e125c5
child 811 a688e8f11bc6
permissions -rw-r--r--
bug fix: support each style when drawing the background of a selected line
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     1
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     3
              All Rights Reserved
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     4
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     5
 This software is furnished under a license and may be used
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    10
 hereby transferred.
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    11
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    12
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    13
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    14
SelectionInListView subclass:#SelectionInTreeView
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    15
	instanceVariableNames:'validateDoubleClickBlock selectionHolder rootHolder imageWidth
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    16
		showLines listOfNodes imageInset textInset labelOffsetY lineMask
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    17
		lineColor openIndicator computeResources closeIndicator showRoot
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    18
		extentOpenIndicator extentCloseIndicator showDirectoryIndicator
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    19
		showDirectoryIndicatorForRoot indicatorExtentDiv2 imageOpened
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    20
		imageClosed imageItem discardMotionEvents registeredImages'
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    21
	classVariableNames:'ImageOpened ImageClosed ImageItem OpenIndicator CloseIndicator'
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    22
	poolDictionaries:''
5a0af910519e bug fix:
ca
parents: 785
diff changeset
    23
	category:'Views-Text'
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    24
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    25
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    26
!SelectionInTreeView class methodsFor:'documentation'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    27
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    28
copyright
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    29
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    30
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    31
              All Rights Reserved
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    32
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    33
 This software is furnished under a license and may be used
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    34
 only in accordance with the terms of that license and with the
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    35
 inclusion of the above copyright notice.   This software may not
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    36
 be provided or otherwise made available to, or used by, any
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    37
 other person.  No title to or ownership of the software is
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    38
 hereby transferred.
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    39
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    40
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    41
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    42
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    43
documentation
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    44
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    45
    somewhat like a SelectionInListView; but specialized for hierarchical (i.e. tree-like)
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    46
    lists and adds the functions to show/hide subtrees. 
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    47
    Requires SelectionInTree as model and TreeItem (or compatible) list entries.
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    48
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    49
    This class obsoletes SelectionInTreeView, which is no longer
446
b6ac0f279b2f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
    50
    maintained but kept for backward compatibility.
b6ac0f279b2f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
    51
b6ac0f279b2f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 444
diff changeset
    52
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    53
    [see also:]
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    54
        SelectionInTree
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    55
        TreeItem
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    56
        SelectionInTreeView
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    57
        SelectionInListView
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
    58
        FileSelectionTree
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    59
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    60
    [author:]
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    61
        Claus Atzkern
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    62
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    63
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    64
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    65
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    66
examples
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    67
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    68
    shows the tree of smalltalk classes:
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    69
                                                                        [exBegin]
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
    70
      |top sel|
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    71
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
    72
      top := StandardSystemView new; extent:300@300.
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    73
      sel := SelectionInTreeView new.
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
    74
      sel root:(TreeItem newAsTreeFromSmalltalkClass:Object).
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    75
      sel action:[:nr | Transcript show:'selected:'; showCR:nr].
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    76
      top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)).
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    77
      top open.
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    78
                                                                        [exEnd]
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    79
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    80
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
    81
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    82
    same, including nil-subclasses (i.e. really all classes):
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    83
                                                                        [exBegin]
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
    84
      |top sel|
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
    85
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
    86
      top := StandardSystemView new; extent:300@300.
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    87
      sel := SelectionInTreeView new.
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
    88
      sel root:(TreeItem newAsTreeFromSmalltalkClass:nil).
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    89
      sel action:[:nr | Transcript show:'selected:'; showCR:nr].
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
    90
      sel lineColor:(Color red).
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    91
      top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)).
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    92
      top open.
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    93
                                                                        [exEnd]
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
    94
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
    95
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
    96
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
    97
    shows the tree of smalltalk classes; show directory indication and no
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
    98
    lines.
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
    99
                                                                        [exBegin]
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   100
      |top sel|
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
   101
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   102
      top := StandardSystemView new; extent:300@300.
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
   103
      sel := SelectionInTreeView new.
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   104
      sel showLines:false.
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   105
      sel showDirectoryIndicator:true.
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   106
      sel root:(TreeItem newAsTreeFromSmalltalkClass:Object).
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   107
      sel action:[:nr | Transcript show:'selected:'; showCR:nr].
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
   108
      top add:(ScrollableView forView:sel) in:((0.0 @ 0.0 ) corner:( 1.0 @ 1.0)).
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
   109
      top open.
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   110
                                                                        [exEnd]
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   111
"
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   112
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   113
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   114
! !
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   115
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   116
!SelectionInTreeView class methodsFor:'constants'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   117
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   118
minImageInset
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   119
    "returns minimum inset from directory indication to image
471
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
   120
    "
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   121
  ^ 6
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   122
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   123
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   124
! !
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   125
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   126
!SelectionInTreeView class methodsFor:'default images'!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   127
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   128
closeIndicator
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   129
    <resource: #fileImage>
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   130
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   131
    CloseIndicator isNil ifTrue:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   132
        CloseIndicator := Image fromFile:('xpmBitmaps/plus.xpm').
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   133
    ].
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   134
  ^ CloseIndicator
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   135
"
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   136
CloseIndicator := nil
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   137
"
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   138
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   139
    "Modified: / 29.10.1997 / 03:36:00 / cg"
471
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
   140
!
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
   141
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   142
imageClosed
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   143
    <resource: #fileImage>
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   144
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   145
    ImageClosed isNil ifTrue:[
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   146
        ImageClosed := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm').
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   147
    ].
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   148
  ^ ImageClosed
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   149
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   150
ImageClosed := nil
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   151
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   152
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   153
    "Modified: / 29.10.1997 / 03:36:05 / cg"
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   154
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   155
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   156
imageItem
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   157
    <resource: #fileImage>
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   158
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   159
    ImageItem isNil ifTrue:[
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   160
        ImageItem := Image fromFile:('xpmBitmaps/document_images/tiny_file_plain.xpm')  
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   161
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   162
    ].
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   163
  ^ ImageItem
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   164
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   165
ImageItem := nil
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   166
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   167
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   168
    "Modified: / 29.10.1997 / 03:36:10 / cg"
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   169
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   170
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   171
imageOpened
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   172
    <resource: #fileImage>
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   173
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   174
    ImageOpened isNil ifTrue:[
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   175
        ImageOpened := Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir_open.xpm').
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   176
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   177
    ].
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   178
  ^ ImageOpened
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   179
"
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   180
ImageOpened := nil
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   181
"
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   182
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   183
    "Modified: / 29.10.1997 / 03:36:15 / cg"
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   184
!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   185
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   186
openIndicator
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   187
    <resource: #fileImage>
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   188
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   189
    OpenIndicator isNil ifTrue:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   190
        OpenIndicator := Image fromFile:('xpmBitmaps/minus.xpm').
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   191
    ].
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   192
  ^ OpenIndicator
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   193
"
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   194
OpenIndicator := nil
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   195
"
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   196
589
979ea44d23ae checkin from browser
Claus Gittinger <cg@exept.de>
parents: 585
diff changeset
   197
    "Modified: / 29.10.1997 / 03:36:21 / cg"
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   198
! !
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   199
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   200
!SelectionInTreeView methodsFor:'accessing'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   201
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
   202
lineColor
80751cda3340 lines as point
ca
parents: 659
diff changeset
   203
    "returns user configured line color or nil
80751cda3340 lines as point
ca
parents: 659
diff changeset
   204
    "
80751cda3340 lines as point
ca
parents: 659
diff changeset
   205
    ^ lineColor
80751cda3340 lines as point
ca
parents: 659
diff changeset
   206
80751cda3340 lines as point
ca
parents: 659
diff changeset
   207
!
80751cda3340 lines as point
ca
parents: 659
diff changeset
   208
80751cda3340 lines as point
ca
parents: 659
diff changeset
   209
lineColor:aColor
80751cda3340 lines as point
ca
parents: 659
diff changeset
   210
    "returns user configured line color or nil
80751cda3340 lines as point
ca
parents: 659
diff changeset
   211
    "
80751cda3340 lines as point
ca
parents: 659
diff changeset
   212
    |col|
80751cda3340 lines as point
ca
parents: 659
diff changeset
   213
80751cda3340 lines as point
ca
parents: 659
diff changeset
   214
    col := aColor = fgColor ifTrue:[nil] ifFalse:[aColor].
80751cda3340 lines as point
ca
parents: 659
diff changeset
   215
80751cda3340 lines as point
ca
parents: 659
diff changeset
   216
    col = lineColor ifFalse:[
80751cda3340 lines as point
ca
parents: 659
diff changeset
   217
        lineColor := col.
80751cda3340 lines as point
ca
parents: 659
diff changeset
   218
80751cda3340 lines as point
ca
parents: 659
diff changeset
   219
        shown ifTrue:[
80751cda3340 lines as point
ca
parents: 659
diff changeset
   220
            lineColor notNil ifTrue:[lineColor := lineColor on:device].
80751cda3340 lines as point
ca
parents: 659
diff changeset
   221
            self invalidate
80751cda3340 lines as point
ca
parents: 659
diff changeset
   222
        ]
80751cda3340 lines as point
ca
parents: 659
diff changeset
   223
    ]
80751cda3340 lines as point
ca
parents: 659
diff changeset
   224
!
80751cda3340 lines as point
ca
parents: 659
diff changeset
   225
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   226
nodeAtIndex:anIndex
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   227
    "returns node at an index or nil
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   228
    "
785
ca
parents: 782
diff changeset
   229
    (anIndex notNil and:[anIndex between:1 and:listOfNodes size]) ifTrue:[
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   230
        ^ listOfNodes at:anIndex
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   231
    ].
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   232
  ^ nil
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   233
!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   234
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   235
root
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   236
    "gets the root of the model; the first item into list.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   237
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   238
    ^ self nodeAtIndex:1
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   239
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   240
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   241
root:aRoot
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   242
    "sets the root of the model; the first item into list.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   243
    "
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   244
    aRoot notNil ifTrue:[aRoot expand].
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   245
    model root:aRoot
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   246
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   247
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   248
textInset
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   249
    "get the left inset of the text label
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   250
    "
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   251
    ^ textInset
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   252
!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   253
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   254
textInset:anInset
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   255
    "set the left inset of the text label
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   256
    "
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   257
    anInset ~~ textInset ifTrue:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   258
        anInset >= 0 ifTrue:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   259
            textInset := anInset.
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   260
            self invalidate
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   261
        ] ifFalse:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   262
            self error
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   263
        ]
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   264
    ].
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   265
! !
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   266
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   267
!SelectionInTreeView methodsFor:'accessing-behavior'!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   268
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   269
showDirectoryIndicator
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   270
    "returns true if directories has an open/closed indicator
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   271
    "
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   272
  ^ showDirectoryIndicator
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   273
!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   274
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   275
showDirectoryIndicator:aState
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   276
    "set or clear open/closed indicator for directories
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   277
    "
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   278
    "show or hide lines
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   279
    "
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   280
    aState ~~ showDirectoryIndicator ifTrue:[
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   281
        showDirectoryIndicator := aState.
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
   282
        self recomputeDirectoryIndicator.
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   283
        self invalidate
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   284
    ].
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   285
!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   286
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   287
showDirectoryIndicatorForRoot
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   288
    "returns true if root directory has an open/closed indicator if
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   289
     the common showDirectoryIndicator is enabled
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   290
    "
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   291
    ^ showDirectoryIndicatorForRoot
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   292
!
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   293
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   294
showDirectoryIndicatorForRoot:aState
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   295
    "true if root directory has an open/closed indicator if
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   296
     the common showDirectoryIndicator is enabled
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   297
    "
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   298
    aState ~~ showDirectoryIndicator ifTrue:[
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   299
        showDirectoryIndicatorForRoot := aState.
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   300
        self recomputeDirectoryIndicator.
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   301
        self invalidate
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   302
    ].
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   303
!
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   304
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   305
showLines
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   306
    "returns true if lines are shown
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   307
    "
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   308
  ^ showLines
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   309
!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   310
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   311
showLines:aState
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   312
    "show or hide lines
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   313
    "
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   314
    aState ~~ showLines ifTrue:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   315
        showLines := aState.
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   316
        self invalidate
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   317
    ].
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   318
!
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   319
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   320
showRoot
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   321
    "list with or without root
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   322
    "
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   323
  ^ showRoot
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   324
!
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   325
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   326
showRoot:aState
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   327
    "list with or without root
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   328
    "
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   329
    showRoot ~~ aState ifTrue:[
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   330
        model showRoot:(showRoot := aState)
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   331
    ].
517
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   332
!
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   333
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   334
validateDoubleClickBlock
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   335
    "set the conditionBlock; this block is evaluated before a doubleClick action
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   336
     on a node will be performed. In case of returning false, the doubleClick will
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   337
     not be handled.
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   338
   "
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   339
   ^ validateDoubleClickBlock
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   340
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   341
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   342
!
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   343
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   344
validateDoubleClickBlock:aOneArgBlock
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   345
    "set the conditionBlock; this block is evaluated before a doubleClick action
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   346
     on a node will be performed. In case of returning false, the doubleClick will
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   347
     not be handled.
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   348
   "
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   349
   validateDoubleClickBlock := aOneArgBlock
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   350
14a46095db49 add validateDoubleClickBlock
ca
parents: 514
diff changeset
   351
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   352
! !
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   353
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   354
!SelectionInTreeView methodsFor:'accessing-channels'!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   355
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   356
rootHolder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   357
    "get the holder which keeps the hierarchical list entry or nil
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   358
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   359
    ^ rootHolder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   360
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   361
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   362
rootHolder:aValueHolder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   363
    "set the holder which keeps the hierarchical list entry or nil
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   364
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   365
    rootHolder notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   366
        rootHolder removeDependent:self
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   367
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   368
    (rootHolder := aValueHolder) notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   369
        rootHolder addDependent:self.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   370
        self rootFromModel.
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   371
    ].
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   372
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   373
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   374
selectionHolder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   375
    "get the holder which keeps a list of selected items or nil
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   376
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   377
    ^ selectionHolder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   378
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   379
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   380
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   381
selectionHolder:aHolder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   382
    "set the holder which keeps a list of selected items or nil
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   383
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   384
    selectionHolder notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   385
        selectionHolder removeDependent:self
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   386
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   387
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   388
    (selectionHolder := aHolder) notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   389
        selectionHolder addDependent:self.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   390
        self selectionFromModel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   391
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   392
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   393
! !
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   394
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   395
!SelectionInTreeView methodsFor:'accessing-images'!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   396
448
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   397
imageClosed
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   398
    "return the value of the instance variable 'imageClosed' (automatically generated)"
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   399
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   400
    ^ imageClosed
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   401
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   402
    "Created: 3.7.1997 / 12:34:31 / cg"
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   403
!
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   404
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   405
imageItem
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   406
    "return the value of the instance variable 'imageItem' (automatically generated)"
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   407
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   408
    ^ imageItem
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   409
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   410
    "Created: 3.7.1997 / 12:34:34 / cg"
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   411
!
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   412
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   413
imageOnDevice:anImage
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   414
    "associate iamge to device and clear pixel mask (in case of realized);
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   415
     returns the new image.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   416
    "
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   417
    |img|
448
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   418
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   419
    img := anImage onDevice:device.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   420
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   421
    realized ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   422
        img := img clearMaskedPixels
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   423
    ].
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   424
    ^ img
448
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   425
!
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   426
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   427
imageOpened
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   428
    "return the value of the instance variable 'imageOpened' (automatically generated)"
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   429
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   430
    ^ imageOpened
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   431
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   432
    "Created: 3.7.1997 / 12:34:28 / cg"
471
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
   433
! !
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
   434
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   435
!SelectionInTreeView methodsFor:'change & update'!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   436
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   437
update:something with:aParameter from:aModel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   438
    "one of my models changed its value
785
ca
parents: 782
diff changeset
   439
    "
ca
parents: 782
diff changeset
   440
    |idx|
ca
parents: 782
diff changeset
   441
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   442
    aModel == rootHolder ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   443
        ^ self rootFromModel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   444
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   445
    aModel == selectionHolder ifTrue:[
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
   446
        ^ self selectionFromModel   
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   447
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   448
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
   449
    aModel == model ifTrue:[
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
   450
        something == #list ifTrue:[  
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
   451
            ^ self getListFromModel
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
   452
        ]
785
ca
parents: 782
diff changeset
   453
    ] ifFalse:[
ca
parents: 782
diff changeset
   454
        (aModel isKindOf:TreeItem) ifTrue:[
ca
parents: 782
diff changeset
   455
            something == #value ifTrue:[  
ca
parents: 782
diff changeset
   456
                idx := self indexOfNode:aModel.
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
   457
785
ca
parents: 782
diff changeset
   458
                idx ~~ 0 ifTrue:[
ca
parents: 782
diff changeset
   459
                    list at:idx put:(aModel name).
ca
parents: 782
diff changeset
   460
                    self redrawLine:idx
ca
parents: 782
diff changeset
   461
                ].
ca
parents: 782
diff changeset
   462
                ^ self
ca
parents: 782
diff changeset
   463
            ].
ca
parents: 782
diff changeset
   464
            something == #children ifTrue:[
ca
parents: 782
diff changeset
   465
                ^ model recomputeList
ca
parents: 782
diff changeset
   466
            ]
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
   467
        ]
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
   468
    ].
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   469
    ^ super update:something with:aParameter from:aModel.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   470
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   471
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   472
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   473
! !
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   474
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   475
!SelectionInTreeView methodsFor:'drawing'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   476
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   477
drawLine:line atX:atX inVisible:visLineNr with:fg and:bg
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   478
    self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   479
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   480
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   481
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   482
drawLine:line fromX:x inVisible:visLineNr with:fg and:bg
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   483
    self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   484
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   485
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   486
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   487
drawLine:line inVisible:visLineNr with:fg and:bg
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   488
    self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   489
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   490
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   491
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   492
drawVisibleLine:visLineNr col:col with:fg and:bg
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   493
    self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   494
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   495
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   496
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   497
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   498
    self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   499
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   500
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   501
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   502
drawVisibleLine:visLineNr from:startCol with:fg and:bg
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   503
    self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   504
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   505
! !
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   506
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   507
!SelectionInTreeView methodsFor:'drawing basics'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   508
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   509
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   510
    "redraw a visible line range with clearing the background
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   511
    "
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   512
    |y0 y1 sz|
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   513
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   514
    shown ifTrue:[
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   515
        y0  := self yOfVisibleLine:startVisLineNr.
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   516
        y0  := y0 - 1.
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   517
        sz  := endVisLineNr - startVisLineNr + 1.
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   518
        y1  := sz * fontHeight.
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   519
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   520
    "/  clear rectangle line and set background color
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   521
        self paint:bg.
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   522
        self fillRectangleX:0 y:y0 width:width height:y1.
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   523
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   524
        (y1 := self visibleLineToAbsoluteLine:startVisLineNr) notNil ifTrue:[
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   525
            self redrawLinesX:0 y:y0 toX:width start:y1 stop:(y1 + sz)
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   526
        ]
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   527
    ]
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   528
!
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   529
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   530
drawLabelIndex:anIndex atX:x y:yCenter
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   531
    "draw text label at x and y centered
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   532
    "
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   533
    |lbl|
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   534
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   535
    (lbl := (listOfNodes at:anIndex) name) notNil ifTrue:[
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   536
        self displayOpaqueString:lbl x:x y:(yCenter + labelOffsetY).
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   537
    ]    
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   538
!
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   539
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   540
redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   541
    "redraw from line to line without clearing the background
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   542
    "
785
ca
parents: 782
diff changeset
   543
    |node image isSelected defLineColor rnode ext prnt
ca
parents: 782
diff changeset
   544
     x       "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   545
     y       "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   546
     level   "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   547
     yTop    "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   548
     yBot    "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   549
     yCtr    "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   550
     size    "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   551
     end     "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   552
     index   "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   553
     xCross  "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   554
     xFig    "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   555
     xStr    "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   556
     dyLvl   "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   557
     soVDt   "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   558
     soVLn   "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   559
     lv      "{ Class:SmallInteger }"
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   560
     figWidthDiv2 "{ Class:SmallInteger }"
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   561
    |
785
ca
parents: 782
diff changeset
   562
    size         := listOfNodes size.
ca
parents: 782
diff changeset
   563
    index        := start.
ca
parents: 782
diff changeset
   564
    end          := stop min:size.
ca
parents: 782
diff changeset
   565
    level        := -1. "/ to force evaluation of #ifFalse in loop
ca
parents: 782
diff changeset
   566
    soVDt        := 0.
ca
parents: 782
diff changeset
   567
    yTop         := y0.
ca
parents: 782
diff changeset
   568
    yCtr         := yTop - (fontHeight // 2).
ca
parents: 782
diff changeset
   569
    dyLvl        := imageInset + imageWidth.
541
4e7032015683 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   570
    figWidthDiv2 := imageWidth // 2.
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
   571
    figWidthDiv2 odd ifTrue:[figWidthDiv2 := figWidthDiv2 + 1].
785
ca
parents: 782
diff changeset
   572
ca
parents: 782
diff changeset
   573
    showLines ifTrue:[
ca
parents: 782
diff changeset
   574
        soVDt := (figWidthDiv2 + (self xOfFigureLevel:1)) - dyLvl - dyLvl.
ca
parents: 782
diff changeset
   575
        self setMaskOrigin:(self viewOrigin + (0 @ 1) \\ (lineMask extent)).
ca
parents: 782
diff changeset
   576
        defLineColor := lineColor ? fgColor.
ca
parents: 782
diff changeset
   577
    ].
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   578
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   579
    [index <= end] whileTrue:[
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   580
        node := listOfNodes at:index.
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   581
        yBot := yTop + fontHeight.
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   582
        yCtr := yCtr + fontHeight.
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   583
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   584
        (lv := node level) == level ifFalse:[
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   585
            xFig   := self xOfFigureLevel:lv.
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   586
            xStr   := self xOfStringLevel:lv.
785
ca
parents: 782
diff changeset
   587
            xCross := xFig - dyLvl + figWidthDiv2.
ca
parents: 782
diff changeset
   588
            level  := lv.
ca
parents: 782
diff changeset
   589
            soVLn  := lv * dyLvl + soVDt.
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   590
        ].
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   591
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   592
        (isSelected := self isInSelection:index) ifTrue:[
785
ca
parents: 782
diff changeset
   593
            self paint:hilightFgColor on:hilightBgColor
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   594
        ].
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   595
        showLines ifTrue:[
785
ca
parents: 782
diff changeset
   596
            isSelected ifFalse:[
ca
parents: 782
diff changeset
   597
                self paint:defLineColor on:bgColor
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
   598
            ].
80751cda3340 lines as point
ca
parents: 659
diff changeset
   599
            self mask:lineMask.
80751cda3340 lines as point
ca
parents: 659
diff changeset
   600
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   601
            xCross < x1 ifTrue:[
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   602
                (    ((x := xFig + figWidthDiv2) between:x0 and:x1)
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   603
                 and:[node isCollapsable
785
ca
parents: 782
diff changeset
   604
                 and:[node children notEmpty]]
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   605
                ) ifTrue:[
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   606
                    self displayLineFromX:x y:yCtr toX:x y:yBot
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   607
                ].
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   608
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   609
                "/ vertical line from previous to current form
785
ca
parents: 782
diff changeset
   610
                (xCross >= x0 and:[level ~~ 1]) ifTrue:[
ca
parents: 782
diff changeset
   611
                    lv := node parent children last == node ifTrue:[yCtr] ifFalse:[yBot].
ca
parents: 782
diff changeset
   612
                    self displayLineFromX:xCross y:yTop - 1 toX:xCross y:lv
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   613
                ].
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   614
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   615
                "/ horizontal line from previous to current form
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   616
                (     xFig > x0
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   617
                 and:[(level ~~ 1
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   618
                  or:[showDirectoryIndicatorForRoot and:[showDirectoryIndicator]])]
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   619
                ) ifTrue:[
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   620
                    self displayLineFromX:xCross y:yCtr toX:xFig y:yCtr
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   621
                ]
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   622
            ].
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   623
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   624
        "/  draw all vertical lines to left side
785
ca
parents: 782
diff changeset
   625
            (xCross >= x0 and:[(rnode := node parent) notNil]) ifTrue:[
ca
parents: 782
diff changeset
   626
                x := soVLn.
ca
parents: 782
diff changeset
   627
                y := yTop - 1.
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   628
785
ca
parents: 782
diff changeset
   629
                [((prnt := rnode parent) notNil and:[(x := x - dyLvl) >= x0])] whileTrue:[
ca
parents: 782
diff changeset
   630
                    (prnt children last ~~ rnode and:[x <= x1]) ifTrue:[
ca
parents: 782
diff changeset
   631
                        self displayLineFromX:x y:y toX:x y:yBot
ca
parents: 782
diff changeset
   632
                    ].
ca
parents: 782
diff changeset
   633
                    rnode := prnt
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   634
                ]
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
   635
            ].
80751cda3340 lines as point
ca
parents: 659
diff changeset
   636
            self mask:nil.
785
ca
parents: 782
diff changeset
   637
        ].
ca
parents: 782
diff changeset
   638
        isSelected ifFalse:[
ca
parents: 782
diff changeset
   639
            self paint:fgColor on:bgColor
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   640
        ].
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   641
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   642
        "/ draw image
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   643
        (image := self figureFor:node) notNil ifTrue:[
785
ca
parents: 782
diff changeset
   644
            (xFig < x1 and:[xStr > x0]) ifTrue:[
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   645
                self displayForm:image x:xFig y:(yCtr - (image height // 2))
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   646
            ]
541
4e7032015683 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 533
diff changeset
   647
        ].
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   648
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   649
        "/ draw text label
770
f197d1f5a246 fix clipping
ca
parents: 769
diff changeset
   650
        xStr < x1 ifTrue:[
f197d1f5a246 fix clipping
ca
parents: 769
diff changeset
   651
            self drawLabelIndex:index atX:xStr y:yCtr .
f197d1f5a246 fix clipping
ca
parents: 769
diff changeset
   652
        ].
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   653
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   654
        "/ draw directory indicator
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   655
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   656
        (showDirectoryIndicator and:[node showIndicator]) ifTrue:[
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   657
            (level ~~ 1 or:[showDirectoryIndicatorForRoot]) ifTrue:[
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   658
                node isCollapsable ifTrue:[
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   659
                    image := openIndicator.
771
0c57b324cf4d fixed type-mismatches
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   660
                    ext := extentOpenIndicator.
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   661
                ] ifFalse:[
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   662
                    image := closeIndicator.
771
0c57b324cf4d fixed type-mismatches
Claus Gittinger <cg@exept.de>
parents: 770
diff changeset
   663
                    ext := extentCloseIndicator.
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   664
                ].
785
ca
parents: 782
diff changeset
   665
                x := ext x.
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   666
785
ca
parents: 782
diff changeset
   667
                (xCross - x < x1 and:[xCross + x > x0]) ifTrue:[
ca
parents: 782
diff changeset
   668
                    self displayForm:image x:(xCross - x) y:(yCtr - ext y)
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   669
                ]
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
   670
            ]
485
26e87be7210f showDirectoryIndicator
ca
parents: 483
diff changeset
   671
        ].
481
91b3f1788cea redraw mechanism
ca
parents: 480
diff changeset
   672
        "/ setup next line
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   673
        index := index + 1.
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   674
        yTop  := yBot.
769
15fafccfed86 optimize redraw routine
ca
parents: 764
diff changeset
   675
    ]
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   676
!
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   677
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   678
redrawSelFrameForYs:aList fromX:x0 toX:x1
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   679
    "redraw selection frames for each line starting at an absolute 
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   680
     y derived from the argument a list.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   681
    "
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   682
    | 
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   683
     spc "{ Class: SmallInteger }"
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   684
     dY  "{ Class: SmallInteger }"
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   685
     w   "{ Class: SmallInteger }"
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   686
     y   "{ Class: SmallInteger }" 
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   687
     x   "{ Class: SmallInteger }" 
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   688
    |
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   689
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   690
    aList size == 0 ifTrue:[ ^ self ].
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   691
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   692
    strikeOut ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   693
        y := fontHeight // 2.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   694
        self paint:bgColor.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   695
        aList do:[:sY| self displayLineFromX:x0 y:(sY + y) toX:x1 y:(sY + y) ].
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   696
        ^ self
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   697
    ].
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   698
    spc := lineSpacing // 2.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   699
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   700
    hilightFrameColor notNil ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   701
        hilightLevel == 0 ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   702
            dY := fontHeight - 1.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   703
            self paint:hilightFrameColor.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   704
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   705
            aList do:[:sY|
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   706
                y := sY - spc. self displayLineFromX:x0 y:y toX:x1 y:y.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   707
                y := y  + dY.  self displayLineFromX:x0 y:y toX:x1 y:y.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   708
            ]
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   709
        ]
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   710
    ] ifFalse:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   711
        hilightStyle == #motif ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   712
            dY := fontHeight - spc - 2.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   713
            self paint:bgColor.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   714
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   715
            aList do:[:sY|
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   716
                y := sY - spc + 1. self displayLineFromX:x0 y:y toX:x1 y:y.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   717
                y := sY + dY.      self displayLineFromX:x0 y:y toX:x1 y:y.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   718
            ]
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   719
        ]
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   720
    ].
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   721
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   722
    hilightLevel ~~ 0 ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   723
        "/ draw edge
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   724
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   725
        w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   726
        x := margin - leftOffset.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   727
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   728
        aList do:[:sY|
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   729
            self drawEdgesForX:x y:(sY - spc) width:w height:fontHeight level:hilightLevel.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   730
        ]
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   731
    ]
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   732
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   733
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   734
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   735
! !
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   736
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   737
!SelectionInTreeView methodsFor:'enumerating'!
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   738
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   739
detectNode:aOneArgBlock
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   740
    "evaluate the argument, aBlock for each node in the list until
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   741
     the block returns true; in this case return the node which caused
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   742
     the true evaluation. If none node is detected, nil is returned.
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   743
    "
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   744
  ^ listOfNodes detect:aOneArgBlock ifNone:nil
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   745
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   746
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   747
selectedNodesDo:aOneArgBlock
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   748
    "evaluate the block on each node selected
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   749
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
   750
    self selectionDo:[:i| aOneArgBlock value:(listOfNodes at:i) ]
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   751
! !
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
   752
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   753
!SelectionInTreeView methodsFor:'event handling'!
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   754
639
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   755
buttonMotion:buttonMask x:x y:y
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   756
    "mouse-move while button was pressed - handle selection changes"
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   757
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   758
    discardMotionEvents ifFalse:[
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   759
        super buttonMotion:buttonMask x:x y:y
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   760
    ]
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   761
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   762
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   763
!
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   764
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   765
buttonMultiPress:button x:x y:y
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   766
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   767
    (self indicatiorLineForButton:button atX:x y:y) == 0 ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   768
        ^ super buttonMultiPress:button x:x y:y
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   769
    ].
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   770
    "/ discard doubleClick on indicator
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   771
!
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   772
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   773
buttonPress:button x:x y:y
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   774
    "check for indicator
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   775
    "
639
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   776
    |expand node lineNr|
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   777
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   778
    lineNr := self indicatiorLineForButton:button atX:x y:y.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   779
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   780
    lineNr == 0 ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   781
        ^ super buttonPress:button x:x y:y
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   782
    ].
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   783
    node := listOfNodes at:lineNr.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   784
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   785
    (     validateDoubleClickBlock isNil
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   786
     or:[(validateDoubleClickBlock value:node) ~~ false]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   787
    ) ifFalse:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   788
        ^ super buttonPress:button x:x y:y
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   789
    ].
639
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   790
    discardMotionEvents := true.
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   791
    dragIsActive  := false.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   792
    clickPosition := nil.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   793
639
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   794
    self hasSelection ifTrue:[
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   795
        (selectConditionBlock isNil or:[selectConditionBlock value:lineNr]) ifTrue:[
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   796
            self selection:lineNr
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   797
        ] ifFalse:[
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   798
            self selection:nil
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   799
        ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   800
    ].
639
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   801
    self nodeAt:lineNr expand:(node isExpandable).
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   802
639
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   803
!
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   804
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   805
buttonRelease:button x:x y:y
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   806
    "stop any autoscroll"
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   807
639
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   808
    discardMotionEvents ifTrue:[
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   809
        clickPosition := nil.
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   810
        discardMotionEvents := false.
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   811
    ].
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   812
    super buttonRelease:button x:x y:y
663a913ec30b discard motion events if +/- is pressed
ca
parents: 623
diff changeset
   813
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   814
!
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   815
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   816
doubleClicked
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   817
    "handle a double click; collapse or expand selected entry
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   818
     in case of having children
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   819
    "
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   820
    |node|
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   821
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   822
    (node := self selectedNode) notNil ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   823
        (     validateDoubleClickBlock isNil
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   824
         or:[(validateDoubleClickBlock value:node) ~~ false]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   825
        ) ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   826
            self selectedNodeExpand:(node isExpandable).
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   827
            super doubleClicked
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   828
        ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   829
    ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   830
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   831
!
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   832
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   833
indicatiorLineForButton:aButton atX:x y:y
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   834
    "returns linenumber assigned to indicator at x/y or 0
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   835
    "
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   836
    |sensor nr x0 node|
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   837
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   838
    (     enabled
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   839
     and:[showDirectoryIndicator
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   840
     and:[aButton == 1 or:[aButton == #select]]]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   841
    ) ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   842
        sensor := self sensor.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   843
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   844
        (sensor ctrlDown or:[sensor shiftDown]) ifFalse:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   845
            nr := self visibleLineToListLine:(self visibleLineOfY:y).
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   846
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   847
            nr notNil ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   848
                node := listOfNodes at:nr.
785
ca
parents: 782
diff changeset
   849
                node hasChildren ifTrue:[
ca
parents: 782
diff changeset
   850
                    x0   := self xOfFigureLevel:(node level - 1).
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   851
785
ca
parents: 782
diff changeset
   852
                    (x > x0 and:[(x0 + imageWidth) > x and:[node children notEmpty]]) ifTrue:[
ca
parents: 782
diff changeset
   853
                        ^ nr
ca
parents: 782
diff changeset
   854
                    ]
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   855
                ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   856
            ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   857
        ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   858
    ].            
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   859
    ^ 0
785
ca
parents: 782
diff changeset
   860
756
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   861
!
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   862
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   863
key:key select:index x:x y:y
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   864
    "select an entry by a keyboard action. This is treated like a doubleClick
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   865
     on that entry.
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   866
     Add on: In case that the entry is not selectable, scroll to the entry
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   867
    "
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   868
    (enabled and:[keyActionStyle notNil]) ifFalse:[
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   869
        ^ self
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   870
    ].
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   871
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   872
    (selectConditionBlock isNil or:[selectConditionBlock value:index]) ifTrue:[
780
b5e301a1293c missing return
tz
parents: 778
diff changeset
   873
        ^ super key:key select:index x:x y:y
756
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   874
    ].
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   875
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   876
    keyActionStyle == #pass ifTrue:[
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   877
        ^ self
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   878
    ].
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   879
204971de9150 key:key select:index x:x y:y
ca
parents: 695
diff changeset
   880
    self gotoLine:index
785
ca
parents: 782
diff changeset
   881
!
ca
parents: 782
diff changeset
   882
ca
parents: 782
diff changeset
   883
redrawX:x y:y width:w height:h
ca
parents: 782
diff changeset
   884
    "a region must be redrawn"
ca
parents: 782
diff changeset
   885
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   886
    |savClip startLn sel
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   887
     lnSpace  "{ Class:SmallInteger }"
785
ca
parents: 782
diff changeset
   888
     y0       "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   889
     y1       "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   890
     visStart "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   891
     visEnd   "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   892
     stopLn   "{ Class:SmallInteger }"
ca
parents: 782
diff changeset
   893
     maxY     "{ Class:SmallInteger }"
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   894
     maxX     "{ Class:SmallInteger }"
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   895
     dltLine  "{ Class:SmallInteger }"
785
ca
parents: 782
diff changeset
   896
     startY   "{ Class:SmallInteger }"|
ca
parents: 782
diff changeset
   897
ca
parents: 782
diff changeset
   898
    shown ifFalse:[^ self].
ca
parents: 782
diff changeset
   899
ca
parents: 782
diff changeset
   900
    visStart := self visibleLineOfY:(y + 1).
ca
parents: 782
diff changeset
   901
    startLn  := self visibleLineToAbsoluteLine:visStart.
ca
parents: 782
diff changeset
   902
ca
parents: 782
diff changeset
   903
    self paint:bgColor.
ca
parents: 782
diff changeset
   904
    self fillRectangleX:x y:y width:w height:h.
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   905
    startLn isNil ifTrue:[ ^ self ].
785
ca
parents: 782
diff changeset
   906
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   907
    sel     := nil.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   908
    maxX    := x + w.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   909
    maxY    := y + h.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   910
    lnSpace := lineSpacing // 2.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   911
    visEnd  := self visibleLineOfY:maxY.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   912
    startY  := self yOfVisibleLine:visStart.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   913
    dltLine := startLn - visStart.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   914
    stopLn  := dltLine + visEnd.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   915
    savClip := clipRect.
785
ca
parents: 782
diff changeset
   916
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   917
    self clippingRectangle:(Rectangle left:x top:y width:w height:h).
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   918
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   919
    self hasSelection ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   920
        "/ redraw the background for all selected lines in the invalid range
785
ca
parents: 782
diff changeset
   921
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   922
        self selectionDo:[:lnNr|
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   923
            (lnNr between:startLn and:stopLn) ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   924
                sel isNil ifTrue:[
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   925
                    sel := OrderedCollection new.
785
ca
parents: 782
diff changeset
   926
                    self paint:hilightBgColor.
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   927
                ].
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   928
                sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)).
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   929
                y0 := y0 - lnSpace.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   930
                y1 := y0 + fontHeight min:maxY.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   931
                y0 := y0 max:y.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   932
                self fillRectangleX:x y:y0 width:w height:y1 - y0.
785
ca
parents: 782
diff changeset
   933
            ]
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   934
        ]
785
ca
parents: 782
diff changeset
   935
    ].
ca
parents: 782
diff changeset
   936
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   937
    self redrawLinesX:x y:startY - lnSpace toX:maxX start:startLn stop:stopLn.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   938
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   939
    "/ draw selection frames
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   940
    self redrawSelFrameForYs:sel fromX:x toX:maxX.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   941
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   942
    self clippingRectangle:savClip.
5a0af910519e bug fix:
ca
parents: 785
diff changeset
   943
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   944
! !
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   945
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   946
!SelectionInTreeView methodsFor:'initialization'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   947
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
   948
create
80751cda3340 lines as point
ca
parents: 659
diff changeset
   949
    super create.
695
3e5240577e37 dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents: 685
diff changeset
   950
    lineMask := lineMask onDevice:device.
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
   951
80751cda3340 lines as point
ca
parents: 659
diff changeset
   952
    lineColor notNil ifTrue:[
695
3e5240577e37 dont use Image>>on: -> use Image>>onDevice:
Claus Gittinger <cg@exept.de>
parents: 685
diff changeset
   953
        lineColor := lineColor onDevice:device
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
   954
    ]
80751cda3340 lines as point
ca
parents: 659
diff changeset
   955
!
80751cda3340 lines as point
ca
parents: 659
diff changeset
   956
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   957
destroy
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   958
    "remove dependencies
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   959
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   960
    rootHolder notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   961
        rootHolder removeDependent:self
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   962
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   963
    selectionHolder notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   964
        selectionHolder removeDependent:self
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   965
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   966
    super destroy.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   967
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   968
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   969
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
   970
785
ca
parents: 782
diff changeset
   971
fetchDefaultImages
ca
parents: 782
diff changeset
   972
    "returns a directory with default keys and images; could be
ca
parents: 782
diff changeset
   973
     redefined by subclass.
ca
parents: 782
diff changeset
   974
    "
ca
parents: 782
diff changeset
   975
    ^ nil
ca
parents: 782
diff changeset
   976
!
ca
parents: 782
diff changeset
   977
448
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   978
fetchDeviceResources
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   979
    "initialize heavily used device resources - to avoid rendering
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   980
     images again and again later"
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   981
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   982
    super fetchDeviceResources.
478
ca
parents: 471
diff changeset
   983
    self refetchDeviceResources
448
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   984
!
7f9f3531660c cache device images for fast drawing
Claus Gittinger <cg@exept.de>
parents: 446
diff changeset
   985
478
ca
parents: 471
diff changeset
   986
fetchImageResources
ca
parents: 471
diff changeset
   987
    "initialize heavily used device resources - to avoid rendering
ca
parents: 471
diff changeset
   988
     images again and again later; returns maximum extent of the images used.
ca
parents: 471
diff changeset
   989
     Could be redefined by subclass
471
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
   990
    "
785
ca
parents: 782
diff changeset
   991
    |img x y keysAndIcons|
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   992
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   993
    imageOpened isNil ifTrue:[
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   994
        imageOpened := (self class imageOpened) onDevice:device
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   995
    ].
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
   996
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
   997
    imageClosed isNil ifTrue:[
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
   998
        imageClosed := self imageOnDevice:(self class imageClosed)
533
d7867efb6f60 #fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents: 532
diff changeset
   999
    ].
785
ca
parents: 782
diff changeset
  1000
ca
parents: 782
diff changeset
  1001
    x := (imageOpened width)  max:(imageClosed width).
ca
parents: 782
diff changeset
  1002
    y := (imageOpened height) max:(imageClosed height).
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1003
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1004
    imageItem isNil ifTrue:[
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1005
        imageItem := self imageOnDevice:(self class imageItem)
533
d7867efb6f60 #fetchImageResources returned the max extent only on the first invocation
Stefan Vogel <sv@exept.de>
parents: 532
diff changeset
  1006
    ].
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
  1007
785
ca
parents: 782
diff changeset
  1008
    x := (imageItem width)  max:x.
ca
parents: 782
diff changeset
  1009
    y := (imageItem height) max:y.
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
  1010
785
ca
parents: 782
diff changeset
  1011
    (keysAndIcons := self fetchDefaultImages) notNil ifTrue:[
ca
parents: 782
diff changeset
  1012
        keysAndIcons keysAndValuesDo:[:aKey :anIcon|
ca
parents: 782
diff changeset
  1013
            (anIcon isImage and:[aKey notNil]) ifTrue:[
ca
parents: 782
diff changeset
  1014
                registeredImages at:aKey put:(self imageOnDevice:anIcon copy)
ca
parents: 782
diff changeset
  1015
            ]
ca
parents: 782
diff changeset
  1016
        ]
ca
parents: 782
diff changeset
  1017
    ].
ca
parents: 782
diff changeset
  1018
    registeredImages keysAndValuesDo:[:k :img|
ca
parents: 782
diff changeset
  1019
        x := (img width)  max:x.
ca
parents: 782
diff changeset
  1020
        y := (img height) max:y.
ca
parents: 782
diff changeset
  1021
    ].
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
  1022
785
ca
parents: 782
diff changeset
  1023
    (listOfNodes size > 0 and:[(img := listOfNodes first icon) isImage]) ifTrue:[
ca
parents: 782
diff changeset
  1024
        x := (img width)  max:x.
ca
parents: 782
diff changeset
  1025
        y := (img height) max:y.
ca
parents: 782
diff changeset
  1026
    ].
ca
parents: 782
diff changeset
  1027
    ^ x @ y
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1028
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1029
480
982c2ad4f6a2 getFontParameters
ca
parents: 478
diff changeset
  1030
getFontParameters
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1031
    "save old computed height derived from images
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1032
    "
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1033
    |lineHeight|
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1034
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1035
    lineHeight := fontHeight ? 0.
480
982c2ad4f6a2 getFontParameters
ca
parents: 478
diff changeset
  1036
    super getFontParameters.
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1037
    labelOffsetY := fontAscent - (fontHeight - lineSpacing // 2).
480
982c2ad4f6a2 getFontParameters
ca
parents: 478
diff changeset
  1038
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1039
    lineHeight > fontHeight ifTrue:[
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1040
        fontHeight := lineHeight
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1041
    ].
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1042
    fontHeight odd ifTrue:[
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1043
        fontHeight := fontHeight + 1
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1044
    ]
480
982c2ad4f6a2 getFontParameters
ca
parents: 478
diff changeset
  1045
!
982c2ad4f6a2 getFontParameters
ca
parents: 478
diff changeset
  1046
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1047
initialize
471
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
  1048
    "setup instance attributes
6fe41e3caca1 add showLines;
ca
parents: 470
diff changeset
  1049
    "
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1050
    super initialize.
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1051
    self bitGravity:#NorthWest.
773
b3596157f97d register the icons and put them into a caching dict
tz
parents: 771
diff changeset
  1052
    showRoot := showDirectoryIndicatorForRoot      := showLines := computeResources := true.
b3596157f97d register the icons and put them into a caching dict
tz
parents: 771
diff changeset
  1053
    showDirectoryIndicator := discardMotionEvents := false.
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1054
    lineMask := Form width:2 height:2 fromArray:#[16rAA 16r55].
773
b3596157f97d register the icons and put them into a caching dict
tz
parents: 771
diff changeset
  1055
    registeredImages := IdentityDictionary new.
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1056
    textInset  := 4.
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1057
    imageInset := 0.    "/ set during indication enabled
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1058
    imageWidth := 8.    "/ default: will change during startup
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1059
    self model:nil.     "/ creates a default model.
478
ca
parents: 471
diff changeset
  1060
!
ca
parents: 471
diff changeset
  1061
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1062
realize
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1063
    super realize.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1064
    self  refetchDeviceResources.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1065
!
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1066
478
ca
parents: 471
diff changeset
  1067
refetchDeviceResources
ca
parents: 471
diff changeset
  1068
    "reinitialize heavily used device resources - to avoid rendering
ca
parents: 471
diff changeset
  1069
     images again and again later
ca
parents: 471
diff changeset
  1070
    "
551
b9d3ddbc3365 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 546
diff changeset
  1071
    |extent|
478
ca
parents: 471
diff changeset
  1072
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1073
    (realized and:[computeResources and:[listOfNodes size ~~ 0]]) ifTrue:[
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1074
        computeResources := false.
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1075
        extent := self fetchImageResources.
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1076
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1077
        extent y >= fontHeight ifTrue:[
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1078
            fontHeight := 1 + extent y.
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1079
        ].
685
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1080
        fontHeight odd ifTrue:[
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1081
            fontHeight := fontHeight + 1
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1082
        ].
80751cda3340 lines as point
ca
parents: 659
diff changeset
  1083
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1084
        imageWidth := extent x.
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1085
        self recomputeDirectoryIndicator.
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1086
        self computeNumberOfLinesShown.
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1087
    ]
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1088
! !
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1089
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1090
!SelectionInTreeView methodsFor:'model'!
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1091
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1092
getListFromModel
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1093
    "if I have a model, get my list from it using the listMessage.
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1094
     If listMessage is nil, try aspectMessage for backward compatibilty.
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1095
    "
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1096
    super list:(self listFromModel) keepSelection:true
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1097
!
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1098
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1099
listFromModel
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1100
    "get list from model and return the new list.
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1101
     If listMessage is nil, try aspectMessage for backward compatibilty.
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1102
    "
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1103
    |msg|
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1104
468
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1105
    widthOfWidestLine := nil.
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1106
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1107
    (msg := listMsg ? aspectMsg) notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1108
        listOfNodes := model perform:msg.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1109
        listOfNodes size ~~ 0 ifTrue:[
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1110
            self refetchDeviceResources.
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1111
            ^ listOfNodes collect:[:n|n name]
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1112
        ]
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1113
    ].
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1114
    listOfNodes := #().
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1115
  ^ #()
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1116
!
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1117
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1118
model:aModel
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1119
    "check whether model is nil; than a default model is created
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1120
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1121
    |model|
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1122
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1123
    model := aModel ? (SelectionInTree new).
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1124
    model showRoot:showRoot.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1125
    super model:model.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1126
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1127
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1128
rootFromModel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1129
    "update hierarchical list from root model; 'rootHolder'
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1130
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1131
    |root|
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1132
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1133
    root := rootHolder root.
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1134
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1135
    self root == root ifFalse:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1136
        self selection:nil.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1137
        self root:root.
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1138
    ].
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1139
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1140
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1141
selectionFromModel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1142
    "set the selection derived from the selectionHolder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1143
    "
545
d01d14358b07 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 541
diff changeset
  1144
    |coll value sz|
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1145
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1146
    (value := selectionHolder value) isNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1147
        ^ self deselect
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1148
    ].
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1149
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1150
    multipleSelectOk ifFalse:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1151
        self selectNode:value
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1152
    ] ifTrue:[
545
d01d14358b07 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 541
diff changeset
  1153
        (sz := value size) ~~ 0 ifTrue:[
d01d14358b07 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 541
diff changeset
  1154
            coll := OrderedCollection new:sz.
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1155
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1156
            value do:[:aNode||i|
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1157
                (i := self indexOfNode:aNode) notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1158
                    coll add:i
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1159
                ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1160
            ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1161
        ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1162
        coll size == 0 ifTrue:[self deselect]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1163
                      ifFalse:[self selection:coll]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1164
    ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1165
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1166
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1167
selectionToModel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1168
    "write selection to selection holder
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1169
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1170
    |newSel oldSel|
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1171
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1172
    oldSel := selectionHolder value.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1173
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1174
    multipleSelectOk ifFalse:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1175
        (newSel := self selectedNode) ~~ oldSel ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1176
            selectionHolder value:newSel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1177
        ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1178
    ] ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1179
        selection size == 0 ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1180
            oldSel notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1181
                selectionHolder value:nil
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1182
            ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1183
        ] ifFalse:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1184
            newSel := selection collect:[:i| listOfNodes at:i].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1185
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1186
            newSel size ~~ oldSel size ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1187
                selectionHolder value:newSel.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1188
            ] ifFalse:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1189
                newSel do:[:aNode|
785
ca
parents: 782
diff changeset
  1190
                    (oldSel includesIdentical:aNode) ifFalse:[
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1191
                        ^ selectionHolder value:newSel
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1192
                    ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1193
                ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1194
            ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1195
        ]
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1196
    ]
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1197
! !
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1198
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1199
!SelectionInTreeView methodsFor:'private'!
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1200
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1201
list:aList keepSelection:keepSelection
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1202
    "setup new list; keep selection dependent on the boolean state
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1203
     keepSelection
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1204
    "
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1205
    |list|
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1206
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1207
    list := aList.
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1208
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1209
    list size == 0 ifTrue:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1210
        listOfNodes := #()
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1211
    ] ifFalse:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1212
        (list first respondsTo:#hasChildren) ifTrue:[
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1213
            listOfNodes := aList.
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1214
            self refetchDeviceResources.
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1215
            list := listOfNodes collect:[:aNode| aNode name ].
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1216
        ]
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1217
    ].
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1218
    super list:list keepSelection:keepSelection
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1219
!
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1220
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1221
nodeAt:anIndex expand:doExpand
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1222
    "expand or collapse the node at an index, anIndex dependent on the boolean state
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1223
     of doExpand
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1224
    "
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1225
    |node|
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1226
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1227
    node := listOfNodes at:anIndex.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1228
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1229
    node hasChildren ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1230
        node isExpandable ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1231
            doExpand ifFalse:[^ self].
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1232
            node expand
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1233
        ] ifFalse:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1234
            doExpand ifTrue:[^ self].
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1235
            node collapse
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1236
        ].
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1237
785
ca
parents: 782
diff changeset
  1238
        node children isEmpty ifTrue:[
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1239
            "/ no children; redraw selected line (image might change)
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1240
            self redrawLine:anIndex.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1241
        ] ifFalse:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1242
            "/ with children; update list and redraw to end.
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1243
            model removeDependent:self.
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1244
            model recomputeList.
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1245
            model addDependent:self.
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1246
            list := self listFromModel.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1247
            self redrawFromLine:anIndex.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1248
            self contentsChanged.
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1249
        ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1250
    ]
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1251
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1252
!
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1253
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1254
recomputeDirectoryIndicator
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1255
    "setup attributes used by directory indicator
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1256
    "
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1257
    |x1 x2 y|
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1258
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1259
    imageInset := 0.
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1260
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1261
    (showDirectoryIndicator and:[computeResources not]) ifFalse:[
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1262
        ^ self
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1263
    ].
569
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1264
    openIndicator isNil ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1265
        openIndicator  := self imageOnDevice:(self class openIndicator)
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1266
    ].
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1267
    closeIndicator isNil ifTrue:[
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1268
        closeIndicator := self imageOnDevice:(self class closeIndicator)
2a1014d6697c checkin from browser
ca
parents: 552
diff changeset
  1269
    ].
546
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1270
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1271
    x1 := (openIndicator widthOn:self) // 2.
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1272
    y  := openIndicator heightOn:self.
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1273
    extentOpenIndicator := Point x:x1 y:(y // 2).
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1274
    x2 := (closeIndicator widthOn:self) // 2.
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1275
    y  := closeIndicator heightOn:self.
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1276
    extentCloseIndicator := Point x:x2 y:(y // 2).
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1277
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1278
    x2 > x1 ifTrue:[x1 := x2].
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1279
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1280
    (x1 := x1 + self class minImageInset) > (imageWidth // 2) ifTrue:[
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1281
        imageInset := x1 - (imageWidth // 2).
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1282
    ].
8d274d70c2c3 fetch resources only if list of nodes not nil otherwise
ca
parents: 545
diff changeset
  1283
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1284
! !
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1285
468
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1286
!SelectionInTreeView methodsFor:'private queries'!
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1287
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1288
lengthOfLongestLineBetween:firstLine and:lastLine
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1289
    "return the length (in characters) of the longest line in a line-range
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1290
    "
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1291
    |max|
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1292
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1293
    max := self widthOfContents:firstLine and:lastLine.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1294
  ^ (max // fontWidth) + 1
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1295
!
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1296
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1297
widthOfContents
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1298
    "return the width of the contents in pixels
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1299
     - used for scrollbar interface"
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1300
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1301
    list isNil ifTrue:[^ 0].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1302
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1303
    (widthOfWidestLine isNil or:[widthOfWidestLine == 0]) ifTrue:[
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1304
        widthOfWidestLine := self widthOfContents:1 and:(self size).
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1305
    ].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1306
  ^ widthOfWidestLine + (leftMargin * 2)
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1307
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1308
!
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1309
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1310
widthOfContents:firstLine and:lastLine
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1311
    "return the length (in pixels) of the longest line in a line-range
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1312
    "
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1313
    |max      "{ Class: SmallInteger }"
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1314
     thisLen  "{ Class: SmallInteger }"
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1315
     first    "{ Class: SmallInteger }"
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1316
     last     "{ Class: SmallInteger }" |
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1317
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1318
    listOfNodes size == 0 ifTrue:[^ 0].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1319
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1320
    last  := listOfNodes size.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1321
    first := firstLine.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1322
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1323
    (first > last) ifTrue:[^ 0].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1324
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1325
    (lastLine < last) ifTrue:[
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1326
        last := lastLine
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1327
    ].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1328
    max  := 0.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1329
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1330
    listOfNodes from:first to:last do:[:anItem||name|
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1331
        thisLen := self xOfStringNode:anItem.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1332
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1333
        (name := anItem name) notNil ifTrue:[
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1334
            thisLen := thisLen + (name widthOn:self).
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1335
        ].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1336
        (thisLen > max) ifTrue:[
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1337
            max := thisLen.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1338
        ]
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1339
    ].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1340
  ^ max + leftOffset.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1341
!
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1342
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1343
withoutRedrawAt:anIndex put:aString
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1344
    "change a line without redisplay"
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1345
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1346
    |width|
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1347
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1348
    width := widthOfWidestLine.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1349
    widthOfWidestLine := nil.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1350
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1351
    super withoutRedrawAt:anIndex put:aString.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1352
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1353
    (widthOfWidestLine := width) notNil ifTrue:[
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1354
        width := self widthOfContents:anIndex and:anIndex.
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1355
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1356
        width > widthOfWidestLine ifTrue:[
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1357
            widthOfWidestLine := width
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1358
        ] ifFalse:[
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1359
            widthOfWidestLine := nil "/ means: unknown
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1360
        ]
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1361
    ].
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1362
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1363
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1364
! !
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1365
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1366
!SelectionInTreeView methodsFor:'queries'!
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1367
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1368
figureFor:aNode
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1369
    "access figure for a node
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1370
    "
785
ca
parents: 782
diff changeset
  1371
    |icon img|
ca
parents: 782
diff changeset
  1372
ca
parents: 782
diff changeset
  1373
    (icon := aNode icon) notNil ifTrue:[
ca
parents: 782
diff changeset
  1374
        img := registeredImages at:icon ifAbsent:nil.
773
b3596157f97d register the icons and put them into a caching dict
tz
parents: 771
diff changeset
  1375
785
ca
parents: 782
diff changeset
  1376
        img notNil ifTrue:[
ca
parents: 782
diff changeset
  1377
            ^ img
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
  1378
        ].
785
ca
parents: 782
diff changeset
  1379
        icon isImage ifTrue:[
ca
parents: 782
diff changeset
  1380
            img := self imageOnDevice:(icon copy).
ca
parents: 782
diff changeset
  1381
            registeredImages at:icon put:img.
ca
parents: 782
diff changeset
  1382
          ^ img
ca
parents: 782
diff changeset
  1383
        ]
763
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
  1384
    ].
dd29c58e8ea6 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 760
diff changeset
  1385
785
ca
parents: 782
diff changeset
  1386
    "/ fallback solution
ca
parents: 782
diff changeset
  1387
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1388
    aNode hasChildren ifTrue:[
785
ca
parents: 782
diff changeset
  1389
        ^ aNode isExpandable ifTrue:[imageClosed] ifFalse:[imageOpened]
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1390
    ].
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1391
  ^ imageItem
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1392
!
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1393
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1394
indexOfNode:aNode
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1395
    "returns index of a node
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1396
    "
785
ca
parents: 782
diff changeset
  1397
    ^ listOfNodes identityIndexOf:aNode
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1398
!
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1399
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1400
xOfFigureLevel:aLevel
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1401
    "origin x where to draw the icon
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1402
    "
785
ca
parents: 782
diff changeset
  1403
    |l "{ Class:SmallInteger }"|
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1404
785
ca
parents: 782
diff changeset
  1405
    l := showRoot ifTrue:[aLevel] ifFalse:[aLevel - 1].
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1406
659
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1407
    showDirectoryIndicator ifFalse:[
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1408
        l := l - 1
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1409
    ] ifTrue:[
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1410
        showDirectoryIndicatorForRoot ifFalse:[
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1411
            l := l - 1
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1412
        ]
16bb1d26f658 add showDirectoryIndicatorForRoot
ca
parents: 639
diff changeset
  1413
    ].
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1414
  ^ (l * (imageInset + imageWidth)) + imageInset - leftOffset + leftMargin
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1415
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1416
!
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1417
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1418
xOfFigureNode:aNode
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1419
    "origin x where to draw the icon
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1420
    "
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1421
    ^ self xOfFigureLevel:(aNode level)
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1422
!
490
1129f3cf5cea add directory open/close indication
ca
parents: 485
diff changeset
  1423
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1424
xOfStringLevel:aLevel
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1425
    "origin x where to draw the text( label )
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1426
    "
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1427
    ^ (self xOfFigureLevel:aLevel) + imageWidth + textInset
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1428
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1429
!
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1430
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1431
xOfStringNode:aNode
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1432
    "origin x where to draw the text( label )
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1433
    "
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1434
    ^ self xOfStringLevel:(aNode level)
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1435
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1436
! !
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1437
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1438
!SelectionInTreeView methodsFor:'selection'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1439
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1440
selectFromListOfNames:aListOfNames
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1441
    "set selection from a list of names
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1442
    "
785
ca
parents: 782
diff changeset
  1443
    |node rdwNd chgd|
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1444
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1445
    aListOfNames size < 1 ifTrue:[
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1446
        ^ self selection:nil
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1447
    ].
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1448
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1449
    node := model root.
785
ca
parents: 782
diff changeset
  1450
    chgd := false.
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1451
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1452
    aListOfNames do:[:el||next|
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1453
        next := node detectChild:[:e|e name = el].
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1454
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1455
        next notNil ifTrue:[
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1456
            node hidden ifTrue:[
785
ca
parents: 782
diff changeset
  1457
                chgd := true.
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1458
                node expand
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1459
            ].
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1460
            node := next
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1461
        ]
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1462
    ].
785
ca
parents: 782
diff changeset
  1463
    chgd ifTrue:[
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1464
        model recomputeList.
494
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1465
    ].
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1466
    self selectNode:node.
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1467
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1468
!
76d8c4e0b612 directory indicator; set a path to be selected
ca
parents: 490
diff changeset
  1469
468
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1470
selectNode:aNode
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1471
    "change selection to a node
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1472
    "
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1473
    self selection:(self indexOfNode:aNode)
468
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1474
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1475
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1476
!
9c54016f159d support of vertical scrollbar
ca
parents: 456
diff changeset
  1477
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1478
selectedIndex
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1479
    "get single selected index or 0
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1480
    "
483
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1481
    selection size == 1 ifTrue:[^ selection first].
1dad61b63e9d optimize doubleClicked & redrawing
ca
parents: 481
diff changeset
  1482
    selection isNumber  ifTrue:[^ selection].
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1483
  ^ 0
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1484
!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1485
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1486
selectedNode
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1487
    "get the single selected node or nil
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1488
    "
456
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1489
    |idx|
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1490
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1491
    (idx := self selectedIndex) ~~ 0 ifTrue:[
d46a10de4380 change model; supports multiple selection
ca
parents: 448
diff changeset
  1492
        ^ listOfNodes at:idx
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1493
    ].
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1494
  ^ nil
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1495
!
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1496
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1497
selectionChangedFrom:oldSelection
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1498
    "update selectionHolder if not nil
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1499
    "
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1500
623
4de870640523 first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents: 589
diff changeset
  1501
    "/ first change my selectionHolders value ...
514
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1502
    selectionHolder notNil ifTrue:[
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1503
        self selectionToModel.
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1504
    ].
c25e078ed84c add selectionHolder and hierarchical list holder
ca
parents: 507
diff changeset
  1505
623
4de870640523 first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents: 589
diff changeset
  1506
    "/ ... then make notifications.
4de870640523 first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents: 589
diff changeset
  1507
    super selectionChangedFrom:oldSelection.
4de870640523 first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents: 589
diff changeset
  1508
4de870640523 first change selectionHolders value,
Claus Gittinger <cg@exept.de>
parents: 589
diff changeset
  1509
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1510
! !
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1511
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1512
!SelectionInTreeView methodsFor:'selection-actions'!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1513
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1514
selectedNodeAdd:something
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1515
    "add a node or collection of nodes after selected node
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1516
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1517
    |node|
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1518
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1519
    something notNil ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1520
        (node := self selectedNode) notNil ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1521
            node parent notNil ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1522
                node isCollapsable ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1523
                    model add:something beforeIndex:1 below:node
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1524
                ] ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1525
                    model add:something after:node
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1526
                ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1527
            ] ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1528
                model add:something beforeIndex:1 below:(self root)
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1529
            ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1530
        ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1531
    ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1532
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1533
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1534
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1535
selectedNodeBecomeChildOfNext
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1536
    "become node a child of followd node
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1537
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1538
    |idx node cprt nprt|
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1539
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1540
    ((node := self selectedNode) isNil or:[(cprt := node parent) isNil]) ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1541
        idx := cprt indexOfChild:node.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1542
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1543
        idx == cprt children size ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1544
            nprt := cprt childAt:(idx + 1).
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1545
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1546
            nprt notNil ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1547
                model removeDependent:self.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1548
                model removeSelection.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1549
                selection := nil.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1550
                model collapse:nprt.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1551
                model add:node beforeIndex:1 below:nprt.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1552
                model addDependent:self.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1553
                model expand:nprt.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1554
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1555
                self selectNode:node.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1556
            ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1557
        ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1558
    ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1559
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1560
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1561
selectedNodeBecomeSisterOfParent
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1562
    "become node a sister of its current parent
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1563
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1564
    |node cprt nprt|
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1565
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1566
    (    (node := self selectedNode) isNil
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1567
     or:[(cprt := node parent) isNil
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1568
     or:[(nprt := cprt parent) isNil]]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1569
    ) ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1570
        model removeDependent:self.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1571
        model removeSelection.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1572
        selection := nil.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1573
        model addDependent:self.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1574
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1575
        model add:node afterIndex:(nprt indexOfChild:cprt) below:nprt.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1576
        self selectNode:node.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1577
    ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1578
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1579
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1580
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1581
selectedNodeChangeSequenceOrder:anOffset
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1582
    "move child 'anOffset' forward or backward in list of children
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1583
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1584
    |idx node size parent|
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1585
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1586
    (      (node   := self selectedNode) notNil
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1587
      and:[(parent := node parent) notNil
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1588
      and:[(size   := parent children size) > 1]]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1589
    ) ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1590
        idx := parent indexOfChild:node.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1591
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1592
        model removeDependent:self.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1593
        model removeSelection.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1594
        selection := nil.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1595
        model addDependent:self.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1596
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1597
        (idx := idx + anOffset) < 1 ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1598
            idx := size
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1599
        ] ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1600
            idx > size ifTrue:[idx := 1]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1601
        ].
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1602
        model add:node beforeIndex:idx below:parent.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1603
        self selectNode:node.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1604
    ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1605
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1606
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1607
selectedNodeExpand:doExpand
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1608
    "collapse or expand selected node
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1609
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1610
    |node index|
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1611
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1612
    (index := self selectedIndex) ~~ 0 ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1613
        node := listOfNodes at:index.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1614
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1615
        node hasChildren ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1616
            node isExpandable ifTrue:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1617
                doExpand ifFalse:[^ self].
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1618
                node expand
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1619
            ] ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1620
                doExpand ifTrue:[^ self].
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1621
                node collapse
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1622
            ].
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1623
785
ca
parents: 782
diff changeset
  1624
            node children isEmpty ifTrue:[
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1625
                "/ no children; redraw selected line (image might change)
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1626
                self redrawLine:index.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1627
            ] ifFalse:[
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1628
                "/ with children; update list and redraw to end.
585
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1629
                model removeDependent:self.
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1630
                model recomputeList.
5a0ed2305998 bug fixes:
ca
parents: 569
diff changeset
  1631
                model addDependent:self.
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1632
                list := self listFromModel.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1633
                self redrawFromLine:index.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1634
                self contentsChanged.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1635
            ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1636
        ]
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1637
    ].
785
ca
parents: 782
diff changeset
  1638
507
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1639
!
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1640
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1641
selectedNodesRemove
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1642
    "remove selected nodes
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1643
    "
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1644
    model removeSelection.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1645
    self selection:nil.
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1646
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1647
! !
546f43d75275 add more functionality based on selection
ca
parents: 497
diff changeset
  1648
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1649
!SelectionInTreeView class methodsFor:'documentation'!
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1650
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1651
version
792
5a0af910519e bug fix:
ca
parents: 785
diff changeset
  1652
    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.49 1998-02-26 07:43:55 ca Exp $'
444
6d40e2c4ed53 intitial checkin
ca
parents:
diff changeset
  1653
! !