forked from bonzini/gst-visualgst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GtkNotebookWidget.st
152 lines (113 loc) · 3.75 KB
/
GtkNotebookWidget.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
GtkConcreteWidget subclass: GtkNotebookWidget [
| currentWidget selectMessage notebook pages labels |
initialize [
<category: 'initialization'>
labels := OrderedCollection new.
pages := OrderedCollection new.
self mainWidget: self buildNotebookWidget
]
buildNotebookWidget [
<category: 'user interface'>
^ notebook := GTK.GtkNotebook new
connectSignal: 'switch-page'
to: self
selector: #'switchPageOn:page:number:'
userData: nil;
setShowTabs: false;
yourself
]
whenSelectionChangedSend: aSymbol to: anObject [
selectMessage := DirectedMessage receiver: anObject selector: aSymbol arguments: #()
]
addWidget: aWidget labeled: aString [
<category: 'user interface'>
self addWidget: aWidget labelWidget: (self buildLabelWidget: aString withIcon: GTK.Gtk gtkStockClose at: aWidget)
]
updateWidget: aWidget withLabel: aString [
<category: 'user interface'>
notebook setTabLabel: aWidget mainWidget tabLabel: (self buildLabelWidget: aString withIcon: GTK.Gtk gtkStockClose at: aWidget)
]
addPermanentWidget: aWidget labeled: aString [
<category: 'user interface'>
self addWidget: aWidget labelWidget: (labels add: (GTK.GtkLabel new: aString))
]
addWidget: aWidget labelWidget: aLabelWidget [
<category: 'user interface'>
currentWidget ifNil: [ currentWidget := aWidget ].
pages addLast: aWidget.
notebook
appendPage: aWidget mainWidget tabLabel: aLabelWidget.
pages size > 1 ifTrue: [ notebook setShowTabs: true ]
]
buildLabelWidget: aString withIcon: aStockString at: aSmallInteger [
<category: 'user interface'>
| image close |
image := GTK.GtkImage newFromStock: aStockString size: GTK.Gtk gtkIconSizeMenu.
close := (GTK.GtkButton new)
setImage: image;
setRelief: GTK.Gtk gtkReliefNone;
connectSignal: 'pressed' to: self selector: #'closeIt:at:' userData: aSmallInteger;
yourself.
^ (GTK.GtkHBox new: false spacing: 0)
add: (labels add: (GTK.GtkLabel new: aString));
add: close;
showAll;
yourself
]
switchPageOn: aGtkNotebook page: aGtkNotebookPage number: anInteger [
<category: 'notebook events'>
currentWidget := pages at: anInteger + 1.
selectMessage ifNotNil: [ selectMessage send ]
]
closeIt: aGtkButton at: aGtkConcreteWidget [
<category: 'notebook events'>
| pageNb |
pageNb := notebook pageNum: aGtkConcreteWidget mainWidget.
aGtkConcreteWidget close.
pages removeAtIndex: pageNb + 1.
labels removeAtIndex: pageNb + 1.
notebook removePage: pageNb.
pages size = 1 ifTrue: [ notebook setShowTabs: false ]
]
widgetAt: anInteger [
<category: 'accessing'>
^ pages at: anInteger
]
currentWidget [
<category: 'accessing'>
^ currentWidget
]
focusedWidget [
<category: 'accessing'>
^ currentWidget focusedWidget
]
currentPage [
<category: 'pages'>
^ notebook getCurrentPage
]
currentPage: aSmallInteger [
<category: 'pages'>
notebook setCurrentPage: aSmallInteger
]
showLastPage [
<category: 'pages'>
self currentPage: self numberOfPages - 1
]
numberOfPages [
<category: 'pages'>
^ notebook getNPages
]
closeCurrentPage [
<category: 'pages'>
self numberOfPages = 1 ifTrue: [ ^ self ].
pages removeAtIndex: self currentPage + 1.
labels removeAtIndex: self currentPage + 1.
notebook removePage: self currentPage.
pages size = 1 ifTrue: [ notebook setShowTabs: false ]
]
showPane [
<category: 'widget'>
notebook showAll.
pages do: [ :each | each postInitialize ]
]
]