HierarchicalItem.st
author Jan Vrany <jan.vrany@labware.com>
Fri, 02 Sep 2022 11:25:39 +0100
branchjv
changeset 6261 9b7eb7159d29
parent 5291 31dd692da914
child 5553 d8caa65e2d54
permissions -rw-r--r--
Fix loong standing bug with some menus not being translated / resolved This has happened with browser "View" menu when sometimes it had the slice resolved and sometimes not. It turned out that it was because the code disabled resources (and therefore slices) resolution when processing shortcuts, so the menu was created and cached unresolved. This fixes the issue. eXept apparently run into the same problem.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1431
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     1
"
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     2
 COPYRIGHT (c) 1999 by eXept Software AG
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     3
              All Rights Reserved
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     4
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     5
 This software is furnished under a license and may be used
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     6
 only in accordance with the terms of that license and with the
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     8
 be provided or otherwise made available to, or used by, any
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     9
 other person.  No title to or ownership of the software is
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    10
 hereby transferred.
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    11
"
1794
029df2e76784 *** empty log message ***
ca
parents: 1733
diff changeset
    12
"{ Package: 'stx:libwidg2' }"
029df2e76784 *** empty log message ***
ca
parents: 1733
diff changeset
    13
4697
f44fe2b614a4 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4690
diff changeset
    14
"{ NameSpace: Smalltalk }"
f44fe2b614a4 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4690
diff changeset
    15
4734
d2234ef436c3 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
    16
AbstractHierarchicalItem subclass:#HierarchicalItem
d2234ef436c3 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
    17
	instanceVariableNames:'isExpanded height width'
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
1430
ae9e48cc7b9d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1409
diff changeset
    20
	category:'Views-Support'
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
HierarchicalItem subclass:#Example
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
	instanceVariableNames:'label icon'
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
	classVariableNames:'PenguinIcon'
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	poolDictionaries:''
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
	privateIn:HierarchicalItem
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
!HierarchicalItem class methodsFor:'documentation'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
1431
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    32
copyright
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    33
"
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    34
 COPYRIGHT (c) 1999 by eXept Software AG
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    35
              All Rights Reserved
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    36
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    37
 This software is furnished under a license and may be used
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    38
 only in accordance with the terms of that license and with the
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    39
 inclusion of the above copyright notice.   This software may not
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    40
 be provided or otherwise made available to, or used by, any
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    41
 other person.  No title to or ownership of the software is
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    42
 hereby transferred.
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    43
"
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    44
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    45
!
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    46
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
documentation
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
"
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    Hierarchical Items are mostly like Models, but the list of
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    dependencies are kept by its HierarchicalList.
5291
31dd692da914 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4765
diff changeset
    51
    Instances of (subclasses of) me are used to build up hierarchical trees.
31dd692da914 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4765
diff changeset
    52
    This class is usually subclassed, to add label, icon or value (reference to some info)
31dd692da914 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4765
diff changeset
    53
    to the tree item.
31dd692da914 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4765
diff changeset
    54
    
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    [Instance variables:]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
        parent      <Item, List or nil>         parent or my HierarchicalList.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
        children    <Collection or nil>         list of children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        isExpanded  <Boolean>                   indicates whether the item is
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
                                                expanded or collapsed
4734
d2234ef436c3 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
    60
        width       <Integer>                   cached width of displayed label
d2234ef436c3 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
    61
        height      <Integer>                   cached height of displayed label
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    [author:]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
        Claus Atzkern
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    [see also:]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
        HierarchicalList
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
        HierarchicalListView
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
"
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
4747
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    72
!HierarchicalItem methodsFor:'accessing'!
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    73
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    74
height
4748
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    75
    "return the cached height"
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    76
4747
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    77
    ^ height
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    78
!
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    79
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    80
height:something
4748
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    81
    "set the cached height"
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    82
4747
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    83
    height := something.
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    84
!
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    85
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    86
width
4748
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    87
    "return the cached width"
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    88
4747
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    89
    ^ width
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    90
!
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    91
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    92
width:something
4748
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    93
    "set the cached width"
997f7be95f45 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4747
diff changeset
    94
4747
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    95
    width := something.
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    96
! !
81aeb56b090c class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4734
diff changeset
    97
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
!HierarchicalItem methodsFor:'private'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
4754
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   100
fetchChildren
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   101
    "should compute the list of children via the model.
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   102
     Be aware, that the somewhat stupid 'optimization' of how the model is fetched may lead to
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   103
     a O(n*log n) or even O(n^2) behavior here.
4765
4074c0fef261 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4754
diff changeset
   104
     *** to optimize: redefine #model by subClass"
4754
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   105
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   106
    |model childrenFromModel|
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   107
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   108
    (model := self model) notNil ifTrue:[
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   109
        childrenFromModel := model childrenFor:self
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   110
    ].
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   111
    ^ childrenFromModel
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   112
!
04b1da5a7647 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4748
diff changeset
   113
4734
d2234ef436c3 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
   114
makeWidthAndHeightUnknown
d2234ef436c3 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
   115
    width := height := nil
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
setExpanded:aBoolean
2547
1b75a2c2be7c Hooks for recursive expand
Stefan Vogel <sv@exept.de>
parents: 2519
diff changeset
   119
    "set expanded flag without any computation or notification"
1b75a2c2be7c Hooks for recursive expand
Stefan Vogel <sv@exept.de>
parents: 2519
diff changeset
   120
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    isExpanded := aBoolean
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
2851
fa192ee81bb5 code cleanup
Claus Gittinger <cg@exept.de>
parents: 2847
diff changeset
   124
!HierarchicalItem methodsFor:'protocol-displaying'!
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
heightOn:aGC
4734
d2234ef436c3 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
   127
    "return the height of the receiver, if it is to be displayed on aGC"
3912
b020ebbffa8a comment/format
Claus Gittinger <cg@exept.de>
parents: 3911
diff changeset
   128
1606
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   129
    height isNil ifTrue:[
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   130
        height := self heightOf:(self label) on:aGC
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   131
    ].
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   132
    ^ height
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
widthOn:aGC
3911
d3f85ef940a3 comment/format
Claus Gittinger <cg@exept.de>
parents: 3910
diff changeset
   136
    "return the width of the receiver, if it is to be displayed on aGC"
d3f85ef940a3 comment/format
Claus Gittinger <cg@exept.de>
parents: 3910
diff changeset
   137
1606
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   138
    width isNil ifTrue:[
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   139
        width := self widthOf:(self label) on:aGC
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   140
    ].
b46b9ec4b5d8 cache height and width
ca
parents: 1602
diff changeset
   141
    ^ width
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
!HierarchicalItem methodsFor:'queries'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
isExpanded
2547
1b75a2c2be7c Hooks for recursive expand
Stefan Vogel <sv@exept.de>
parents: 2519
diff changeset
   147
    "returns true if the item is expanded"
1b75a2c2be7c Hooks for recursive expand
Stefan Vogel <sv@exept.de>
parents: 2519
diff changeset
   148
1b75a2c2be7c Hooks for recursive expand
Stefan Vogel <sv@exept.de>
parents: 2519
diff changeset
   149
    ^ isExpanded 
2252
ebcefc9af592 add #sort:
ca
parents: 2230
diff changeset
   150
! !
ebcefc9af592 add #sort:
ca
parents: 2230
diff changeset
   151
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
!HierarchicalItem::Example class methodsFor:'instance creation'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
labeled:aLabel
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
    ^ self new setLabel:aLabel
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
labeled:aLabel icon:anIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    ^ self new setLabel:aLabel icon:anIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
!HierarchicalItem::Example class methodsFor:'resources'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
iconForLevel:aLevel
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
    "returns an icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    aLevel == 2 ifTrue:[ ^ ResourceSelectionBrowser iconPrivateClass ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
    aLevel == 3 ifTrue:[ ^ ResourceSelectionBrowser iconClass ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    aLevel == 4 ifTrue:[ ^ ResourceSelectionBrowser iconCategory ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
  ^ nil
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
penguinIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
    PenguinIcon isNil ifTrue:[
1794
029df2e76784 *** empty log message ***
ca
parents: 1733
diff changeset
   180
        PenguinIcon := Smalltalk imageFromFileNamed:'xpmBitmaps/misc_logos/linux_penguin.xpm'
029df2e76784 *** empty log message ***
ca
parents: 1733
diff changeset
   181
                                 inPackage:'stx:goodies'
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    ^ PenguinIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
!HierarchicalItem::Example methodsFor:'accessing'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
children
2781
062d03cf175e *** empty log message ***
ca
parents: 2724
diff changeset
   189
    |lvl lbl txt image img icon|
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    children notNil ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
        ^ children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    (lvl := self level) == 5 ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
        children := #().
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
      ^ children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    icon     := self class iconForLevel:(lvl + 1).
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    children := OrderedCollection new.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    lvl < 4 ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
        txt := (lvl + 1) printString, ' ['.
2781
062d03cf175e *** empty log message ***
ca
parents: 2724
diff changeset
   204
        img := Icon saveIcon.
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
        1 to:5 do:[:i|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
            (i == 2 or:[i == 3]) ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
                lbl := img
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
            ] ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
                i == 4 ifTrue:[
1540
3fab5658652a support carrige return in labels
Claus Gittinger <cg@exept.de>
parents: 1539
diff changeset
   211
                    lbl := Array with:(self class penguinIcon)
4666
5071574aaec0 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 4542
diff changeset
   212
                                 with:('penguin#and#text' copyReplaceAll:$# with:(Character cr)).
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
                ] ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
                    lbl := txt, (i printString), ']'
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
                ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
            ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
            children add:(self class labeled:lbl icon:icon)
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
        ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    ] ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
        image := ResourceSelectionBrowser iconPrivateClass.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
        txt   := LabelAndIcon icon:image string:'Text'.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
        img   := Icon copyIcon.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
        1 to:5 do:[:i|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
            lbl := i odd ifTrue:[txt] ifFalse:[img].
1398
590a0d3a5ff4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1390
diff changeset
   226
            lbl := Array with:lbl with:'test' with:img.
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
            children add:(self class labeled:lbl icon:icon).
3333
ee578ab4ee94 Example - add editable text
Stefan Vogel <sv@exept.de>
parents: 3173
diff changeset
   228
        ].
ee578ab4ee94 Example - add editable text
Stefan Vogel <sv@exept.de>
parents: 3173
diff changeset
   229
        children add:(self class labeled:'Edit Text').
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    children do:[:aChild| aChild parent:self ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
  ^ children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    "returns the icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    ^ icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
icon:anIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    "set the icon; if icon changed, a notification
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
     is raised.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    icon ~= anIcon ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
        icon := anIcon.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
        self iconChanged
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
label
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    "returns the label
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    ^ label
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
label:aLabel
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    "set the label; if label changed, a notification
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
     is raised.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    label ~= aLabel ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
        label := aLabel.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
        self changed.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
setIcon:anIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    "set the icon without any change notification
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    icon := anIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
setLabel:aLabel
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
    "set the label without any change notification
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
    label := aLabel
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
setLabel:aLabel icon:anIcon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
    "set the label and icon without any change notification
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
    label := aLabel.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
    icon  := anIcon.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
!HierarchicalItem class methodsFor:'documentation'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
version
5291
31dd692da914 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4765
diff changeset
   292
    ^ '$Header$'
3849
05e3fe811288 changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents: 3716
diff changeset
   293
!
05e3fe811288 changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents: 3716
diff changeset
   294
05e3fe811288 changed comment in: #fontChanged
Stefan Vogel <sv@exept.de>
parents: 3716
diff changeset
   295
version_CVS
5291
31dd692da914 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4765
diff changeset
   296
    ^ '$Header$'
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
! !
4188
57e4733cf628 class: HierarchicalItem
Claus Gittinger <cg@exept.de>
parents: 3983
diff changeset
   298