5302
|
1 |
"{ Package: 'stx:libtool' }"
|
|
2 |
|
|
3 |
ToolApplicationModel subclass:#MultiViewToolApplication
|
|
4 |
instanceVariableNames:'workspaces tabList selectedWorkspaceIndexHolder workspaceHolder'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Interface-Smalltalk'
|
|
8 |
!
|
|
9 |
|
|
10 |
!MultiViewToolApplication class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
Common code for multiView applications (Workspace and Terminal app)
|
|
15 |
|
|
16 |
[author:]
|
|
17 |
Claus Gittinger
|
|
18 |
"
|
|
19 |
! !
|
|
20 |
|
|
21 |
!MultiViewToolApplication class methodsFor:'interface specs'!
|
|
22 |
|
|
23 |
windowSpec
|
|
24 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
25 |
|
|
26 |
^ self subclassResponsibility
|
|
27 |
! !
|
|
28 |
|
|
29 |
!MultiViewToolApplication class methodsFor:'menu specs'!
|
|
30 |
|
|
31 |
mainMenu
|
|
32 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
33 |
|
|
34 |
^ self subclassResponsibility
|
|
35 |
!
|
|
36 |
|
|
37 |
tabMenu
|
|
38 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
39 |
|
|
40 |
^ self subclassResponsibility
|
|
41 |
! !
|
|
42 |
|
|
43 |
!MultiViewToolApplication class methodsFor:'queries'!
|
|
44 |
|
|
45 |
isVisualStartable
|
|
46 |
"return true, if this application can be started via #open.
|
|
47 |
(to allow start of a change browser via double-click in the browser)"
|
|
48 |
|
|
49 |
self == MultiViewApplication ifTrue:[^false].
|
|
50 |
^ super isVisualStartable
|
|
51 |
! !
|
|
52 |
|
|
53 |
!MultiViewToolApplication methodsFor:'accessing'!
|
|
54 |
|
|
55 |
selectedWorkspace
|
|
56 |
|wsIndex|
|
|
57 |
|
|
58 |
workspaces isNil ifTrue:[
|
|
59 |
workspaces := OrderedCollection new.
|
|
60 |
].
|
|
61 |
wsIndex := self selectedWorkspaceIndexHolder value.
|
|
62 |
wsIndex == 0 ifTrue:[
|
|
63 |
^ nil
|
|
64 |
].
|
|
65 |
|
|
66 |
workspaces size < wsIndex ifTrue:[
|
|
67 |
workspaces grow:wsIndex.
|
|
68 |
workspaces at:wsIndex put:(self createWorkspace).
|
|
69 |
].
|
|
70 |
^ workspaces at:wsIndex
|
|
71 |
!
|
|
72 |
|
|
73 |
tabMenuAt:index
|
|
74 |
|m i ws|
|
|
75 |
|
|
76 |
m := self class tabMenu.
|
|
77 |
m := m decodeAsLiteralArray.
|
|
78 |
i := m detectItem:[:item | item value == #removeWorkspace:] ifNone:nil.
|
|
79 |
i notNil ifTrue:[
|
|
80 |
i argument:index.
|
|
81 |
index ~~ self selectedWorkspaceIndexHolder value ifTrue:[
|
|
82 |
"/ for now: if that buffer is modified,
|
|
83 |
"/ do not allow removing.
|
|
84 |
"/ (must be brought to front, in order for check-for-modification to work)
|
|
85 |
ws := workspaces at:index.
|
|
86 |
(ws isKindOf:ScrollableView) ifTrue:[
|
|
87 |
ws := ws scrolledView
|
|
88 |
].
|
|
89 |
((ws isKindOf:TextView) not
|
|
90 |
or:[ ws modified ])
|
|
91 |
ifTrue:[
|
|
92 |
i disable
|
|
93 |
].
|
|
94 |
].
|
|
95 |
].
|
|
96 |
i := m detectItem:[:item | item value == #renameWorkspace:] ifNone:nil.
|
|
97 |
i notNil ifTrue:[
|
|
98 |
i argument:index.
|
|
99 |
].
|
|
100 |
|
|
101 |
m findGuiResourcesIn:self.
|
|
102 |
^ m
|
|
103 |
!
|
|
104 |
|
|
105 |
workspaceHolder
|
|
106 |
workspaceHolder isNil ifTrue:[
|
|
107 |
workspaceHolder := ValueHolder with:(self selectedWorkspace).
|
|
108 |
].
|
|
109 |
^ workspaceHolder
|
|
110 |
! !
|
|
111 |
|
|
112 |
!MultiViewToolApplication methodsFor:'aspects'!
|
|
113 |
|
|
114 |
selectedWorkspaceIndexHolder
|
|
115 |
selectedWorkspaceIndexHolder isNil ifTrue:[
|
|
116 |
selectedWorkspaceIndexHolder := 1 asValue.
|
|
117 |
selectedWorkspaceIndexHolder onChangeSend:#workspaceSelectionChanged to:self.
|
|
118 |
].
|
|
119 |
^ selectedWorkspaceIndexHolder.
|
|
120 |
!
|
|
121 |
|
|
122 |
tabList
|
|
123 |
tabList isNil ifTrue:[
|
|
124 |
tabList := List new.
|
|
125 |
].
|
|
126 |
^ tabList.
|
|
127 |
! !
|
|
128 |
|
|
129 |
!MultiViewToolApplication methodsFor:'aspects-queries'!
|
|
130 |
|
|
131 |
canRemoveWorkspace
|
|
132 |
^ self canRemoveWorkspace:(self selectedWorkspaceIndexHolder value)
|
|
133 |
!
|
|
134 |
|
|
135 |
canRemoveWorkspace:idx
|
|
136 |
^ self tabList size > 1
|
|
137 |
"/ and:[ (self workspacesTextViewAt:(self selectedWorkspaceIndexHolder value))
|
|
138 |
!
|
|
139 |
|
|
140 |
hasMultipleBuffersHolder
|
|
141 |
^ [ workspaces size > 1 ]
|
|
142 |
!
|
|
143 |
|
|
144 |
hasSelectionInActiveWorkspace
|
|
145 |
^ self selectedWorkspacesTextView selectionAsString size > 0
|
|
146 |
! !
|
|
147 |
|
|
148 |
!MultiViewToolApplication methodsFor:'menu-actions'!
|
|
149 |
|
|
150 |
addWindow:aWindow named:name
|
|
151 |
^ self addWindow:aWindow named:name asFirst:false
|
|
152 |
!
|
|
153 |
|
|
154 |
addWindow:aWindow named:name asFirst:asFirst
|
|
155 |
|tabList wsIndex newSelectedIndex|
|
|
156 |
|
|
157 |
tabList := self tabList.
|
|
158 |
wsIndex := tabList size + 1.
|
|
159 |
wsIndex == 1 ifTrue:[
|
|
160 |
"/ first - add a name for the first tab
|
|
161 |
tabList add:(self window label). "/ 'Workspace'.
|
|
162 |
wsIndex := wsIndex + 1.
|
|
163 |
].
|
|
164 |
|
|
165 |
workspaces grow:wsIndex.
|
|
166 |
asFirst ifTrue:[
|
|
167 |
tabList addFirst:(name bindWith:wsIndex).
|
|
168 |
workspaces replaceFrom:2 to:wsIndex with:workspaces startingAt:1.
|
|
169 |
newSelectedIndex := 1.
|
|
170 |
] ifFalse:[
|
|
171 |
tabList addLast:(name bindWith:wsIndex).
|
|
172 |
newSelectedIndex := wsIndex.
|
|
173 |
].
|
|
174 |
workspaces at:newSelectedIndex put:aWindow.
|
|
175 |
self selectedWorkspaceIndexHolder value:newSelectedIndex.
|
|
176 |
"/ workspaceHolder value:aWindow.
|
|
177 |
!
|
|
178 |
|
|
179 |
menuSaveAllAs
|
|
180 |
self
|
|
181 |
askForFile:'Save all Buffers into:'
|
|
182 |
thenDo:[:file :doAppend |
|
|
183 |
|ws append|
|
|
184 |
|
|
185 |
append := doAppend.
|
|
186 |
workspaces do:[:subView |
|
|
187 |
|ws|
|
|
188 |
|
|
189 |
ws := self workspaceViewOfView:subView.
|
|
190 |
ws notNil ifTrue:[
|
|
191 |
ws saveAs:file doAppend:append.
|
|
192 |
ws modified:false.
|
|
193 |
].
|
|
194 |
append := true.
|
|
195 |
].
|
|
196 |
]
|
|
197 |
!
|
|
198 |
|
|
199 |
menuSaveAs
|
|
200 |
self
|
|
201 |
askForFile:'Save Buffer into:'
|
|
202 |
thenDo:[:file :doAppend |
|
|
203 |
|ws|
|
|
204 |
|
|
205 |
ws := self selectedWorkspacesTextView.
|
|
206 |
ws saveAs:file doAppend:doAppend.
|
|
207 |
ws modified:false.
|
|
208 |
]
|
|
209 |
!
|
|
210 |
|
|
211 |
newWorkspace
|
|
212 |
self class open
|
|
213 |
!
|
|
214 |
|
|
215 |
removeWorkspace
|
|
216 |
self removeWorkspace:(self selectedWorkspaceIndexHolder value)
|
|
217 |
!
|
|
218 |
|
|
219 |
removeWorkspace:wsIndex
|
|
220 |
|tabList newWsIndex|
|
|
221 |
|
|
222 |
wsIndex == self selectedWorkspaceIndexHolder value ifTrue:[
|
|
223 |
(self askIfModified:'Text was modified. Remove anyway ?' yesButton:'Remove') ifFalse:[
|
|
224 |
^ self
|
|
225 |
].
|
|
226 |
].
|
|
227 |
|
|
228 |
tabList := self tabList.
|
|
229 |
|
|
230 |
wsIndex == tabList size ifTrue:[
|
|
231 |
newWsIndex := wsIndex - 1.
|
|
232 |
] ifFalse:[
|
|
233 |
newWsIndex := wsIndex.
|
|
234 |
].
|
|
235 |
|
|
236 |
tabList removeIndex:wsIndex.
|
|
237 |
(workspaces at:wsIndex) destroy.
|
|
238 |
workspaces removeIndex:wsIndex.
|
|
239 |
|
|
240 |
tabList size == 1 ifTrue:[
|
|
241 |
self window label:(tabList at:1).
|
|
242 |
tabList removeIndex:1
|
|
243 |
].
|
|
244 |
|
|
245 |
workspaceHolder value:(workspaces at:newWsIndex).
|
|
246 |
self selectedWorkspaceIndexHolder value:newWsIndex.
|
|
247 |
"/ to force change (update workspaceHolder - even if same index)
|
|
248 |
self selectedWorkspaceIndexHolder changed:#value.
|
|
249 |
!
|
|
250 |
|
|
251 |
renameWorkspace
|
|
252 |
self renameWorkspace:(self selectedWorkspaceIndexHolder value)
|
|
253 |
!
|
|
254 |
|
|
255 |
renameWorkspace:wsIndex
|
|
256 |
|tabList oldName newName|
|
|
257 |
|
|
258 |
tabList := self tabList.
|
|
259 |
tabList isEmpty ifTrue:[
|
|
260 |
oldName := self window label
|
|
261 |
] ifFalse:[
|
|
262 |
oldName := tabList at:wsIndex.
|
|
263 |
].
|
|
264 |
newName := Dialog request:(resources string:'New Name for %1:' with:oldName) initialAnswer:oldName.
|
|
265 |
newName size == 0 ifTrue:[ ^ self].
|
|
266 |
|
|
267 |
self renameWorkspace:wsIndex to:newName.
|
|
268 |
!
|
|
269 |
|
|
270 |
renameWorkspace:wsIndex to:newName
|
|
271 |
|tabList|
|
|
272 |
|
|
273 |
tabList := self tabList.
|
|
274 |
tabList notEmpty ifTrue:[
|
|
275 |
tabList at:wsIndex put:newName.
|
|
276 |
].
|
|
277 |
wsIndex == self selectedWorkspaceIndexHolder value ifTrue:[
|
|
278 |
self window label:newName.
|
|
279 |
].
|
|
280 |
! !
|
|
281 |
|
|
282 |
!MultiViewToolApplication methodsFor:'menu-actions-editing'!
|
|
283 |
|
|
284 |
copySelection
|
|
285 |
self selectedWorkspacesTextView copySelection
|
|
286 |
!
|
|
287 |
|
|
288 |
cutSelection
|
|
289 |
self selectedWorkspacesTextView cutSelection
|
|
290 |
!
|
|
291 |
|
|
292 |
paste
|
|
293 |
self selectedWorkspacesTextView paste
|
|
294 |
!
|
|
295 |
|
|
296 |
paste:aString
|
|
297 |
self selectedWorkspacesTextView paste:aString.
|
|
298 |
!
|
|
299 |
|
|
300 |
selectAll
|
|
301 |
self selectedWorkspacesTextView selectAll.
|
|
302 |
! !
|
|
303 |
|
|
304 |
!MultiViewToolApplication methodsFor:'private'!
|
|
305 |
|
|
306 |
askForFile:question thenDo:aBlock
|
|
307 |
Dialog
|
|
308 |
requestSaveFileName:(resources string:question)
|
|
309 |
default:'file.wsp'
|
|
310 |
fromDirectory:nil
|
|
311 |
action:[:fileName | aBlock value:fileName value:false]
|
|
312 |
appendAction:[:fileName | aBlock value:fileName value:true]
|
|
313 |
|
|
314 |
"/ |file doAppend|
|
|
315 |
"/
|
|
316 |
"/ doAppend := false.
|
|
317 |
"/ Dialog aboutToOpenBoxNotificationSignal handle:[:n |
|
|
318 |
"/ |box|
|
|
319 |
"/
|
|
320 |
"/ box := n parameter.
|
|
321 |
"/ box addButton:(Button label:'Append' action:[doAppend := true. box okPressed]).
|
|
322 |
"/ n proceed.
|
|
323 |
"/ ] do:[
|
|
324 |
"/ file := Dialog requestFileName:question default:'file.wsp'.
|
|
325 |
"/ ].
|
|
326 |
"/ file isEmptyOrNil ifFalse:[
|
|
327 |
"/ aBlock value:file value:doAppend
|
|
328 |
"/ ].
|
|
329 |
!
|
|
330 |
|
|
331 |
askIfAnyModified:arg1 yesButton:arg2
|
|
332 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
333 |
|
|
334 |
^ self subclassResponsibility
|
|
335 |
!
|
|
336 |
|
|
337 |
askIfModified:question yesButton:yesButtonText
|
|
338 |
"tell user, that code has been modified - let her confirm"
|
|
339 |
|
|
340 |
|textView|
|
|
341 |
|
|
342 |
textView := self selectedWorkspace.
|
|
343 |
(self isModifiedWorkspace:textView) ifFalse:[^ true].
|
|
344 |
|
|
345 |
(Dialog
|
|
346 |
confirm:(resources string:question) withCRs
|
|
347 |
yesLabel:(resources at:yesButtonText)
|
|
348 |
noLabel:(resources at:'Cancel'))
|
|
349 |
ifTrue:[
|
|
350 |
"/ reset modified flag so question is asked only once
|
|
351 |
textView modified:false.
|
|
352 |
^ true
|
|
353 |
].
|
|
354 |
^ false
|
|
355 |
|
|
356 |
"Modified: 2.10.1997 / 14:23:47 / stefan"
|
|
357 |
!
|
|
358 |
|
|
359 |
createWorkspace
|
|
360 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
361 |
|
|
362 |
^ self subclassResponsibility
|
|
363 |
!
|
|
364 |
|
|
365 |
isModifiedWorkspace:aView
|
|
366 |
self subclassResponsibility
|
|
367 |
!
|
|
368 |
|
|
369 |
selectedWorkspacesTextView
|
|
370 |
^ self workspaceViewOfView:(self selectedWorkspace)
|
|
371 |
!
|
|
372 |
|
|
373 |
workspaceSelectionChanged
|
|
374 |
|wsIndex windowLabel v|
|
|
375 |
|
|
376 |
"/ self selected
|
|
377 |
self workspaceHolder value:(v := self selectedWorkspace).
|
|
378 |
wsIndex := self selectedWorkspaceIndexHolder value.
|
|
379 |
|
|
380 |
wsIndex ~~ 0 ifTrue:[
|
|
381 |
windowLabel := tabList at:wsIndex ifAbsent:nil.
|
|
382 |
windowLabel notNil ifTrue:[self window label:windowLabel].
|
|
383 |
].
|
|
384 |
!
|
|
385 |
|
|
386 |
workspaceViewOfView:aView
|
|
387 |
|view|
|
|
388 |
|
|
389 |
view := aView.
|
|
390 |
(view isScrollWrapper) ifTrue:[
|
|
391 |
view := view scrolledView.
|
|
392 |
view isNil ifTrue:[^ nil].
|
|
393 |
].
|
|
394 |
(view isTextView) ifFalse:[
|
|
395 |
(view isKindOf:InspectorView) ifFalse:[
|
|
396 |
^ nil
|
|
397 |
].
|
|
398 |
view := view workspace.
|
|
399 |
(view isScrollWrapper) ifTrue:[
|
|
400 |
view := view scrolledView
|
|
401 |
].
|
|
402 |
].
|
|
403 |
^ view
|
|
404 |
! !
|
|
405 |
|
|
406 |
!MultiViewToolApplication class methodsFor:'documentation'!
|
|
407 |
|
|
408 |
version
|
|
409 |
^ '$Header: /cvs/stx/stx/libtool/MultiViewToolApplication.st,v 1.1 2003-10-22 17:13:29 cg Exp $'
|
|
410 |
! !
|