36
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
45
|
3 |
All Rights Reserved
|
36
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
StandardSystemView subclass:#FileBrowser
|
45
|
14 |
instanceVariableNames:'labelView filterField fileListView subView
|
|
15 |
currentDirectory
|
|
16 |
fileList
|
|
17 |
checkBlock checkDelta timeOfLastCheck
|
|
18 |
showLongList showVeryLongList showDotFiles
|
|
19 |
myName killButton compressTabs lockUpdate'
|
|
20 |
classVariableNames:'DirectoryHistory HistorySize'
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Interface-Browsers'
|
36
|
23 |
!
|
|
24 |
|
|
25 |
FileBrowser comment:'
|
|
26 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
45
|
27 |
All Rights Reserved
|
36
|
28 |
|
47
|
29 |
$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.18 1994-10-10 03:33:24 claus Exp $
|
36
|
30 |
'!
|
|
31 |
|
|
32 |
!FileBrowser class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
copyright
|
|
35 |
"
|
|
36 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
45
|
37 |
All Rights Reserved
|
36
|
38 |
|
|
39 |
This software is furnished under a license and may be used
|
|
40 |
only in accordance with the terms of that license and with the
|
|
41 |
inclusion of the above copyright notice. This software may not
|
|
42 |
be provided or otherwise made available to, or used by, any
|
|
43 |
other person. No title to or ownership of the software is
|
|
44 |
hereby transferred.
|
|
45 |
"
|
|
46 |
!
|
|
47 |
|
|
48 |
version
|
|
49 |
"
|
47
|
50 |
$Header: /cvs/stx/stx/libtool/Attic/FBrowser.st,v 1.18 1994-10-10 03:33:24 claus Exp $
|
36
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
documentation
|
|
55 |
"
|
|
56 |
this used to be a very simple demo application,
|
|
57 |
but migrated into a quite nice tool, includes all kinds of
|
|
58 |
warning and information boxes, background processes for directory-
|
|
59 |
reading and internationalized strings. A good example for beginners,
|
|
60 |
on how to do things ....
|
|
61 |
See additional information in 'doc/misc/fbrowser.doc'.
|
45
|
62 |
|
|
63 |
instancevariables of interrest:
|
|
64 |
|
|
65 |
checkDelta <Integer> number of seconds of check interval
|
|
66 |
(looks ever so often if shown directory
|
|
67 |
has changed). You may make this number
|
|
68 |
higher, if your network-times are
|
|
69 |
incorrect and thus, the filebrowser
|
|
70 |
checks too often.
|
|
71 |
|
|
72 |
compressTabs <Boolean> if true, leading spaces will be
|
|
73 |
replaced by tabs when saving text
|
36
|
74 |
"
|
|
75 |
! !
|
|
76 |
|
|
77 |
!FileBrowser class methodsFor:'instance creation'!
|
|
78 |
|
|
79 |
openOn:aDirectoryPath
|
|
80 |
"start a new FileBrowser in a pathname"
|
|
81 |
|
|
82 |
^ (self new currentDirectory:aDirectoryPath) open
|
|
83 |
|
|
84 |
"FileBrowser openOn:'aDirectoryPath'"
|
|
85 |
! !
|
|
86 |
|
|
87 |
!FileBrowser methodsFor:'initialization'!
|
|
88 |
|
|
89 |
initialize
|
45
|
90 |
|frame spacing halfSpacing v cutOff topFrame labelFrame|
|
36
|
91 |
|
|
92 |
super initialize.
|
|
93 |
|
45
|
94 |
compressTabs := true.
|
|
95 |
lockUpdate := false.
|
|
96 |
|
36
|
97 |
DirectoryHistory isNil ifTrue:[
|
45
|
98 |
DirectoryHistory := OrderedCollection new.
|
|
99 |
HistorySize := 15.
|
36
|
100 |
].
|
|
101 |
|
|
102 |
myName := (resources string:self class name).
|
|
103 |
self label:myName.
|
|
104 |
self icon:(Form fromFile:(resources at:'ICON_FILE' default:'FBrowser.xbm')
|
45
|
105 |
resolution:100).
|
|
106 |
|
|
107 |
labelFrame := View origin:(0.0 @ 0.0)
|
|
108 |
corner:(1.0 @ (font height * 2))
|
|
109 |
in:self.
|
|
110 |
StyleSheet name = #st80 ifTrue:[
|
|
111 |
labelFrame level:1
|
|
112 |
].
|
36
|
113 |
|
|
114 |
spacing := ViewSpacing.
|
|
115 |
halfSpacing := spacing // 2.
|
|
116 |
|
45
|
117 |
StyleSheet is3D ifFalse:[
|
|
118 |
cutOff := halfSpacing
|
|
119 |
] ifTrue:[
|
|
120 |
cutOff := 0
|
|
121 |
].
|
|
122 |
|
36
|
123 |
checkBlock := [self checkIfDirectoryHasChanged].
|
45
|
124 |
checkDelta := resources at:'CHECK_DELTA' default:10.
|
36
|
125 |
|
|
126 |
currentDirectory := FileDirectory directoryNamed:'.'.
|
|
127 |
showLongList := resources at:'LONG_LIST' default:false.
|
|
128 |
showDotFiles := resources at:'SHOW_DOT_FILES' default:false.
|
|
129 |
|
45
|
130 |
filterField := EditField in:labelFrame.
|
36
|
131 |
filterField origin:[((width // 4 * 3) + halfSpacing) @ halfSpacing]
|
45
|
132 |
corner:(1.0 @ filterField heightIncludingBorder).
|
|
133 |
filterField rightInset:ViewSpacing-halfSpacing.
|
|
134 |
|
36
|
135 |
self initializeFilterPattern.
|
|
136 |
filterField leaveAction:[:key | fileListView scrollToTop. self updateCurrentDirectory].
|
|
137 |
|
45
|
138 |
labelView := Label in:labelFrame.
|
36
|
139 |
labelView origin:(halfSpacing @ halfSpacing)
|
45
|
140 |
extent:[((width // 4 * 3) - spacing - borderWidth)
|
|
141 |
@
|
|
142 |
(filterField heightIncludingBorder)
|
|
143 |
"(font height + font descent)"
|
|
144 |
].
|
36
|
145 |
labelView adjust:#right.
|
|
146 |
labelView borderWidth:0.
|
|
147 |
self initializeLabelMiddleButtonMenu.
|
45
|
148 |
labelFrame middleButtonMenu:(labelView middleButtonMenu).
|
|
149 |
|
36
|
150 |
|
|
151 |
killButton := Button label:(resources string:'kill') in:self.
|
|
152 |
killButton origin:(halfSpacing @ halfSpacing)
|
45
|
153 |
extent:(killButton width @ filterField height).
|
36
|
154 |
killButton hidden:true.
|
|
155 |
|
|
156 |
frame := VariableVerticalPanel
|
45
|
157 |
origin:[frame borderWidth negated
|
|
158 |
@
|
|
159 |
labelFrame height
|
|
160 |
"/ (labelView height + labelView origin y + spacing)
|
|
161 |
]
|
|
162 |
corner:(1.0 @ 1.0)
|
|
163 |
in:self.
|
36
|
164 |
|
|
165 |
topFrame := ScrollableView for:SelectionInListView in:frame.
|
|
166 |
topFrame origin:(0.0 @ 0.0) corner:(1.0 @ 0.3).
|
|
167 |
|
|
168 |
fileListView := topFrame scrolledView.
|
|
169 |
fileListView action:[:lineNr | self fileSelect:lineNr].
|
|
170 |
fileListView doubleClickAction:[:lineNr | self fileSelect:lineNr.
|
45
|
171 |
self fileGet].
|
36
|
172 |
fileListView multipleSelectOk:true.
|
|
173 |
|
|
174 |
v := self initializeSubViewIn:frame.
|
|
175 |
v origin:(0.0 @ 0.3) corner:(1.0 @ 1.0).
|
|
176 |
subView := v scrolledView.
|
|
177 |
(subView respondsTo:#directoryForFileDialog:) ifTrue:[
|
45
|
178 |
subView directoryForFileDialog:currentDirectory
|
36
|
179 |
].
|
|
180 |
|
|
181 |
ObjectMemory addDependent:self.
|
|
182 |
!
|
|
183 |
|
45
|
184 |
initEvents
|
|
185 |
self enableEvent:#visibilityChange.
|
|
186 |
!
|
|
187 |
|
36
|
188 |
initializeFilterPattern
|
|
189 |
"set an initial matchpattern - can be redefined in subclasses"
|
|
190 |
|
|
191 |
filterField contents:'*'
|
|
192 |
!
|
|
193 |
|
|
194 |
initializeSubViewIn:frame
|
|
195 |
"set up the contents view - can be redefined in subclasses for
|
|
196 |
different view types (SoundFileBrowser/ImageBrowsers etc.)"
|
|
197 |
|
|
198 |
^ HVScrollableView for:CodeView miniScrollerH:true miniScrollerV:false in:frame.
|
|
199 |
!
|
|
200 |
|
|
201 |
currentDirectory:aDirectoryPath
|
|
202 |
"set the directory to be browsed"
|
|
203 |
|
|
204 |
currentDirectory := FileDirectory directoryNamed:aDirectoryPath.
|
|
205 |
(subView respondsTo:#directoryForFileDialog:) ifTrue:[
|
45
|
206 |
subView directoryForFileDialog:currentDirectory
|
36
|
207 |
]
|
|
208 |
!
|
|
209 |
|
|
210 |
realize
|
|
211 |
self initializeFileListMiddleButtonMenu.
|
|
212 |
super realize.
|
|
213 |
"/ self updateCurrentDirectory
|
|
214 |
!
|
|
215 |
|
|
216 |
initializeLabelMiddleButtonMenu
|
|
217 |
|labels selectors args|
|
|
218 |
|
|
219 |
labelView notNil ifTrue:[
|
45
|
220 |
labels := resources array:#(
|
|
221 |
'copy path'
|
|
222 |
'-'
|
|
223 |
'up'
|
|
224 |
'change to home-directory'
|
|
225 |
'change directory ...'
|
|
226 |
).
|
36
|
227 |
|
45
|
228 |
selectors := #(
|
|
229 |
copyPath
|
|
230 |
nil
|
|
231 |
changeToParentDirectory
|
|
232 |
changeToHomeDirectory
|
|
233 |
changeCurrentDirectory
|
|
234 |
).
|
36
|
235 |
|
45
|
236 |
args := Array new:5.
|
36
|
237 |
|
45
|
238 |
DirectoryHistory size > 0 ifTrue:[
|
|
239 |
labels := labels copyWith:'-'.
|
|
240 |
selectors := selectors copyWith:nil.
|
|
241 |
args := args copyWith:nil.
|
36
|
242 |
|
45
|
243 |
DirectoryHistory do:[:dirName |
|
|
244 |
labels := labels copyWith:dirName.
|
|
245 |
selectors := selectors copyWith:#changeDirectoryTo:.
|
|
246 |
args := args copyWith:dirName
|
|
247 |
]
|
|
248 |
].
|
36
|
249 |
|
45
|
250 |
labelView
|
|
251 |
middleButtonMenu:(PopUpMenu
|
|
252 |
labels:labels
|
|
253 |
selectors:selectors
|
|
254 |
args:args
|
|
255 |
receiver:self
|
|
256 |
for:labelView).
|
36
|
257 |
|
|
258 |
|
|
259 |
]
|
|
260 |
!
|
|
261 |
|
|
262 |
initializeFileListMiddleButtonMenu
|
|
263 |
|labels|
|
|
264 |
|
|
265 |
fileListView notNil ifTrue:[
|
45
|
266 |
labels := resources array:#(
|
|
267 |
'spawn'
|
|
268 |
'get contents'
|
|
269 |
'show info'
|
|
270 |
'show full info'
|
|
271 |
'fileIn'
|
|
272 |
'-'
|
|
273 |
'update'
|
|
274 |
'-'
|
|
275 |
'execute unix command ...'
|
|
276 |
'-'
|
|
277 |
'remove'
|
|
278 |
'rename ...'
|
|
279 |
'-'
|
|
280 |
'display long list'
|
|
281 |
'show all files'
|
|
282 |
'-'
|
|
283 |
'create directory ...'
|
|
284 |
'create file ...').
|
36
|
285 |
|
45
|
286 |
fileListView
|
|
287 |
middleButtonMenu:(PopUpMenu
|
|
288 |
labels:labels
|
|
289 |
selectors:#(fileSpawn
|
|
290 |
fileGet
|
|
291 |
fileGetInfo
|
|
292 |
fileGetLongInfo
|
|
293 |
fileFileIn
|
|
294 |
nil
|
|
295 |
updateCurrentDirectory
|
|
296 |
nil
|
|
297 |
fileExecute
|
|
298 |
nil
|
|
299 |
fileRemove
|
|
300 |
fileRename
|
|
301 |
nil
|
|
302 |
changeDisplayMode
|
|
303 |
changeDotFileVisibility
|
|
304 |
nil
|
|
305 |
newDirectory
|
|
306 |
newFile)
|
|
307 |
receiver:self
|
|
308 |
for:fileListView)
|
|
309 |
]
|
|
310 |
! !
|
|
311 |
|
|
312 |
!FileBrowser methodsFor:'events'!
|
|
313 |
|
|
314 |
mapped
|
|
315 |
super mapped.
|
|
316 |
"
|
|
317 |
whant to know about changed history
|
|
318 |
"
|
|
319 |
DirectoryHistory addDependent:self.
|
|
320 |
self updateCurrentDirectory
|
|
321 |
!
|
|
322 |
|
|
323 |
visibilityChange:how
|
|
324 |
|wasVisible|
|
|
325 |
|
|
326 |
wasVisible := shown.
|
|
327 |
super visibilityChange:how.
|
|
328 |
(wasVisible not and:[shown]) ifTrue:[
|
|
329 |
"
|
|
330 |
start checking again
|
|
331 |
"
|
|
332 |
Processor removeTimedBlock:checkBlock.
|
|
333 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta.
|
36
|
334 |
]
|
|
335 |
! !
|
|
336 |
|
|
337 |
!FileBrowser methodsFor:'private'!
|
|
338 |
|
|
339 |
showAlert:aString with:anErrorString
|
|
340 |
"show an alertbox, displaying the last Unix-error"
|
|
341 |
|
|
342 |
anErrorString isNil ifTrue:[
|
45
|
343 |
self warn:aString withCRs
|
36
|
344 |
] ifFalse:[
|
45
|
345 |
self warn:(aString , '\\(' , anErrorString , ')' ) withCRs
|
36
|
346 |
]
|
|
347 |
!
|
|
348 |
|
|
349 |
ask:question yesButton:yesButtonText action:aBlock
|
|
350 |
"common method to ask a yes/no question"
|
|
351 |
|
|
352 |
self ask:question yesButton:yesButtonText noButton:'abort' action:aBlock
|
|
353 |
!
|
|
354 |
|
|
355 |
ask:question yesButton:yesButtonText noButton:noButtonText action:aBlock
|
|
356 |
"common method to ask a yes/no question"
|
|
357 |
|
37
|
358 |
|yesNoBox|
|
|
359 |
|
|
360 |
yesNoBox := YesNoBox new.
|
36
|
361 |
yesNoBox title:question withCRs.
|
|
362 |
yesNoBox okText:(resources at:yesButtonText).
|
|
363 |
yesNoBox noText:(resources at:noButtonText).
|
|
364 |
yesNoBox okAction:aBlock.
|
|
365 |
yesNoBox showAtPointer
|
|
366 |
!
|
|
367 |
|
|
368 |
askIfModified:question yesButton:yesButtonText action:aBlock
|
|
369 |
"tell user, that code has been modified - let her confirm"
|
|
370 |
|
|
371 |
(subView modified not or:[subView contentsWasSaved]) ifTrue:[
|
45
|
372 |
aBlock value.
|
|
373 |
^ self
|
36
|
374 |
].
|
|
375 |
self ask:question yesButton:yesButtonText action:aBlock
|
|
376 |
!
|
|
377 |
|
|
378 |
withoutHiddenFiles:aCollection
|
|
379 |
"remove hidden files (i.e. those that start with '.') from
|
|
380 |
the list in aCollection"
|
|
381 |
|
|
382 |
|newCollection|
|
|
383 |
|
|
384 |
newCollection := aCollection species new.
|
|
385 |
aCollection do:[:fname |
|
45
|
386 |
((fname startsWith:'.') and:[(fname = '..') not]) ifTrue:[
|
|
387 |
showDotFiles ifTrue:[
|
|
388 |
newCollection add:fname
|
|
389 |
]
|
|
390 |
] ifFalse:[
|
|
391 |
newCollection add:fname
|
|
392 |
]
|
36
|
393 |
].
|
|
394 |
^ newCollection
|
|
395 |
!
|
|
396 |
|
|
397 |
getInfoFile
|
|
398 |
"get filename of a description-file (.dir.info);
|
|
399 |
uncomment stuff below if you want this to also
|
|
400 |
automatically show contents of README files."
|
|
401 |
|
|
402 |
#( '.dir.info'
|
|
403 |
"you can add these if you like ..."
|
|
404 |
"
|
|
405 |
'README'
|
|
406 |
'ReadMe'
|
|
407 |
'Readme'
|
|
408 |
'readme'
|
|
409 |
"
|
|
410 |
) do:[:f |
|
45
|
411 |
(currentDirectory isReadable:f) ifTrue:[^ f].
|
36
|
412 |
].
|
|
413 |
^ nil
|
|
414 |
!
|
|
415 |
|
|
416 |
showInfo:info
|
|
417 |
"show directory info when dir has changed"
|
|
418 |
|
|
419 |
info notNil ifTrue:[
|
45
|
420 |
self show:(self readFile:info)
|
36
|
421 |
] ifFalse:[
|
45
|
422 |
self show:nil.
|
36
|
423 |
]
|
|
424 |
!
|
|
425 |
|
|
426 |
getSelectedFileName
|
|
427 |
"returns the currently selected file; shows an error if
|
|
428 |
multiple files are selected"
|
|
429 |
|
|
430 |
|sel|
|
|
431 |
|
|
432 |
sel := fileListView selection.
|
|
433 |
(sel isKindOf:Collection) ifTrue:[
|
45
|
434 |
self onlyOneSelection
|
36
|
435 |
] ifFalse:[
|
45
|
436 |
sel notNil ifTrue:[
|
|
437 |
^ fileList at:sel
|
|
438 |
]
|
36
|
439 |
].
|
|
440 |
^ nil
|
|
441 |
!
|
|
442 |
|
|
443 |
getFileInfoString:longInfo
|
|
444 |
"get stat info on selected file - return a string which can be
|
|
445 |
shown in a box"
|
|
446 |
|
|
447 |
|fileName fullPath text info stream fileOutput type modeBits modeString s|
|
|
448 |
|
|
449 |
fileName := self getSelectedFileName.
|
|
450 |
fileName isNil ifTrue:[^ nil].
|
|
451 |
|
|
452 |
info := currentDirectory infoOf:fileName.
|
|
453 |
info isNil ifTrue:[
|
45
|
454 |
self showAlert:(resources string:'cannot get info of ''%1'' !!' with:fileName)
|
|
455 |
with:(OperatingSystem lastErrorString).
|
|
456 |
^ nil
|
36
|
457 |
].
|
|
458 |
|
|
459 |
text := Text new.
|
|
460 |
type := info at:#type.
|
|
461 |
(longInfo and:[type == #regular]) ifTrue:[
|
45
|
462 |
fullPath := currentDirectory pathName , '/' , fileName.
|
|
463 |
stream := PipeStream readingFrom:('file ' , fullPath).
|
|
464 |
stream notNil ifTrue:[
|
|
465 |
fileOutput := stream contents asString.
|
|
466 |
stream close.
|
|
467 |
fileOutput := fileOutput copyFrom:(fileOutput indexOf:$:) + 1.
|
|
468 |
fileOutput := fileOutput withoutSeparators
|
|
469 |
]
|
36
|
470 |
].
|
|
471 |
|
|
472 |
s := (resources at:'type: ').
|
|
473 |
fileOutput isNil ifTrue:[
|
45
|
474 |
s := s , type asString
|
36
|
475 |
] ifFalse:[
|
45
|
476 |
s := s , 'regular (' , fileOutput , ')'
|
36
|
477 |
].
|
|
478 |
text add:s.
|
|
479 |
text add:(resources at:'size: ') , (info at:#size) printString.
|
|
480 |
|
|
481 |
modeBits := (info at:#mode).
|
|
482 |
modeString := self getModeString:modeBits.
|
|
483 |
longInfo ifTrue:[
|
45
|
484 |
text add:((resources at:'access: ')
|
|
485 |
, modeString
|
|
486 |
, ' (' , (modeBits printStringRadix:8), ')' )
|
36
|
487 |
] ifFalse:[
|
45
|
488 |
text add:(resources at:'access: ') , modeString
|
36
|
489 |
].
|
|
490 |
text add:(resources at:'owner: ')
|
45
|
491 |
, (OperatingSystem getUserNameFromID:(info at:#uid)).
|
36
|
492 |
longInfo ifTrue:[
|
|
493 |
text add:(resources at:'group: ')
|
45
|
494 |
, (OperatingSystem getGroupNameFromID:(info at:#gid)).
|
36
|
495 |
text add:(resources at:'last access: ')
|
45
|
496 |
, (info at:#accessTime) asTime printString
|
|
497 |
, ' '
|
|
498 |
, (info at:#accessTime) asDate printString.
|
36
|
499 |
text add:(resources at:'last modification: ')
|
45
|
500 |
, (info at:#modificationTime) asTime printString
|
|
501 |
, ' '
|
|
502 |
, (info at:#modificationTime) asDate printString.
|
36
|
503 |
|
|
504 |
].
|
|
505 |
^ text asString
|
|
506 |
!
|
|
507 |
|
37
|
508 |
getModeString:modeBits with:texts
|
36
|
509 |
"convert file-mode bits into a more user-friendly string.
|
|
510 |
This is wrong here - should be moved into OperatingSystem."
|
|
511 |
|
|
512 |
|bits modeString|
|
|
513 |
|
|
514 |
bits := modeBits bitAnd:8r777.
|
|
515 |
modeString := ''.
|
|
516 |
|
|
517 |
#( nil 8r400 8r200 8r100 nil 8r040 8r020 8r010 nil 8r004 8r002 8r001 )
|
37
|
518 |
with: texts do:[:bitMask :access |
|
45
|
519 |
bitMask isNil ifTrue:[
|
|
520 |
modeString := modeString , (resources string:access)
|
|
521 |
] ifFalse:[
|
|
522 |
(bits bitAnd:bitMask) == 0 ifTrue:[
|
|
523 |
modeString := modeString copyWith:$-
|
|
524 |
] ifFalse:[
|
|
525 |
modeString := modeString copyWith:access
|
|
526 |
]
|
|
527 |
]
|
36
|
528 |
].
|
|
529 |
^ modeString
|
|
530 |
!
|
|
531 |
|
37
|
532 |
getModeString:modeBits
|
|
533 |
"convert file-mode bits into a more user-friendly string.
|
|
534 |
This is wrong here - should be moved into OperatingSystem."
|
|
535 |
|
|
536 |
^ self getModeString:modeBits
|
45
|
537 |
with:#( 'owner:' $r $w $x
|
|
538 |
' group:' $r $w $x
|
|
539 |
' others:' $r $w $x )
|
37
|
540 |
!
|
|
541 |
|
36
|
542 |
checkIfDirectoryHasChanged
|
|
543 |
"every checkDelta secs, check if directoy has changed and update view if so"
|
|
544 |
|
|
545 |
|oldSelection nOld here|
|
|
546 |
|
|
547 |
shown ifTrue:[
|
45
|
548 |
currentDirectory notNil ifTrue:[
|
|
549 |
lockUpdate ifTrue:[
|
|
550 |
Processor removeTimedBlock:checkBlock.
|
|
551 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta.
|
|
552 |
^ self
|
|
553 |
].
|
|
554 |
|
|
555 |
here := currentDirectory pathName.
|
|
556 |
(OperatingSystem isReadable:here) ifTrue:[
|
|
557 |
Processor removeTimedBlock:checkBlock.
|
36
|
558 |
|
45
|
559 |
(currentDirectory timeOfLastChange > timeOfLastCheck) ifTrue:[
|
|
560 |
nOld := fileListView numberOfSelections.
|
|
561 |
oldSelection := fileListView selectionValue.
|
|
562 |
self updateCurrentDirectory.
|
|
563 |
nOld ~~ 0 ifTrue:[
|
|
564 |
nOld > 1 ifTrue:[
|
|
565 |
oldSelection do:[:element |
|
|
566 |
fileListView addElementToSelection:element
|
|
567 |
]
|
|
568 |
] ifFalse:[
|
|
569 |
fileListView selectElementWithoutScroll:oldSelection
|
|
570 |
]
|
|
571 |
]
|
|
572 |
] ifFalse:[
|
|
573 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta
|
|
574 |
]
|
|
575 |
] ifFalse:[
|
|
576 |
"
|
|
577 |
if the directory has been deleted, or is not readable ...
|
|
578 |
"
|
|
579 |
(OperatingSystem isValidPath:here) ifFalse:[
|
|
580 |
self warn:(resources string:'FileBrowser:\\directory %1 is gone ?!!?' with:here) withCRs
|
|
581 |
] ifTrue:[
|
|
582 |
self warn:(resources string:'FileBrowser:\\directory %1 is no longer readable ?!!?' with:here) withCRs
|
|
583 |
].
|
|
584 |
fileListView contents:nil.
|
|
585 |
self label:(myName , ': directory is gone !!').
|
|
586 |
"/ Processor addTimedBlock:checkBlock afterSeconds:checkDelta
|
|
587 |
]
|
|
588 |
]
|
36
|
589 |
]
|
|
590 |
!
|
|
591 |
|
|
592 |
sizePrintString:size
|
|
593 |
"helper for update-directory to return a string with a files size.
|
|
594 |
This one gives the size in byte, Kb or Mb depending on size.
|
|
595 |
If you dont like this, just uncomment the first statement below."
|
|
596 |
|
|
597 |
|unitString sizeString|
|
|
598 |
|
|
599 |
"
|
|
600 |
^ size printString.
|
|
601 |
"
|
|
602 |
unitString := ''.
|
|
603 |
size < (500 * 1024) ifTrue:[
|
45
|
604 |
size < (1024) ifTrue:[
|
|
605 |
sizeString := size printString
|
|
606 |
] ifFalse:[
|
|
607 |
sizeString := (size * 10 // 1024 / 10.0) printString.
|
|
608 |
unitString := ' Kb'
|
|
609 |
]
|
36
|
610 |
] ifFalse:[
|
45
|
611 |
sizeString := (size * 10 // 1024 // 1024 / 10.0) printString.
|
|
612 |
unitString := ' Mb'
|
36
|
613 |
].
|
|
614 |
^ (sizeString printStringLeftPaddedTo:5) , unitString.
|
|
615 |
!
|
|
616 |
|
|
617 |
updateCurrentDirectory
|
|
618 |
"update listView with directory contents"
|
|
619 |
|
|
620 |
|files text len line info modeString typ
|
|
621 |
prevUid prevGid nameString groupString matchPattern
|
45
|
622 |
tabSpec|
|
36
|
623 |
|
|
624 |
self withCursor:(Cursor read) do:[
|
45
|
625 |
Processor removeTimedBlock:checkBlock.
|
36
|
626 |
|
45
|
627 |
labelView label:(currentDirectory pathName).
|
|
628 |
timeOfLastCheck := Time now.
|
|
629 |
|
|
630 |
files := currentDirectory asOrderedCollection.
|
36
|
631 |
|
45
|
632 |
matchPattern := filterField contents.
|
|
633 |
(matchPattern notNil and:[
|
|
634 |
matchPattern isEmpty not and:[
|
|
635 |
matchPattern ~= '*']]) ifTrue:[
|
|
636 |
files := files select:[:aName |
|
|
637 |
((currentDirectory typeOf:aName) == #directory)
|
|
638 |
or:[matchPattern match:aName]
|
|
639 |
].
|
|
640 |
].
|
|
641 |
files sort.
|
36
|
642 |
|
45
|
643 |
files size == 0 ifTrue:[
|
|
644 |
self notify:('directory ', currentDirectory pathName, ' vanished').
|
|
645 |
^ self
|
|
646 |
].
|
|
647 |
files := self withoutHiddenFiles:files.
|
|
648 |
|
|
649 |
"
|
|
650 |
this is a time consuming operation (especially, if reading an
|
|
651 |
NFS-mounted directory); therefore lower my priority while getting
|
|
652 |
the files info ...
|
|
653 |
"
|
|
654 |
Processor activeProcess withLowerPriorityDo:[
|
|
655 |
fileList := files.
|
|
656 |
showLongList ifTrue:[
|
37
|
657 |
|
|
658 |
tabSpec := TabulatorSpecification new.
|
|
659 |
tabSpec unit:#inch.
|
|
660 |
tabSpec positions:#(0 2 2.3 4.3 5.3 6.0).
|
|
661 |
" name type mode owner group "
|
|
662 |
tabSpec align: #(#left #left #left #right #right #decimal).
|
|
663 |
|
|
664 |
|
45
|
665 |
text := OrderedCollection new.
|
|
666 |
files do:[:aFileName |
|
37
|
667 |
|entry|
|
|
668 |
|
|
669 |
entry := MultiColListEntry new.
|
|
670 |
entry tabulatorSpecification:tabSpec.
|
|
671 |
|
45
|
672 |
"
|
|
673 |
if multiple FileBrowsers are reading, let others
|
|
674 |
make some progress too
|
|
675 |
"
|
|
676 |
Processor yield.
|
36
|
677 |
|
45
|
678 |
len := aFileName size.
|
|
679 |
(len < 20) ifTrue:[
|
|
680 |
line := aFileName , (String new:(22 - len))
|
|
681 |
] ifFalse:[
|
|
682 |
"can happen on BSD only"
|
|
683 |
line := (aFileName copyTo:20) , ' '
|
|
684 |
].
|
37
|
685 |
entry colAt:1 put:line.
|
|
686 |
|
45
|
687 |
info := currentDirectory infoOf:aFileName.
|
|
688 |
info isNil ifTrue:[
|
|
689 |
"not accessable - usually a symlink,
|
|
690 |
which is not there/not readable
|
|
691 |
"
|
|
692 |
text add:line , '? bad symbolic link'.
|
37
|
693 |
entry colAt:2 put:'?'.
|
|
694 |
entry colAt:3 put:'bad symbolic link'.
|
45
|
695 |
] ifFalse:[
|
|
696 |
typ := (info at:#type) at:1.
|
|
697 |
(typ == $r) ifFalse:[
|
|
698 |
line := line , typ asString , ' '.
|
37
|
699 |
entry colAt:2 put:typ asString.
|
45
|
700 |
] ifTrue:[
|
|
701 |
line := line , ' '.
|
37
|
702 |
entry colAt:2 put:' '.
|
45
|
703 |
].
|
36
|
704 |
|
45
|
705 |
modeString := self getModeString:(info at:#mode)
|
|
706 |
with:#( '' $r $w $x
|
|
707 |
' ' $r $w $x
|
|
708 |
' ' $r $w $x ).
|
37
|
709 |
entry colAt:3 put:modeString.
|
45
|
710 |
line := line , modeString , ' '.
|
36
|
711 |
|
45
|
712 |
((info at:#uid) ~~ prevUid) ifTrue:[
|
|
713 |
prevUid := (info at:#uid).
|
|
714 |
nameString := OperatingSystem getUserNameFromID:prevUid.
|
|
715 |
nameString := nameString , (String new:(10 - nameString size))
|
|
716 |
].
|
37
|
717 |
entry colAt:4 put:nameString withoutSpaces.
|
45
|
718 |
line := line , nameString.
|
|
719 |
((info at:#gid) ~~ prevGid) ifTrue:[
|
|
720 |
prevGid := (info at:#gid).
|
|
721 |
groupString := OperatingSystem getGroupNameFromID:prevGid.
|
|
722 |
groupString := groupString , (String new:(10 - groupString size))
|
|
723 |
].
|
37
|
724 |
entry colAt:5 put:groupString withoutSpaces.
|
45
|
725 |
line := line , groupString.
|
36
|
726 |
|
45
|
727 |
(typ == $r) ifTrue:[
|
|
728 |
line := line , (self sizePrintString:(info at:#size)) , ' '.
|
37
|
729 |
entry colAt:6 put:(self sizePrintString:(info at:#size)).
|
45
|
730 |
].
|
37
|
731 |
text add:entry
|
|
732 |
"/ text add:line
|
45
|
733 |
].
|
|
734 |
].
|
|
735 |
] ifFalse:[
|
|
736 |
text := files collect:[:aName |
|
|
737 |
"
|
|
738 |
if multiple FileBrowsers are reading, let others
|
|
739 |
make some progress too
|
|
740 |
"
|
|
741 |
Processor yield.
|
|
742 |
(((currentDirectory typeOf:aName) == #directory) and:[
|
|
743 |
(aName ~= '..') and:[aName ~= '.']]) ifTrue:[
|
|
744 |
aName , ' ...'
|
|
745 |
] ifFalse:[
|
|
746 |
aName
|
|
747 |
]
|
|
748 |
].
|
|
749 |
].
|
|
750 |
fileListView setList:text expandTabs:false
|
|
751 |
].
|
36
|
752 |
|
45
|
753 |
"
|
|
754 |
install a new check after some time
|
|
755 |
"
|
|
756 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta
|
36
|
757 |
]
|
|
758 |
!
|
|
759 |
|
|
760 |
doChangeCurrentDirectoryTo:fileName updateHistory:updateHistory
|
|
761 |
"verify argument is name of a readable & executable directory
|
|
762 |
and if so, go there"
|
|
763 |
|
|
764 |
|msg|
|
|
765 |
|
|
766 |
self label:myName.
|
|
767 |
fileName notNil ifTrue:[
|
45
|
768 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
769 |
(currentDirectory isReadable:fileName) ifTrue:[
|
|
770 |
(currentDirectory isExecutable:fileName) ifTrue:[
|
47
|
771 |
"/ this code updates when a directory is left
|
|
772 |
"/
|
|
773 |
"/ updateHistory ifTrue:[
|
|
774 |
"/ (DirectoryHistory includes:(currentDirectory pathName)) ifFalse:[
|
|
775 |
"/ DirectoryHistory addFirst:currentDirectory pathName.
|
|
776 |
"/ DirectoryHistory size > HistorySize ifTrue:[
|
|
777 |
"/ DirectoryHistory removeLast
|
|
778 |
"/ ].
|
|
779 |
"/ DirectoryHistory changed.
|
|
780 |
"/ ]
|
|
781 |
"/ ].
|
|
782 |
|
|
783 |
self setCurrentDirectory:fileName.
|
|
784 |
|
|
785 |
"/ its better to do it on entry
|
|
786 |
"/
|
45
|
787 |
updateHistory ifTrue:[
|
|
788 |
(DirectoryHistory includes:(currentDirectory pathName)) ifFalse:[
|
|
789 |
DirectoryHistory addFirst:currentDirectory pathName.
|
|
790 |
DirectoryHistory size > HistorySize ifTrue:[
|
|
791 |
DirectoryHistory removeLast
|
|
792 |
].
|
|
793 |
DirectoryHistory changed.
|
|
794 |
]
|
|
795 |
].
|
47
|
796 |
^ self
|
45
|
797 |
].
|
|
798 |
msg := (resources string:'cannot change directory to ''%1'' !!' with:fileName)
|
|
799 |
] ifFalse:[
|
|
800 |
msg := (resources string:'cannot read directory ''%1'' !!' with:fileName)
|
|
801 |
]
|
|
802 |
] ifFalse:[
|
|
803 |
msg := (resources string:'''%1'' is not a directory !!' with:fileName)
|
|
804 |
].
|
|
805 |
self showAlert:msg with:nil
|
36
|
806 |
]
|
|
807 |
!
|
|
808 |
|
|
809 |
doChangeToParentDirectory
|
|
810 |
"go to home directory"
|
|
811 |
|
|
812 |
self doChangeCurrentDirectoryTo:'..' updateHistory:true
|
|
813 |
!
|
|
814 |
|
|
815 |
doChangeToHomeDirectory
|
|
816 |
"go to home directory"
|
|
817 |
|
|
818 |
self doChangeCurrentDirectoryTo:(OperatingSystem getHomeDirectory) updateHistory:true
|
|
819 |
!
|
|
820 |
|
|
821 |
setCurrentDirectory:aPathName
|
|
822 |
"setup for another directory"
|
|
823 |
|
|
824 |
|newDirectory info|
|
|
825 |
|
|
826 |
aPathName isEmpty ifTrue:[^ self].
|
|
827 |
(currentDirectory isDirectory:aPathName) ifTrue:[
|
45
|
828 |
newDirectory := FileDirectory directoryNamed:aPathName in:currentDirectory.
|
|
829 |
newDirectory notNil ifTrue:[
|
|
830 |
currentDirectory := newDirectory.
|
|
831 |
fileListView contents:nil.
|
|
832 |
self updateCurrentDirectory.
|
|
833 |
info := self getInfoFile.
|
|
834 |
self showInfo:info.
|
|
835 |
"
|
|
836 |
tell my subview (whatever that is) to start its file-dialog
|
|
837 |
(i.e. save-as etc.) in that directory
|
|
838 |
"
|
|
839 |
(subView respondsTo:#directoryForFileDialog:) ifTrue:[
|
|
840 |
subView directoryForFileDialog:currentDirectory
|
|
841 |
]
|
|
842 |
]
|
36
|
843 |
]
|
|
844 |
!
|
|
845 |
|
|
846 |
readFile:fileName
|
|
847 |
"read in the file, answer its contents as Text"
|
|
848 |
|
|
849 |
^ self readFile:fileName lineDelimiter:Character cr
|
|
850 |
!
|
|
851 |
|
|
852 |
readStream:aStream
|
|
853 |
"read in from aStream, answer its contents as Text"
|
|
854 |
|
|
855 |
^ self readStream:aStream lineDelimiter:Character cr
|
|
856 |
!
|
|
857 |
|
|
858 |
readFile:fileName lineDelimiter:aCharacter
|
|
859 |
"read in the file, answer its contents as Text. The files lines are delimited by aCharacter."
|
|
860 |
|
|
861 |
|stream text msg line sz|
|
|
862 |
|
|
863 |
stream := FileStream readonlyFileNamed:fileName in:currentDirectory.
|
|
864 |
stream isNil ifTrue:[
|
45
|
865 |
msg := (resources string:'cannot read file ''%1'' !!' with:fileName).
|
|
866 |
self showAlert:msg with:(FileStream lastErrorString).
|
|
867 |
^ nil
|
36
|
868 |
].
|
|
869 |
|
|
870 |
"for very big files, give ObjectMemory a hint, to preallocate more"
|
|
871 |
(sz := stream size) > 1000000 ifTrue:[
|
45
|
872 |
ObjectMemory moreOldSpace:sz
|
36
|
873 |
].
|
|
874 |
|
|
875 |
text := self readStream:stream lineDelimiter:aCharacter.
|
|
876 |
stream close.
|
|
877 |
^ text
|
|
878 |
!
|
|
879 |
|
|
880 |
readStream:aStream lineDelimiter:aCharacter
|
|
881 |
"read from aStream, answer its contents as Text. The files lines are delimited by aCharacter."
|
|
882 |
|
|
883 |
|text msg line|
|
|
884 |
|
|
885 |
aCharacter == Character cr ifTrue:[
|
45
|
886 |
text := aStream contents
|
36
|
887 |
] ifFalse:[
|
45
|
888 |
text := Text new.
|
|
889 |
[aStream atEnd] whileFalse:[
|
|
890 |
line := aStream upTo:aCharacter.
|
|
891 |
text add:line
|
|
892 |
].
|
36
|
893 |
].
|
|
894 |
^ text
|
|
895 |
!
|
|
896 |
|
|
897 |
writeFile:fileName text:someText
|
|
898 |
|stream msg startNr nLines string|
|
|
899 |
|
|
900 |
self withCursor:(Cursor write) do:[
|
45
|
901 |
stream := FileStream newFileNamed:fileName in:currentDirectory.
|
|
902 |
stream isNil ifTrue:[
|
|
903 |
msg := (resources string:'cannot write file ''%1'' !!' with:fileName).
|
|
904 |
self showAlert:msg with:(FileStream lastErrorString)
|
|
905 |
] ifFalse:[
|
|
906 |
someText isString ifTrue:[
|
|
907 |
stream nextPutAll:someText.
|
|
908 |
] ifFalse:[
|
|
909 |
"
|
|
910 |
on some systems, writing linewise is very slow (via NFS)
|
|
911 |
therefore we convert to a string and write it in chunks
|
|
912 |
to avoid creating huge strings, we do it in blocks of 1000 lines
|
|
913 |
"
|
|
914 |
startNr := 1.
|
|
915 |
nLines := someText size.
|
|
916 |
[startNr <= nLines] whileTrue:[
|
|
917 |
string := someText asStringFrom:startNr
|
|
918 |
to:((startNr + 1000) min:nLines)
|
|
919 |
compressTabs:compressTabs.
|
|
920 |
stream nextPutAll:string.
|
|
921 |
startNr := startNr + 1000 + 1.
|
|
922 |
].
|
36
|
923 |
"/ someText do:[:line |
|
|
924 |
"/ line notNil ifTrue:[
|
|
925 |
"/ stream nextPutAll:line.
|
|
926 |
"/ ].
|
|
927 |
"/ stream cr.
|
|
928 |
"/ ]
|
45
|
929 |
].
|
|
930 |
stream close.
|
|
931 |
subView modified:false
|
|
932 |
]
|
36
|
933 |
]
|
|
934 |
!
|
|
935 |
|
|
936 |
doCreateDirectory:newName
|
|
937 |
(currentDirectory includes:newName) ifTrue:[
|
45
|
938 |
self warn:'%1 already exists.' with:newName.
|
|
939 |
^ self
|
36
|
940 |
].
|
|
941 |
|
|
942 |
(currentDirectory createDirectory:newName) ifTrue:[
|
45
|
943 |
self updateCurrentDirectory
|
36
|
944 |
] ifFalse:[
|
45
|
945 |
self showAlert:(resources string:'cannot create directory ''%1'' !!' with:newName)
|
|
946 |
with:(OperatingSystem lastErrorString)
|
36
|
947 |
]
|
|
948 |
!
|
|
949 |
|
|
950 |
doCreateFile:newName
|
|
951 |
|aStream box|
|
|
952 |
|
|
953 |
(currentDirectory includes:newName) ifTrue:[
|
45
|
954 |
box := YesNoBox new.
|
|
955 |
box title:(resources string:'%1 already exists\\truncate ?' with:newName) withCRs.
|
|
956 |
box okText:(resources string:'truncate').
|
|
957 |
box noText:(resources string:'cancel').
|
|
958 |
box noAction:[^ self].
|
|
959 |
box showAtPointer
|
36
|
960 |
].
|
|
961 |
|
|
962 |
aStream := FileStream newFileNamed:newName in:currentDirectory.
|
|
963 |
aStream notNil ifTrue:[
|
45
|
964 |
aStream close.
|
|
965 |
self updateCurrentDirectory
|
36
|
966 |
] ifFalse:[
|
45
|
967 |
self showAlert:(resources string:'cannot create file ''%1'' !!' with:newName)
|
|
968 |
with:(FileStream lastErrorString)
|
36
|
969 |
]
|
|
970 |
!
|
|
971 |
|
|
972 |
showFile:fileName
|
|
973 |
"show contents of fileName in subView"
|
|
974 |
|
|
975 |
|buffer s n i ok convert|
|
|
976 |
|
|
977 |
((currentDirectory typeOf:fileName) == #regular) ifFalse:[
|
45
|
978 |
"clicked on something else - ignore it ..."
|
|
979 |
self show:(resources string:'''%1'' is not a regular file' with:fileName).
|
|
980 |
^ self
|
36
|
981 |
].
|
|
982 |
"
|
|
983 |
check if file is a text file
|
|
984 |
"
|
|
985 |
s := FileStream readonlyFileNamed:fileName in:currentDirectory.
|
|
986 |
s isNil ifTrue:[
|
45
|
987 |
self showAlert:(resources string:'cannot read file ''%1'' !!' with:fileName)
|
|
988 |
with:(FileStream lastErrorString).
|
|
989 |
^ nil
|
36
|
990 |
].
|
|
991 |
|
|
992 |
buffer := String new:300.
|
|
993 |
n := s nextBytes:300 into:buffer.
|
|
994 |
s close.
|
|
995 |
|
|
996 |
ok := true.
|
|
997 |
1 to:n do:[:i |
|
45
|
998 |
(buffer at:i) isPrintable ifFalse:[ok := false].
|
36
|
999 |
].
|
|
1000 |
ok ifFalse:[
|
45
|
1001 |
(self confirm:(resources string:'''%1'' seems to be a binary file - continue anyway ?' with:fileName))
|
|
1002 |
ifFalse:[^ self]
|
36
|
1003 |
].
|
|
1004 |
|
|
1005 |
convert := false.
|
|
1006 |
ok ifTrue:[
|
45
|
1007 |
"
|
|
1008 |
check if line delimiter is a cr
|
|
1009 |
"
|
|
1010 |
i := buffer indexOf:Character cr.
|
|
1011 |
i == 0 ifTrue:[
|
|
1012 |
"
|
|
1013 |
no newline found - try cr
|
|
1014 |
"
|
|
1015 |
i := buffer indexOf:(Character value:13).
|
|
1016 |
i ~~ 0 ifTrue:[
|
|
1017 |
convert := self confirm:(resources string:'''%1'' seems to have CR as line delimiter - convert to NL ?' with:fileName).
|
|
1018 |
]
|
|
1019 |
]
|
36
|
1020 |
].
|
|
1021 |
|
|
1022 |
"release old text first - we might need the memory in case of huge files
|
|
1023 |
(helps if you have a 4Mb file in the view, and click on another biggy)"
|
|
1024 |
subView contents:nil.
|
|
1025 |
|
|
1026 |
convert ifTrue:[
|
45
|
1027 |
self show:(self readFile:fileName lineDelimiter:(Character value:13))
|
36
|
1028 |
] ifFalse:[
|
45
|
1029 |
self show:(self readFile:fileName).
|
36
|
1030 |
].
|
|
1031 |
subView acceptAction:[:theCode |
|
45
|
1032 |
self writeFile:fileName text:theCode
|
36
|
1033 |
]
|
|
1034 |
!
|
|
1035 |
|
|
1036 |
show:something
|
|
1037 |
"show something in subview and undef acceptAction"
|
|
1038 |
|
|
1039 |
subView contents:something.
|
|
1040 |
subView acceptAction:nil.
|
|
1041 |
subView modified:false
|
|
1042 |
!
|
|
1043 |
|
|
1044 |
doFileGet
|
|
1045 |
"get selected file - show contents in subView"
|
|
1046 |
|
|
1047 |
|fileName|
|
|
1048 |
|
|
1049 |
self withCursor:(Cursor read) do:[
|
45
|
1050 |
fileName := self getSelectedFileName.
|
|
1051 |
fileName notNil ifTrue:[
|
|
1052 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
1053 |
self doChangeCurrentDirectoryTo:fileName updateHistory:true.
|
|
1054 |
self label:myName
|
|
1055 |
] ifFalse:[
|
|
1056 |
self showFile:fileName.
|
|
1057 |
(currentDirectory isWritable:fileName) ifFalse:[
|
|
1058 |
self label:(myName , ': ' , fileName , ' (readonly)')
|
|
1059 |
] ifTrue:[
|
|
1060 |
self label:(myName , ': ' , fileName)
|
|
1061 |
]
|
|
1062 |
]
|
|
1063 |
]
|
36
|
1064 |
]
|
|
1065 |
!
|
|
1066 |
|
|
1067 |
doExecuteCommand:command replace:replace
|
|
1068 |
"execute a unix command inserting the output of the command.
|
|
1069 |
If replace is true, all text is replaced by the commands output;
|
|
1070 |
otherwise, its inserted as selected text at the cursor position."
|
|
1071 |
|
|
1072 |
|stream line lnr myProcess myPriority startLine startCol stopSignal
|
|
1073 |
access|
|
|
1074 |
|
|
1075 |
access := Semaphore forMutualExclusion.
|
|
1076 |
stopSignal := Signal new.
|
|
1077 |
|
|
1078 |
"
|
|
1079 |
must take killButton out of my group
|
|
1080 |
"
|
|
1081 |
windowGroup removeView:killButton.
|
|
1082 |
"
|
|
1083 |
bring it to front, and turn hidden-mode off
|
|
1084 |
"
|
|
1085 |
killButton raise.
|
|
1086 |
killButton hidden:false.
|
|
1087 |
"
|
|
1088 |
it will make me raise stopSignal when pressed
|
|
1089 |
"
|
|
1090 |
killButton action:[
|
45
|
1091 |
stream notNil ifTrue:[
|
|
1092 |
access critical:[
|
|
1093 |
myProcess interruptWith:[stopSignal raise].
|
|
1094 |
]
|
|
1095 |
]
|
36
|
1096 |
].
|
|
1097 |
"
|
|
1098 |
start it up under its own windowgroup
|
|
1099 |
"
|
|
1100 |
killButton openAutonomous.
|
|
1101 |
|
|
1102 |
"
|
|
1103 |
go fork a pipe and read it
|
|
1104 |
"
|
|
1105 |
self label:(myName , ': executing ' , (command copyTo:(20 min:command size)) , ' ...').
|
|
1106 |
[
|
|
1107 |
self withCursor:(Cursor wait) do:[
|
45
|
1108 |
stopSignal catch:[
|
|
1109 |
startLine := subView cursorLine.
|
|
1110 |
startCol := subView cursorCol.
|
36
|
1111 |
|
45
|
1112 |
stream := PipeStream readingFrom:('cd '
|
|
1113 |
, currentDirectory pathName
|
|
1114 |
, '; '
|
|
1115 |
, command).
|
|
1116 |
stream notNil ifTrue:[
|
|
1117 |
"
|
|
1118 |
this can be a time consuming operation; therefore lower my priority
|
|
1119 |
"
|
|
1120 |
myProcess := Processor activeProcess.
|
|
1121 |
myPriority := myProcess priority.
|
|
1122 |
myProcess priority:(Processor userBackgroundPriority).
|
36
|
1123 |
|
45
|
1124 |
[
|
|
1125 |
replace ifTrue:[
|
|
1126 |
subView list:nil.
|
|
1127 |
lnr := 1.
|
|
1128 |
].
|
36
|
1129 |
|
45
|
1130 |
[stream atEnd] whileFalse:[
|
|
1131 |
(stream readWaitWithTimeout:0.5) ifTrue:[
|
|
1132 |
"
|
|
1133 |
data available
|
|
1134 |
"
|
|
1135 |
line := stream nextLine.
|
36
|
1136 |
|
45
|
1137 |
"
|
|
1138 |
need this critical section; otherwise,
|
|
1139 |
we could get the signal while waiting for
|
|
1140 |
an expose event ...
|
|
1141 |
"
|
|
1142 |
access critical:[
|
|
1143 |
line notNil ifTrue:[
|
|
1144 |
replace ifTrue:[
|
|
1145 |
subView at:lnr put:line.
|
|
1146 |
lnr := lnr + 1.
|
|
1147 |
] ifFalse:[
|
|
1148 |
subView insertStringAtCursor:line.
|
|
1149 |
subView insertCharAtCursor:(Character cr).
|
|
1150 |
]
|
|
1151 |
].
|
|
1152 |
].
|
|
1153 |
].
|
36
|
1154 |
|
45
|
1155 |
shown ifTrue:[windowGroup processExposeEvents].
|
|
1156 |
"
|
|
1157 |
give others running at same prio a chance too
|
|
1158 |
(especially other FileBrowsers doing the same)
|
|
1159 |
"
|
|
1160 |
Processor yield
|
|
1161 |
].
|
|
1162 |
] valueNowOrOnUnwindDo:[
|
|
1163 |
stream close. stream := nil.
|
|
1164 |
].
|
|
1165 |
self updateCurrentDirectory
|
|
1166 |
].
|
|
1167 |
replace ifTrue:[
|
|
1168 |
subView modified:false.
|
|
1169 |
].
|
|
1170 |
]
|
36
|
1171 |
]
|
|
1172 |
] valueNowOrOnUnwindDo:[
|
45
|
1173 |
|wg|
|
36
|
1174 |
|
45
|
1175 |
self label:myName.
|
|
1176 |
myProcess notNil ifTrue:[myProcess priority:myPriority].
|
36
|
1177 |
|
45
|
1178 |
"
|
|
1179 |
remove the killButton from its group
|
|
1180 |
(otherwise, it will be destroyed when we shut down the group)
|
|
1181 |
"
|
|
1182 |
wg := killButton windowGroup.
|
|
1183 |
killButton windowGroup:nil.
|
|
1184 |
"
|
|
1185 |
shut down the windowgroup
|
|
1186 |
"
|
|
1187 |
wg notNil ifTrue:[
|
|
1188 |
wg process terminate.
|
|
1189 |
].
|
|
1190 |
"
|
|
1191 |
hide the button, and make sure it will stay
|
|
1192 |
hidden when we are realized again
|
|
1193 |
"
|
|
1194 |
killButton unrealize.
|
|
1195 |
killButton hidden:true.
|
|
1196 |
"
|
|
1197 |
clear its action (actually not needed, but
|
|
1198 |
releases reference to thisContext earlier)
|
|
1199 |
"
|
|
1200 |
killButton action:nil.
|
36
|
1201 |
]
|
|
1202 |
!
|
|
1203 |
|
|
1204 |
initialCommandFor:fileName into:aBox
|
|
1205 |
"set a useful initial command for execute box.
|
|
1206 |
|
|
1207 |
XXX should be changed to take stuff from a config file
|
|
1208 |
XXX or from resources."
|
|
1209 |
|
|
1210 |
((currentDirectory typeOf:fileName) == #regular) ifTrue:[
|
|
1211 |
|
45
|
1212 |
(currentDirectory isExecutable:fileName) ifTrue:[
|
|
1213 |
aBox initialText:(fileName , '<arguments>').
|
|
1214 |
^ self
|
|
1215 |
].
|
36
|
1216 |
|
45
|
1217 |
"some heuristics - my personal preferences ...
|
|
1218 |
(actually this should come from a configfile)"
|
36
|
1219 |
|
45
|
1220 |
(fileName endsWith:'akefile') ifTrue:[
|
|
1221 |
aBox initialText:'make target' selectFrom:6 to:11.
|
|
1222 |
^ self
|
|
1223 |
].
|
|
1224 |
(fileName endsWith:'.tar.Z') ifTrue:[
|
|
1225 |
aBox initialText:'zcat ' , fileName , ' | tar tvf -'.
|
|
1226 |
^ self
|
|
1227 |
].
|
|
1228 |
(fileName endsWith:'.taz') ifTrue:[
|
|
1229 |
aBox initialText:'zcat ' , fileName , ' | tar tvf -'.
|
|
1230 |
^ self
|
|
1231 |
].
|
|
1232 |
(fileName endsWith:'.tar') ifTrue:[
|
|
1233 |
aBox initialText:'tar tvf ' , fileName selectFrom:1 to:7.
|
|
1234 |
^ self
|
|
1235 |
].
|
|
1236 |
(fileName endsWith:'.zoo') ifTrue:[
|
|
1237 |
aBox initialText:'zoo -list ' , fileName selectFrom:1 to:9.
|
|
1238 |
^ self
|
|
1239 |
].
|
|
1240 |
(fileName endsWith:'.zip') ifTrue:[
|
|
1241 |
aBox initialText:'unzip -l ' , fileName selectFrom:1 to:8.
|
|
1242 |
^ self
|
|
1243 |
].
|
|
1244 |
(fileName endsWith:'.Z') ifTrue:[
|
|
1245 |
aBox initialText:'uncompress ' , fileName selectFrom:1 to:10.
|
|
1246 |
^ self
|
|
1247 |
].
|
|
1248 |
(fileName endsWith:'tar.gz') ifTrue:[
|
|
1249 |
aBox initialText:('gunzip <' , fileName , ' | tar tvf -' ).
|
|
1250 |
^ self
|
|
1251 |
].
|
|
1252 |
(fileName endsWith:'.gz') ifTrue:[
|
|
1253 |
aBox initialText:('gunzip <' , fileName , ' >' , (fileName copyTo:(fileName size - 3))).
|
|
1254 |
^ self
|
|
1255 |
].
|
|
1256 |
(fileName endsWith:'.html') ifTrue:[
|
|
1257 |
aBox initialText:'chimera ' , fileName .
|
|
1258 |
^ self
|
|
1259 |
].
|
|
1260 |
(fileName endsWith:'.uue') ifTrue:[
|
|
1261 |
aBox initialText:'uudecode ' , fileName selectFrom:1 to:8.
|
|
1262 |
^ self
|
|
1263 |
].
|
|
1264 |
(fileName endsWith:'.c') ifTrue:[
|
|
1265 |
aBox initialText:'cc -c ' , fileName selectFrom:1 to:5.
|
|
1266 |
^ self
|
|
1267 |
].
|
|
1268 |
(fileName endsWith:'.cc') ifTrue:[
|
|
1269 |
aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6.
|
|
1270 |
^ self
|
|
1271 |
].
|
|
1272 |
(fileName endsWith:'.C') ifTrue:[
|
|
1273 |
aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6.
|
|
1274 |
^ self
|
|
1275 |
].
|
|
1276 |
(fileName endsWith:'.xbm') ifTrue:[
|
|
1277 |
aBox initialText:'bitmap ' , fileName selectFrom:1 to:6.
|
|
1278 |
^ self
|
|
1279 |
].
|
|
1280 |
((fileName endsWith:'.ps') or:[fileName endsWith:'.PS']) ifTrue:[
|
|
1281 |
aBox initialText:'ghostview ' , fileName selectFrom:1 to:9.
|
|
1282 |
^ self
|
|
1283 |
].
|
|
1284 |
((fileName endsWith:'.1')
|
|
1285 |
or:[fileName endsWith:'.man']) ifTrue:[
|
|
1286 |
aBox initialText:'nroff -man ' , fileName selectFrom:1 to:10.
|
|
1287 |
^ self
|
|
1288 |
].
|
|
1289 |
aBox initialText:'<cmd> ' , fileName selectFrom:1 to:5
|
36
|
1290 |
]
|
|
1291 |
!
|
|
1292 |
|
|
1293 |
askForCommandThenDo:aBlock
|
|
1294 |
"setup and launch a querybox to ask for unix command.
|
|
1295 |
Then evaluate aBlock passing the command-string as argument."
|
|
1296 |
|
|
1297 |
|fileName sel box|
|
|
1298 |
|
45
|
1299 |
box := FilenameEnterBox new.
|
36
|
1300 |
box initialText:''.
|
|
1301 |
|
|
1302 |
sel := fileListView selection.
|
|
1303 |
(sel isKindOf:Collection) ifFalse:[
|
45
|
1304 |
sel notNil ifTrue:[
|
|
1305 |
fileName := fileList at:sel
|
|
1306 |
]
|
36
|
1307 |
].
|
|
1308 |
fileName notNil ifTrue:[
|
45
|
1309 |
self initialCommandFor:fileName into:box.
|
36
|
1310 |
].
|
|
1311 |
box title:(resources at:'execute unix command:').
|
|
1312 |
box okText:(resources at:'execute').
|
|
1313 |
box action:aBlock.
|
|
1314 |
box showAtPointer
|
|
1315 |
!
|
|
1316 |
|
|
1317 |
selectedFilesDo:aBlock
|
|
1318 |
|sel files|
|
|
1319 |
|
|
1320 |
sel := fileListView selection.
|
|
1321 |
sel notNil ifTrue:[
|
45
|
1322 |
(sel isKindOf:Collection) ifTrue:[
|
|
1323 |
files := sel collect:[:index | fileList at:index].
|
|
1324 |
files do:[:aFile |
|
|
1325 |
aBlock value:aFile
|
|
1326 |
]
|
|
1327 |
] ifFalse:[
|
|
1328 |
aBlock value:(fileList at:sel)
|
|
1329 |
]
|
36
|
1330 |
]
|
|
1331 |
|
|
1332 |
!
|
|
1333 |
|
|
1334 |
doRename:oldName to:newName
|
|
1335 |
(oldName notNil and:[newName notNil]) ifTrue:[
|
45
|
1336 |
(oldName isBlank or:[newName isBlank]) ifFalse:[
|
|
1337 |
currentDirectory renameFile:oldName newName:newName.
|
|
1338 |
self updateCurrentDirectory.
|
|
1339 |
]
|
36
|
1340 |
]
|
|
1341 |
!
|
|
1342 |
|
|
1343 |
doRemove
|
|
1344 |
"remove the selected file(s) - no questions asked"
|
|
1345 |
|
|
1346 |
|ok msg dir|
|
|
1347 |
|
|
1348 |
self withCursor:(Cursor execute) do:[
|
45
|
1349 |
lockUpdate := true.
|
|
1350 |
[
|
|
1351 |
self selectedFilesDo:[:fileName |
|
|
1352 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
1353 |
dir := FileDirectory directoryNamed:fileName in:currentDirectory.
|
|
1354 |
dir isEmpty ifFalse:[
|
|
1355 |
self ask:(resources string:'directory ''%1'' is not empty\remove anyway ?' with:fileName)
|
|
1356 |
yesButton:'remove'
|
|
1357 |
action:[currentDirectory removeDirectory:fileName]
|
|
1358 |
] ifTrue:[
|
|
1359 |
currentDirectory removeDirectory:fileName
|
|
1360 |
].
|
|
1361 |
] ifFalse:[
|
|
1362 |
ok := currentDirectory remove:fileName.
|
|
1363 |
ok ifFalse:[
|
|
1364 |
"was not able to remove it"
|
|
1365 |
msg := (resources string:'cannot remove ''%1'' !!' with:fileName).
|
|
1366 |
self showAlert:msg with:(OperatingSystem lastErrorString)
|
|
1367 |
] ifTrue:[
|
36
|
1368 |
"
|
45
|
1369 |
self show:nil
|
36
|
1370 |
"
|
45
|
1371 |
]
|
|
1372 |
]
|
|
1373 |
].
|
|
1374 |
fileListView deselect.
|
|
1375 |
self updateCurrentDirectory.
|
|
1376 |
] valueNowOrOnUnwindDo:[
|
|
1377 |
lockUpdate := false
|
|
1378 |
]
|
36
|
1379 |
]
|
|
1380 |
!
|
|
1381 |
|
|
1382 |
onlyOneSelection
|
|
1383 |
"show a warning, that only one file must be selected for
|
|
1384 |
this operation"
|
|
1385 |
|
45
|
1386 |
self warn:'exactly one file must be selected !!'
|
36
|
1387 |
! !
|
|
1388 |
|
|
1389 |
!FileBrowser methodsFor:'user interaction'!
|
|
1390 |
|
|
1391 |
fileSpawn
|
|
1392 |
"start another FileBrowser on the selected directory or
|
|
1393 |
on the same directory if none is selected."
|
|
1394 |
|
|
1395 |
|any|
|
|
1396 |
|
|
1397 |
any := false.
|
|
1398 |
self selectedFilesDo:[:fileName |
|
45
|
1399 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
1400 |
self class openOn:(currentDirectory pathName , '/' , fileName).
|
|
1401 |
any := true
|
|
1402 |
]
|
36
|
1403 |
].
|
|
1404 |
any ifFalse:[
|
45
|
1405 |
self class openOn:currentDirectory pathName
|
36
|
1406 |
]
|
|
1407 |
!
|
|
1408 |
|
|
1409 |
copyPath
|
|
1410 |
"copy current path into cut & paste buffer"
|
|
1411 |
|
|
1412 |
Smalltalk at:#CopyBuffer put:(currentDirectory pathName)
|
|
1413 |
!
|
|
1414 |
|
|
1415 |
fileExecute
|
|
1416 |
"if text was modified show a queryBox,
|
|
1417 |
otherwise pop up execute box immediately"
|
|
1418 |
|
|
1419 |
|action|
|
|
1420 |
|
37
|
1421 |
true ifTrue:[
|
45
|
1422 |
"
|
|
1423 |
this replaces everything by the commands output ...
|
|
1424 |
"
|
|
1425 |
action := [:command| self doExecuteCommand:command replace:true].
|
36
|
1426 |
|
45
|
1427 |
self askIfModified:(resources at:'contents has not been saved.\\Modifications will be lost when command is executed.') withCRs
|
|
1428 |
yesButton:(resources at:'execute')
|
|
1429 |
action:[self askForCommandThenDo:action]
|
37
|
1430 |
] ifFalse:[
|
45
|
1431 |
"
|
|
1432 |
this inserts the commands output ...
|
|
1433 |
"
|
|
1434 |
action := [:command| self doExecuteCommand:command replace:false].
|
|
1435 |
self askForCommandThenDo:action
|
37
|
1436 |
]
|
36
|
1437 |
!
|
|
1438 |
|
|
1439 |
fileSelect:lineNr
|
|
1440 |
"selected a file - do nothing here"
|
|
1441 |
^ self
|
|
1442 |
!
|
|
1443 |
|
|
1444 |
fileGet
|
37
|
1445 |
"if text was modified show a queryBox,
|
36
|
1446 |
otherwise get it immediately"
|
|
1447 |
|
|
1448 |
|fileName msg label|
|
|
1449 |
|
|
1450 |
(subView modified not or:[subView contentsWasSaved]) ifTrue:[^ self doFileGet].
|
|
1451 |
fileName := self getSelectedFileName.
|
|
1452 |
fileName notNil ifTrue:[
|
45
|
1453 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
1454 |
msg := (resources at:'contents has not been saved.\\Modifications will be lost when directory is changed.').
|
|
1455 |
label := 'change'.
|
|
1456 |
] ifFalse:[
|
|
1457 |
msg := (resources at:'contents has not been saved.\\Modifications will be lost when new file is read.').
|
|
1458 |
label := 'get'.
|
|
1459 |
].
|
|
1460 |
self ask:msg yesButton:label action:[self doFileGet]
|
36
|
1461 |
]
|
|
1462 |
!
|
|
1463 |
|
|
1464 |
filePrint
|
|
1465 |
|fileName inStream printStream line|
|
|
1466 |
|
|
1467 |
self withCursor:(Cursor execute) do:[
|
45
|
1468 |
fileName := self getSelectedFileName.
|
|
1469 |
fileName notNil ifTrue:[
|
|
1470 |
((currentDirectory typeOf:fileName) == #regular) ifTrue:[
|
|
1471 |
inStream := FileStream readonlyFileNamed:fileName
|
|
1472 |
in:currentDirectory.
|
|
1473 |
inStream isNil ifFalse:[
|
|
1474 |
printStream := PrinterStream new.
|
|
1475 |
printStream notNil ifTrue:[
|
|
1476 |
[inStream atEnd] whileFalse:[
|
|
1477 |
line := inStream nextLine.
|
|
1478 |
printStream nextPutAll:line.
|
|
1479 |
printStream cr
|
|
1480 |
].
|
|
1481 |
printStream close
|
|
1482 |
].
|
|
1483 |
inStream close
|
|
1484 |
]
|
|
1485 |
]
|
|
1486 |
].
|
|
1487 |
0 "compiler hint"
|
36
|
1488 |
]
|
|
1489 |
!
|
|
1490 |
|
|
1491 |
fileFileIn
|
|
1492 |
"fileIn the selected file(s)"
|
|
1493 |
|
|
1494 |
|aStream upd|
|
|
1495 |
|
|
1496 |
self withCursor:(Cursor wait) do:[
|
45
|
1497 |
self selectedFilesDo:[:fileName |
|
|
1498 |
((currentDirectory typeOf:fileName) == #regular) ifTrue:[
|
|
1499 |
((fileName endsWith:'.o')
|
|
1500 |
or:[(fileName endsWith:'.so')
|
|
1501 |
or:[fileName endsWith:'.obj']]) ifTrue:[
|
|
1502 |
Object abortSignal catch:[
|
|
1503 |
ObjectFileLoader loadObjectFile:(currentDirectory pathName , '/' ,fileName)
|
|
1504 |
]
|
|
1505 |
] ifFalse:[
|
|
1506 |
aStream := FileStream readonlyFileNamed:fileName in:currentDirectory.
|
|
1507 |
aStream isNil ifFalse:[
|
|
1508 |
upd := Class updateChanges:false.
|
|
1509 |
[
|
|
1510 |
Smalltalk systemPath addFirst:(currentDirectory pathName).
|
|
1511 |
aStream fileIn.
|
|
1512 |
Smalltalk systemPath removeFirst
|
|
1513 |
] valueNowOrOnUnwindDo:[
|
|
1514 |
Class updateChanges:upd.
|
|
1515 |
aStream close
|
|
1516 |
]
|
|
1517 |
]
|
|
1518 |
]
|
|
1519 |
]
|
|
1520 |
]
|
36
|
1521 |
]
|
|
1522 |
!
|
|
1523 |
|
|
1524 |
fileRemove
|
|
1525 |
"remove the selected file(s).
|
|
1526 |
Query if user really wants to remove the file.
|
|
1527 |
- should be enhanced, to look for a ~/.trash directory
|
|
1528 |
and move files there if it exists (without asking in this case)."
|
|
1529 |
|
|
1530 |
|sel q|
|
|
1531 |
|
|
1532 |
sel := fileListView selection.
|
|
1533 |
sel notNil ifTrue:[
|
45
|
1534 |
(sel isKindOf:Collection) ifTrue:[
|
|
1535 |
q := resources string:'remove selected files ?'
|
|
1536 |
] ifFalse:[
|
|
1537 |
q := resources string:'remove ''%1'' ?' with:(fileList at:sel)
|
|
1538 |
].
|
|
1539 |
self ask:q yesButton:'remove' action:[self doRemove]
|
36
|
1540 |
]
|
|
1541 |
!
|
|
1542 |
|
|
1543 |
newDirectory
|
|
1544 |
"ask for and create a new directory"
|
|
1545 |
|
37
|
1546 |
|queryBox|
|
|
1547 |
|
|
1548 |
queryBox := FilenameEnterBox new.
|
36
|
1549 |
queryBox initialText:''.
|
|
1550 |
queryBox title:(resources at:'create new directory:') withCRs.
|
|
1551 |
queryBox okText:(resources at:'create').
|
|
1552 |
"queryBox abortText:(resources at:'abort')."
|
|
1553 |
queryBox action:[:newName | self doCreateDirectory:newName].
|
|
1554 |
queryBox showAtPointer
|
|
1555 |
!
|
|
1556 |
|
|
1557 |
newFile
|
|
1558 |
"ask for and create a new file"
|
|
1559 |
|
37
|
1560 |
|sel queryBox|
|
36
|
1561 |
|
37
|
1562 |
queryBox := FilenameEnterBox new.
|
36
|
1563 |
sel := subView selection.
|
|
1564 |
sel notNil ifTrue:[
|
45
|
1565 |
queryBox initialText:(sel asString)
|
36
|
1566 |
] ifFalse:[
|
45
|
1567 |
queryBox initialText:''
|
36
|
1568 |
].
|
|
1569 |
queryBox title:(resources at:'create new file:') withCRs.
|
|
1570 |
queryBox okText:(resources at:'create').
|
|
1571 |
"queryBox abortText:(resources at:'abort')."
|
|
1572 |
queryBox action:[:newName | self doCreateFile:newName].
|
|
1573 |
queryBox showAtPointer
|
|
1574 |
!
|
|
1575 |
|
|
1576 |
fileRename
|
|
1577 |
"rename the selected file(s)"
|
|
1578 |
|
37
|
1579 |
|queryBox|
|
|
1580 |
|
|
1581 |
queryBox := FilenameEnterBox new.
|
36
|
1582 |
queryBox okText:(resources at:'rename').
|
|
1583 |
"queryBox abortText:(resources at:'abort')."
|
|
1584 |
self selectedFilesDo:[:oldName |
|
45
|
1585 |
queryBox title:(resources string:'rename ''%1'' to:' with:oldName).
|
|
1586 |
queryBox initialText:oldName.
|
|
1587 |
queryBox action:[:newName | self doRename:oldName to:newName].
|
|
1588 |
queryBox showAtPointer
|
36
|
1589 |
]
|
|
1590 |
!
|
|
1591 |
|
|
1592 |
terminate
|
|
1593 |
"exit FileBrowser"
|
|
1594 |
|
|
1595 |
self askIfModified:(resources at:'contents has not been saved.\\Modifications will be lost when FileBrowser is closed.') withCRs
|
45
|
1596 |
yesButton:(resources at:'close')
|
|
1597 |
action:[self destroy]
|
36
|
1598 |
!
|
|
1599 |
|
|
1600 |
destroy
|
|
1601 |
"destroy view and boxes"
|
|
1602 |
|
|
1603 |
ObjectMemory removeDependent:self.
|
|
1604 |
Processor removeTimedBlock:checkBlock.
|
|
1605 |
checkBlock := nil.
|
45
|
1606 |
DirectoryHistory removeDependent:self.
|
36
|
1607 |
super destroy
|
|
1608 |
!
|
|
1609 |
|
45
|
1610 |
update:what with:someArgument from:changedObject
|
36
|
1611 |
(what == #aboutToExit) ifTrue:[
|
45
|
1612 |
"system wants to shut down this
|
|
1613 |
- if text was modified, pop up, and ask user and save if requested."
|
|
1614 |
|
|
1615 |
(subView modified and:[subView contentsWasSaved not]) ifTrue:[
|
|
1616 |
shown ifFalse:[
|
|
1617 |
self unrealize.
|
|
1618 |
self realize
|
|
1619 |
].
|
|
1620 |
self raise.
|
|
1621 |
"
|
|
1622 |
mhmh: I dont like this - need some way to tell windowGroup to handle
|
|
1623 |
all pending exposures ...
|
|
1624 |
"
|
|
1625 |
self withAllSubViewsDo:[:view | view redraw].
|
36
|
1626 |
|
45
|
1627 |
self ask:(resources at:'FileBrowser:\\contents has not been saved.\\Save before exiting ?') withCRs
|
|
1628 |
yesButton:'save'
|
|
1629 |
noButton:'don''t save'
|
|
1630 |
action:[
|
|
1631 |
subView acceptAction notNil ifTrue:[
|
|
1632 |
subView accept
|
|
1633 |
] ifFalse:[
|
|
1634 |
subView save
|
|
1635 |
]
|
|
1636 |
]
|
|
1637 |
].
|
|
1638 |
^ self
|
36
|
1639 |
].
|
45
|
1640 |
changedObject == DirectoryHistory ifTrue:[
|
|
1641 |
self initializeLabelMiddleButtonMenu.
|
|
1642 |
^ self
|
|
1643 |
].
|
36
|
1644 |
!
|
|
1645 |
|
|
1646 |
changeDirectoryTo:aDirectoryName
|
|
1647 |
"sent from label menu to change back to a previous directory"
|
|
1648 |
|
|
1649 |
self doChangeCurrentDirectoryTo:aDirectoryName updateHistory:false
|
|
1650 |
!
|
|
1651 |
|
|
1652 |
changeCurrentDirectory
|
|
1653 |
"if text was modified show a queryBox,
|
|
1654 |
otherwise change immediately to directory"
|
|
1655 |
|
|
1656 |
self askIfModified:(resources at:'contents has not been saved.\\Modifications will be lost when directory is changed.') withCRs
|
45
|
1657 |
yesButton:(resources at:'change')
|
|
1658 |
action:[self queryForDirectoryToChange]
|
36
|
1659 |
!
|
|
1660 |
|
|
1661 |
changeToParentDirectory
|
|
1662 |
"if text was modified show a queryBox,
|
|
1663 |
otherwise change immediately to directory"
|
|
1664 |
|
|
1665 |
self askIfModified:(resources at:'contents has not been saved.\\Modifications will be lost when directory is changed.') withCRs
|
45
|
1666 |
yesButton:(resources at:'change')
|
|
1667 |
action:[self doChangeToParentDirectory]
|
36
|
1668 |
!
|
|
1669 |
|
|
1670 |
changeToHomeDirectory
|
|
1671 |
"if text was modified show a queryBox,
|
|
1672 |
otherwise change immediately to directory"
|
|
1673 |
|
|
1674 |
self askIfModified:(resources at:'contents has not been saved.\\Modifications will be lost when directory is changed.') withCRs
|
45
|
1675 |
yesButton:(resources at:'change')
|
|
1676 |
action:[self doChangeToHomeDirectory]
|
36
|
1677 |
!
|
|
1678 |
|
|
1679 |
queryForDirectoryToChange
|
|
1680 |
"query for new directory"
|
|
1681 |
|
37
|
1682 |
|queryBox|
|
|
1683 |
|
|
1684 |
queryBox := FilenameEnterBox new.
|
36
|
1685 |
queryBox initialText:''.
|
|
1686 |
queryBox title:(resources at:'change directory to:') withCRs.
|
|
1687 |
queryBox okText:(resources at:'change').
|
|
1688 |
"queryBox abortText:(resources at:'abort')."
|
|
1689 |
queryBox action:[:newName | self doChangeCurrentDirectoryTo:newName updateHistory:true].
|
|
1690 |
queryBox showAtPointer
|
|
1691 |
!
|
|
1692 |
|
|
1693 |
fileGetInfo:longInfo
|
|
1694 |
"get info on selected file - show it in a box"
|
|
1695 |
|
|
1696 |
|string|
|
|
1697 |
|
|
1698 |
string := self getFileInfoString:longInfo.
|
|
1699 |
string notNil ifTrue:[
|
45
|
1700 |
self information:string
|
36
|
1701 |
]
|
|
1702 |
!
|
|
1703 |
|
|
1704 |
fileGetLongInfo
|
|
1705 |
"triggered by menu: show long stat-info"
|
|
1706 |
|
|
1707 |
self fileGetInfo:true
|
|
1708 |
!
|
|
1709 |
|
|
1710 |
fileGetInfo
|
|
1711 |
"triggered by menu: show short stat-info"
|
|
1712 |
|
|
1713 |
self fileGetInfo:false
|
|
1714 |
!
|
|
1715 |
|
|
1716 |
changeDisplayMode
|
|
1717 |
"toggle from long to short listing (and vice-versa)"
|
|
1718 |
|
|
1719 |
|long short|
|
|
1720 |
|
|
1721 |
long := (resources at:'display long list').
|
|
1722 |
short := (resources at:'display short list').
|
|
1723 |
|
|
1724 |
showLongList := showLongList not.
|
|
1725 |
showLongList ifFalse:[
|
45
|
1726 |
fileListView middleButtonMenu labelAt:short put:long
|
36
|
1727 |
] ifTrue:[
|
45
|
1728 |
fileListView middleButtonMenu labelAt:long put:short
|
36
|
1729 |
].
|
|
1730 |
self updateCurrentDirectory
|
|
1731 |
!
|
|
1732 |
|
|
1733 |
changeDotFileVisibility
|
|
1734 |
"turn on/off visibility of files whose name starts with '.'"
|
|
1735 |
|
|
1736 |
|show dontShow|
|
|
1737 |
|
|
1738 |
show := (resources at:'show all files').
|
|
1739 |
dontShow := (resources at:'hide hidden files').
|
|
1740 |
|
|
1741 |
showDotFiles := showDotFiles not.
|
|
1742 |
showDotFiles ifFalse:[
|
45
|
1743 |
fileListView middleButtonMenu labelAt:dontShow put:show
|
36
|
1744 |
] ifTrue:[
|
45
|
1745 |
fileListView middleButtonMenu labelAt:show put:dontShow
|
36
|
1746 |
].
|
|
1747 |
self updateCurrentDirectory
|
|
1748 |
! !
|