/
NotebookMorph.class.st
242 lines (194 loc) · 5.6 KB
/
NotebookMorph.class.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
Class {
#name : #NotebookMorph,
#superclass : #TabGroupMorph,
#instVars : [
'headerMorph'
],
#category : #'Spec-MorphicAdapters-Notebook'
}
{ #category : #accessing }
NotebookMorph class >> tabCellInset [
^ 2
]
{ #category : #adding }
NotebookMorph >> addLazyPage: aBlock label: aStringOrMorph [
self
addLazyPage: aBlock
label: aStringOrMorph
collapsable: false
]
{ #category : #adding }
NotebookMorph >> addLazyPage: aBlock label: aStringOrMorph action: anActionMorphOrNil [
| newPage label |
newPage := NotebookPageMorph new.
newPage lazyPageMorphCreation: aBlock.
label := self
buildLabelFrom: aStringOrMorph
withAction: anActionMorphOrNil.
newPage labelMorph: label.
self addPage: newPage label: label
]
{ #category : #adding }
NotebookMorph >> addLazyPage: aBlock label: aStringOrMorph collapsable: aBoolean [
| newPage label |
newPage := NotebookPageMorph new.
newPage lazyPageMorphCreation: aBlock.
label := self
buildLabelFrom: aStringOrMorph
withAction: (aBoolean
ifTrue: [ self newCloseButtonFor: newPage ]
ifFalse: [ nil ]).
newPage labelMorph: label.
self addPage: newPage label: label
]
{ #category : #private }
NotebookMorph >> buildLabelFrom: aString [
^ LabelMorph newLabel: aString
]
{ #category : #private }
NotebookMorph >> buildLabelFrom: aStringOrMorph withAction: aMorph [
| innerLabel |
innerLabel := aStringOrMorph isMorph
ifTrue: [ aStringOrMorph ]
ifFalse: [ self buildLabelFrom: aStringOrMorph ].
^ aMorph
ifNotNil: [
aMorph vResizing: #spaceFill.
PanelMorph new
addMorphBack: innerLabel;
addMorphBack: aMorph;
yourself ]
ifNil: [
innerLabel ]
]
{ #category : #testing }
NotebookMorph >> hasPageWithModel: anObject [
"an utility to easy know if the notebook has a page for a model"
^ self pages anySatisfy: [ :each | each model = anObject ]
]
{ #category : #accessing }
NotebookMorph >> headerMorph [
^ headerMorph
]
{ #category : #accessing }
NotebookMorph >> headerMorph: anObject [
headerMorph := anObject.
headerMorph clipSubmorphs: true.
]
{ #category : #initialization }
NotebookMorph >> initialize [
super initialize.
self
removeMorph: self contentMorph;
removeMorph: self tabSelectorMorph;
headerMorph: self newHeaderMorph;
addMorph: self headerMorph;
addMorph: self contentMorph
]
{ #category : #factory }
NotebookMorph >> newCloseButtonFor: aPage [
^ ButtonPresenter new
icon: (self theme windowCloseForm);
action: [ self removePage: aPage ];
buildWithSpec
]
{ #category : #factory }
NotebookMorph >> newContentMorph [
"Answer a new content morph"
^ PanelMorph new
roundedCorners: #(2 3 4);
changeTableLayout;
layoutInset: 4;
cellInset: 8;
vResizing: #spaceFill;
hResizing: #spaceFill;
borderStyle: (self theme tabPanelBorderStyleFor: self);
yourself
]
{ #category : #private }
NotebookMorph >> newHeaderMorph [
^ (self theme newRowIn: self theme for: { self tabSelectorMorph })
cellInset: 0;
cellPositioning: #bottomCenter;
borderWidth: 0
]
{ #category : #factory }
NotebookMorph >> newTabSelectorMorph [
^ NotebookTabSelectorMorph new
vResizing: #shrinkWrap;
hResizing: #spaceFill;
cellInset: self class tabCellInset;
yourself
]
{ #category : #private }
NotebookMorph >> newToolbarMorph [
^ GLMPanelMorph new
fillStyle: (SolidFillStyle color: Color transparent);
borderStyle: (BorderStyle width: 0);
vResizing: #spaceFill;
hResizing: #shrinkWrap;
cellPositioning: #center;
changeTableLayout;
cellInset: 0;
yourself
]
{ #category : #private }
NotebookMorph >> pageAt: index [
^ (self pages at: index ) actualPageMorph
]
{ #category : #accessing }
NotebookMorph >> pageWithModel: anObject [
"an utility to easy find pages with a model"
^ self pages detect: [ :each | each model = anObject ]
]
{ #category : #private }
NotebookMorph >> removePage: aPage [
| removedPageIndex subscriptions |
removedPageIndex := self pages indexOf: aPage.
self suspendAnnouncementsDuring: [ super removePage: aPage ].
self announcer
announce:
(LazyTabPageRemoved new
tabs: self;
page: aPage;
pageIndex: removedPageIndex;
newIndex: self tabSelectorMorph selectedIndex).
self pages isEmpty ifTrue: [ self contentMorph removeAllMorphs ]
]
{ #category : #private }
NotebookMorph >> removePageIndex: anInteger [
self removePage: (self pages at: anInteger)
]
{ #category : #private }
NotebookMorph >> suspendAnnouncementsDuring: aBlock [
| subscriptions |
subscriptions := self announcer subscriptions subscriptions.
subscriptions do: [ :sub | self announcer unsubscribe: sub ].
aBlock value.
subscriptions do: [ :sub | self announcer basicSubscribe: sub ]
]
{ #category : #private }
NotebookMorph >> updatePageIndex: index [
"Change to the given page index, update the toolbar and send the announcement"
| page oldPage |
index = 0 ifTrue: [ ^ self ].
oldPage := self tabSelectorMorph selectedTab.
page := self pageMorph.
page isNil
ifTrue: [
self contentMorph addMorph: (self pageAt: index).]
ifFalse: [ | pageBounds |
pageBounds := self pageMorph bounds.
self contentMorph replaceSubmorph: page by: (self pageAt: index).
self flag: 'Without setting here the bounds the pange moves a few pizels when refreshing the inspector'.
self pageMorph bounds: pageBounds.
self pageMorph layoutChanged ].
self headerMorph layoutChanged.
self pageMorph layoutChanged.
self adoptPaneColor: (self owner ifNil: [self]) paneColor.
(self tabSelectorMorph tabs at: index) font: self tabSelectorMorph font.
self announcer announce: (NotebookPageChanged new
page: (self pages at: index);
oldPage: oldPage;
pageIndex: index)
]