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
|
98
|
14 |
instanceVariableNames:'labelView filterField fileListView subView currentDirectory
|
172
|
15 |
fileList checkBlock checkDelta timeOfLastCheck showLongList
|
|
16 |
showVeryLongList showDotFiles myName killButton compressTabs
|
|
17 |
lockUpdate previousDirectory currentFileName timeOfFileRead
|
|
18 |
tabSpec commandView commandIndex'
|
132
|
19 |
classVariableNames:'DirectoryHistory DirectoryHistoryWhere HistorySize DefaultIcon
|
172
|
20 |
CommandHistory CommandHistorySize'
|
45
|
21 |
poolDictionaries:''
|
|
22 |
category:'Interface-Browsers'
|
36
|
23 |
!
|
|
24 |
|
|
25 |
!FileBrowser class methodsFor:'documentation'!
|
|
26 |
|
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
45
|
30 |
All Rights Reserved
|
36
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
this used to be a very simple demo application,
|
|
44 |
but migrated into a quite nice tool, includes all kinds of
|
|
45 |
warning and information boxes, background processes for directory-
|
|
46 |
reading and internationalized strings. A good example for beginners,
|
100
|
47 |
on how to do things .... (and maybe how not to do things ;-, since some
|
|
48 |
stuff is historic and was implemented at times when better mechanisms
|
|
49 |
were not available)
|
52
|
50 |
|
36
|
51 |
See additional information in 'doc/misc/fbrowser.doc'.
|
45
|
52 |
|
52
|
53 |
WARNING: files edited with FileBrowser will have leading spaces (multiple-8)
|
|
54 |
being replaced by tabs. If tabs are to be preserved at other
|
|
55 |
positions (for example, sendmail-config files) they will be
|
|
56 |
corrupt after being written.
|
|
57 |
|
45
|
58 |
instancevariables of interrest:
|
|
59 |
|
|
60 |
checkDelta <Integer> number of seconds of check interval
|
|
61 |
(looks ever so often if shown directory
|
|
62 |
has changed). You may make this number
|
|
63 |
higher, if your network-times are
|
|
64 |
incorrect and thus, the filebrowser
|
|
65 |
checks too often.
|
|
66 |
|
|
67 |
compressTabs <Boolean> if true, leading spaces will be
|
|
68 |
replaced by tabs when saving text
|
52
|
69 |
|
|
70 |
some of the defaults (long/short list etc.) can be set by the resource file;
|
|
71 |
see FileBrowser>>initialize for more details..
|
36
|
72 |
"
|
172
|
73 |
!
|
|
74 |
|
|
75 |
version
|
|
76 |
^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.55 1995-11-15 12:16:34 cg Exp $'! !
|
36
|
77 |
|
|
78 |
!FileBrowser class methodsFor:'instance creation'!
|
|
79 |
|
|
80 |
openOn:aDirectoryPath
|
|
81 |
"start a new FileBrowser in a pathname"
|
|
82 |
|
|
83 |
^ (self new currentDirectory:aDirectoryPath) open
|
|
84 |
|
52
|
85 |
"
|
|
86 |
FileBrowser openOn:'aDirectoryPath'
|
|
87 |
FileBrowser openOn:'/etc'
|
|
88 |
FileBrowser openOn:'..'
|
|
89 |
FileBrowser openOn:'.'
|
|
90 |
"
|
93
|
91 |
!
|
|
92 |
|
|
93 |
openOnFileNamed:aFilename
|
|
94 |
"start a new FileBrowser on a file"
|
|
95 |
|
|
96 |
|f browser|
|
|
97 |
|
|
98 |
f := aFilename asFilename.
|
|
99 |
browser := self new.
|
|
100 |
browser currentDirectory:f directoryName.
|
|
101 |
browser showFile:f baseName.
|
|
102 |
^ browser open
|
|
103 |
|
|
104 |
"
|
|
105 |
FileBrowser openOnFileNamed:'Makefile'
|
|
106 |
FileBrowser openOnFileNamed:'../Makefile'
|
|
107 |
FileBrowser openOnFileNamed:'/tmp/foo'
|
|
108 |
"
|
36
|
109 |
! !
|
|
110 |
|
73
|
111 |
!FileBrowser class methodsFor:'defaults'!
|
|
112 |
|
|
113 |
defaultIcon
|
|
114 |
DefaultIcon isNil ifTrue:[
|
|
115 |
DefaultIcon := Form
|
|
116 |
fromFile:(ClassResources at:'ICON_FILE'
|
|
117 |
default:'FBrowser.xbm')
|
|
118 |
resolution:100.
|
|
119 |
].
|
|
120 |
^ DefaultIcon
|
|
121 |
! !
|
|
122 |
|
172
|
123 |
!FileBrowser methodsFor:'events'!
|
|
124 |
|
|
125 |
mapped
|
|
126 |
super mapped.
|
|
127 |
"
|
|
128 |
whant to know about changed history
|
|
129 |
"
|
|
130 |
self updateCurrentDirectory
|
|
131 |
!
|
|
132 |
|
|
133 |
visibilityChange:how
|
|
134 |
|wasVisible|
|
|
135 |
|
|
136 |
wasVisible := shown.
|
|
137 |
super visibilityChange:how.
|
|
138 |
(wasVisible not and:[shown]) ifTrue:[
|
|
139 |
"
|
|
140 |
start checking again
|
|
141 |
"
|
|
142 |
Processor removeTimedBlock:checkBlock.
|
|
143 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta.
|
|
144 |
]
|
|
145 |
! !
|
|
146 |
|
|
147 |
!FileBrowser methodsFor:'fileList user interaction'!
|
|
148 |
|
|
149 |
changeDisplayMode
|
|
150 |
"toggle from long to short listing (and vice-versa)"
|
|
151 |
|
|
152 |
showLongList := showLongList not.
|
|
153 |
self updateCurrentDirectory
|
|
154 |
!
|
|
155 |
|
|
156 |
changeDotFileVisibility
|
|
157 |
"turn on/off visibility of files whose name starts with '.'"
|
|
158 |
|
|
159 |
showDotFiles := showDotFiles not.
|
|
160 |
self updateCurrentDirectory
|
|
161 |
!
|
|
162 |
|
|
163 |
fileExecute
|
|
164 |
"if text was modified show a queryBox,
|
|
165 |
otherwise pop up execute box immediately"
|
|
166 |
|
|
167 |
|action|
|
|
168 |
|
|
169 |
"
|
|
170 |
this replaces everything by the commands output ...
|
|
171 |
"
|
|
172 |
action := [:command| self doExecuteCommand:command replace:true].
|
|
173 |
|
|
174 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when command is executed.'
|
|
175 |
yesButton:'execute') ifFalse:[^ self].
|
|
176 |
|
|
177 |
"/ "
|
|
178 |
"/ this inserts the commands output ...
|
|
179 |
"/ "
|
|
180 |
"/ action := [:command| self doExecuteCommand:command replace:false].
|
|
181 |
"/
|
|
182 |
self askForCommandThenDo:action
|
|
183 |
!
|
|
184 |
|
|
185 |
fileFileIn
|
|
186 |
"fileIn the selected file(s)"
|
|
187 |
|
|
188 |
self fileFileInLazy:false
|
|
189 |
!
|
|
190 |
|
|
191 |
fileFileInLazy
|
|
192 |
"fileIn the selected file(s). Do a quick load (no compilation)"
|
|
193 |
|
|
194 |
self fileFileInLazy:true
|
|
195 |
!
|
|
196 |
|
|
197 |
fileFileInLazy:lazy
|
|
198 |
"fileIn the selected file(s)"
|
|
199 |
|
|
200 |
|aStream here oldPath wasLazy|
|
|
201 |
|
|
202 |
self selectedFilesDo:[:fileName |
|
|
203 |
((currentDirectory typeOf:fileName) == #regular) ifTrue:[
|
|
204 |
here := currentDirectory pathName.
|
|
205 |
|
|
206 |
((fileName endsWith:'.o')
|
|
207 |
or:[(fileName endsWith:'.so')
|
|
208 |
or:[fileName endsWith:'.obj']]) ifTrue:[
|
|
209 |
Object abortSignal catch:[
|
|
210 |
|p|
|
|
211 |
|
|
212 |
p := (here , '/' ,fileName).
|
|
213 |
"/
|
|
214 |
"/ look if already loaded ... then unload first
|
|
215 |
"/
|
|
216 |
(ObjectFileLoader loadedObjectFiles includes:p) ifTrue:[
|
|
217 |
(Dialog confirm:(resources
|
|
218 |
string:'%1 is already loaded; load anyway ?'
|
|
219 |
with:p)) ifFalse:[
|
|
220 |
^ self
|
|
221 |
].
|
|
222 |
Transcript showCr:'unloading old ' , p , ' ...'.
|
|
223 |
ObjectFileLoader unloadObjectFile:p.
|
|
224 |
].
|
|
225 |
|
|
226 |
Transcript showCr:'loading ' , p , ' ...'.
|
|
227 |
ObjectFileLoader loadObjectFile:p.
|
|
228 |
Class addInfoRecord:('fileIn ' , fileName)
|
|
229 |
]
|
|
230 |
] ifFalse:[
|
|
231 |
aStream := FileStream readonlyFileNamed:fileName in:currentDirectory.
|
|
232 |
aStream isNil ifFalse:[
|
|
233 |
[
|
|
234 |
Class withoutUpdatingChangesDo:[
|
|
235 |
oldPath := Smalltalk systemPath.
|
|
236 |
Smalltalk systemPath:(oldPath copy addFirst:here; yourself).
|
|
237 |
wasLazy := Compiler compileLazy:lazy.
|
|
238 |
aStream fileIn.
|
|
239 |
].
|
|
240 |
Class addInfoRecord:('fileIn ' , fileName)
|
|
241 |
] valueNowOrOnUnwindDo:[
|
|
242 |
Compiler compileLazy:wasLazy.
|
|
243 |
Smalltalk systemPath:oldPath.
|
|
244 |
aStream close
|
|
245 |
]
|
|
246 |
]
|
|
247 |
]
|
|
248 |
]
|
|
249 |
]
|
|
250 |
|
|
251 |
"Created: 15.11.1995 / 12:48:51 / cg"
|
|
252 |
"Modified: 15.11.1995 / 12:49:57 / cg"
|
|
253 |
!
|
|
254 |
|
|
255 |
fileGet
|
|
256 |
"get contents of selected file into subView.
|
|
257 |
If text was modified show a queryBox,
|
|
258 |
otherwise get it immediately"
|
|
259 |
|
|
260 |
|fileName msg label|
|
|
261 |
|
|
262 |
(subView modified not or:[subView contentsWasSaved]) ifTrue:[^ self doFileGet].
|
|
263 |
fileName := self getSelectedFileName.
|
|
264 |
fileName notNil ifTrue:[
|
|
265 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
266 |
msg := 'contents has not been saved.\\Modifications will be lost when directory is changed.'.
|
|
267 |
label := 'change'.
|
|
268 |
] ifFalse:[
|
|
269 |
msg := 'contents has not been saved.\\Modifications will be lost when new file is read.'.
|
|
270 |
label := 'get'.
|
|
271 |
].
|
|
272 |
(self ask:(resources at:msg) yesButton:label) ifTrue:[
|
|
273 |
self doFileGet
|
|
274 |
]
|
|
275 |
]
|
|
276 |
!
|
|
277 |
|
|
278 |
fileGetInfo
|
|
279 |
"show short file (stat)-info"
|
|
280 |
|
|
281 |
self fileGetInfo:false
|
|
282 |
!
|
|
283 |
|
|
284 |
fileGetInfo:longInfo
|
|
285 |
"get info on selected file - show it in a box"
|
|
286 |
|
|
287 |
|string|
|
|
288 |
|
|
289 |
string := self getFileInfoString:longInfo.
|
|
290 |
string notNil ifTrue:[
|
|
291 |
self information:string
|
|
292 |
]
|
|
293 |
!
|
|
294 |
|
|
295 |
fileGetLongInfo
|
|
296 |
"show long stat (file)-info"
|
|
297 |
|
|
298 |
self fileGetInfo:true
|
|
299 |
!
|
|
300 |
|
|
301 |
fileInsert
|
|
302 |
"insert contents of file at cursor"
|
|
303 |
|
|
304 |
|fileName|
|
|
305 |
|
|
306 |
fileName := self getSelectedFileName.
|
|
307 |
fileName notNil ifTrue:[
|
|
308 |
self showFile:fileName insert:true
|
|
309 |
]
|
|
310 |
!
|
|
311 |
|
|
312 |
fileListMenu
|
|
313 |
"return the menu to show in the fileList"
|
|
314 |
|
|
315 |
|labels selectors m sel|
|
|
316 |
|
|
317 |
labels := #(
|
|
318 |
'spawn'
|
|
319 |
'-'
|
|
320 |
'get contents'
|
|
321 |
'insert contents'
|
|
322 |
'show info'
|
|
323 |
'show full info'
|
|
324 |
'fileIn'
|
|
325 |
'quick fileIn (lazy)'
|
|
326 |
'-'
|
|
327 |
'update'
|
|
328 |
'-'
|
|
329 |
'execute unix command ...'
|
|
330 |
'st/x tools'
|
|
331 |
'-'
|
|
332 |
'remove'
|
|
333 |
'rename ...'
|
|
334 |
'-'
|
|
335 |
'display long list'
|
|
336 |
'show all files'
|
|
337 |
'-'
|
|
338 |
'create directory ...'
|
|
339 |
'create file ...'
|
|
340 |
).
|
|
341 |
|
|
342 |
selectors := #(
|
|
343 |
fileSpawn
|
|
344 |
nil
|
|
345 |
fileGet
|
|
346 |
fileInsert
|
|
347 |
fileGetInfo
|
|
348 |
fileGetLongInfo
|
|
349 |
fileFileIn
|
|
350 |
fileFileInLazy
|
|
351 |
nil
|
|
352 |
updateCurrentDirectory
|
|
353 |
nil
|
|
354 |
fileExecute
|
|
355 |
stxTools
|
|
356 |
nil
|
|
357 |
fileRemove
|
|
358 |
fileRename
|
|
359 |
nil
|
|
360 |
changeDisplayMode
|
|
361 |
changeDotFileVisibility
|
|
362 |
nil
|
|
363 |
newDirectory
|
|
364 |
newFile
|
|
365 |
).
|
|
366 |
|
|
367 |
m := PopUpMenu
|
|
368 |
labels:(resources array:labels)
|
|
369 |
selectors:selectors
|
|
370 |
receiver:self.
|
|
371 |
|
|
372 |
showDotFiles ifTrue:[
|
|
373 |
m labelAt:#changeDotFileVisibility put:'hide hidden files'
|
|
374 |
].
|
|
375 |
showLongList ifTrue:[
|
|
376 |
m labelAt:#changeDisplayMode put:'display short list'
|
|
377 |
].
|
|
378 |
|
|
379 |
m subMenuAt:#stxTools
|
|
380 |
put:(PopUpMenu
|
|
381 |
labels:#(
|
|
382 |
'Changes browser'
|
|
383 |
'Editor '
|
|
384 |
'HTML reader'
|
|
385 |
'Image inspect '
|
|
386 |
)
|
|
387 |
selectors:#(
|
|
388 |
openChangesBrowser
|
|
389 |
openEditor
|
|
390 |
openHTMLReader
|
|
391 |
openImageInspector
|
|
392 |
)
|
|
393 |
receiver:self).
|
|
394 |
|
|
395 |
((sel := fileListView selection) isNil or:[sel isEmpty]) ifTrue:[
|
|
396 |
m disableAll:#(fileGet fileInsert
|
|
397 |
fileGetInfo fileGetLongInfo
|
|
398 |
fileFileIn fileFileInLazy
|
|
399 |
fileRemove fileRename).
|
|
400 |
(m subMenuAt:#stxTools)
|
|
401 |
disableAll:#(openChangesBrowser openEditor openHTMLReader openImageInspector)
|
|
402 |
].
|
|
403 |
|
|
404 |
^m
|
|
405 |
!
|
|
406 |
|
|
407 |
filePrint
|
|
408 |
|fileName inStream printStream line|
|
|
409 |
|
|
410 |
self withCursor:(Cursor execute) do:[
|
|
411 |
fileName := self getSelectedFileName.
|
|
412 |
fileName notNil ifTrue:[
|
|
413 |
((currentDirectory typeOf:fileName) == #regular) ifTrue:[
|
|
414 |
inStream := FileStream readonlyFileNamed:fileName
|
|
415 |
in:currentDirectory.
|
|
416 |
inStream isNil ifFalse:[
|
|
417 |
printStream := PrinterStream new.
|
|
418 |
printStream notNil ifTrue:[
|
|
419 |
[inStream atEnd] whileFalse:[
|
|
420 |
line := inStream nextLine.
|
|
421 |
printStream nextPutAll:line.
|
|
422 |
printStream cr
|
|
423 |
].
|
|
424 |
printStream close
|
|
425 |
].
|
|
426 |
inStream close
|
|
427 |
]
|
|
428 |
]
|
|
429 |
].
|
|
430 |
0 "compiler hint"
|
|
431 |
]
|
|
432 |
!
|
|
433 |
|
|
434 |
fileRemove
|
|
435 |
"remove the selected file(s).
|
|
436 |
Query if user really wants to remove the file.
|
|
437 |
- should be enhanced, to look for a ~/.trash directory
|
|
438 |
and move files there if it exists (without asking in this case)."
|
|
439 |
|
|
440 |
|sel q|
|
|
441 |
|
|
442 |
sel := fileListView selection.
|
|
443 |
sel notNil ifTrue:[
|
|
444 |
sel size > 1 ifTrue:[
|
|
445 |
q := resources string:'remove selected files ?'
|
|
446 |
] ifFalse:[
|
|
447 |
q := resources string:'remove ''%1'' ?' with:(fileList at:sel first)
|
|
448 |
].
|
|
449 |
(self ask:q yesButton:'remove') ifTrue:[self doRemove]
|
|
450 |
]
|
|
451 |
!
|
|
452 |
|
|
453 |
fileRename
|
|
454 |
"rename the selected file(s)"
|
|
455 |
|
|
456 |
|queryBox|
|
|
457 |
|
|
458 |
queryBox := FilenameEnterBox new.
|
|
459 |
queryBox okText:(resources at:'rename').
|
|
460 |
self selectedFilesDo:[:oldName |
|
|
461 |
queryBox title:(resources string:'rename ''%1'' to:' with:oldName).
|
|
462 |
queryBox initialText:oldName.
|
|
463 |
queryBox action:[:newName | self doRename:oldName to:newName].
|
|
464 |
queryBox showAtPointer
|
|
465 |
]
|
|
466 |
!
|
|
467 |
|
|
468 |
fileSelect:lineNr
|
|
469 |
"selected a file - do nothing here"
|
|
470 |
^ self
|
|
471 |
!
|
|
472 |
|
|
473 |
fileSpawn
|
|
474 |
"start another FileBrowser on the selected directory or
|
|
475 |
on the same directory if none is selected."
|
|
476 |
|
|
477 |
|any|
|
|
478 |
|
|
479 |
any := false.
|
|
480 |
self selectedFilesDo:[:fileName |
|
|
481 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
482 |
self class openOn:(currentDirectory pathName , '/' , fileName).
|
|
483 |
any := true
|
|
484 |
]
|
|
485 |
].
|
|
486 |
any ifFalse:[
|
|
487 |
self class openOn:currentDirectory pathName
|
|
488 |
]
|
|
489 |
!
|
|
490 |
|
|
491 |
newDirectory
|
|
492 |
"ask for and create a new directory"
|
|
493 |
|
|
494 |
|queryBox|
|
|
495 |
|
|
496 |
queryBox := FilenameEnterBox
|
|
497 |
title:(resources at:'create new directory:') withCRs
|
|
498 |
okText:(resources at:'create')
|
|
499 |
action:[:newName | self doCreateDirectory:newName].
|
|
500 |
"/ queryBox initialText:''.
|
|
501 |
queryBox showAtPointer
|
|
502 |
!
|
|
503 |
|
|
504 |
newFile
|
|
505 |
"ask for and create a new file"
|
|
506 |
|
|
507 |
|sel queryBox|
|
|
508 |
|
|
509 |
queryBox := FilenameEnterBox
|
|
510 |
title:(resources at:'create new file:') withCRs
|
|
511 |
okText:(resources at:'create')
|
|
512 |
action:[:newName | self doCreateFile:newName].
|
|
513 |
sel := subView selection.
|
|
514 |
sel notNil ifTrue:[
|
|
515 |
queryBox initialText:(sel asString)
|
|
516 |
] ifFalse:[
|
|
517 |
"/ queryBox initialText:''
|
|
518 |
].
|
|
519 |
queryBox showAtPointer
|
|
520 |
!
|
|
521 |
|
|
522 |
openChangesBrowser
|
|
523 |
"open a change browser on the selected file(s)"
|
|
524 |
|
|
525 |
self openTool:ChangesBrowser
|
|
526 |
!
|
|
527 |
|
|
528 |
openEditor
|
|
529 |
self openTool:EditTextView
|
|
530 |
!
|
|
531 |
|
|
532 |
openHTMLReader
|
|
533 |
self openTool:XtHTML
|
|
534 |
!
|
|
535 |
|
|
536 |
openImageInspector
|
|
537 |
|img|
|
|
538 |
|
|
539 |
self selectedFilesDo:[:fileName |
|
|
540 |
(currentDirectory isDirectory:fileName) ifFalse:[
|
|
541 |
img := Image fromFile:(currentDirectory pathName , '/' , fileName).
|
|
542 |
img notNil ifTrue:[
|
|
543 |
img inspect
|
|
544 |
] ifFalse:[
|
|
545 |
self warn:'unknown format: ' , fileName
|
|
546 |
]
|
|
547 |
]
|
|
548 |
].
|
|
549 |
|
|
550 |
"Modified: 17.9.1995 / 17:41:24 / claus"
|
|
551 |
!
|
|
552 |
|
|
553 |
openTool:aToolClass
|
|
554 |
"open a tool on the selected file(s)"
|
|
555 |
|
|
556 |
self selectedFilesDo:[:fileName |
|
|
557 |
(currentDirectory isDirectory:fileName) ifFalse:[
|
|
558 |
aToolClass openOn:(currentDirectory pathName , '/' , fileName).
|
|
559 |
]
|
|
560 |
].
|
|
561 |
! !
|
|
562 |
|
|
563 |
!FileBrowser methodsFor:'help '!
|
|
564 |
|
|
565 |
helpTextFor:aComponent
|
|
566 |
|s|
|
|
567 |
|
|
568 |
aComponent == subView ifTrue:[
|
|
569 |
s := 'HELP_SUBVIEW'
|
|
570 |
].
|
|
571 |
aComponent == fileListView ifTrue:[
|
|
572 |
s := 'HELP_FILELIST'
|
|
573 |
].
|
|
574 |
aComponent == filterField ifTrue:[
|
|
575 |
s := 'HELP_FILTER'
|
|
576 |
].
|
|
577 |
aComponent == labelView ifTrue:[
|
|
578 |
s := 'HELP_PATHFIELD'
|
|
579 |
].
|
|
580 |
aComponent == commandView ifTrue:[
|
|
581 |
s := 'HELP_COMMANDVIEW'
|
|
582 |
].
|
|
583 |
s notNil ifTrue:[
|
|
584 |
^ resources string:s
|
|
585 |
].
|
|
586 |
^ nil
|
|
587 |
! !
|
|
588 |
|
36
|
589 |
!FileBrowser methodsFor:'initialization'!
|
|
590 |
|
172
|
591 |
currentDirectory:aDirectoryPath
|
|
592 |
"set the directory to be browsed"
|
|
593 |
|
|
594 |
currentDirectory := FileDirectory directoryNamed:aDirectoryPath.
|
|
595 |
self changed:#path.
|
|
596 |
"
|
|
597 |
tell my subview (whatever that is) to start its file-dialog
|
|
598 |
(i.e. save-as etc.) in that directory
|
|
599 |
"
|
|
600 |
(subView respondsTo:#directoryForFileDialog:) ifTrue:[
|
|
601 |
subView directoryForFileDialog:currentDirectory
|
|
602 |
]
|
|
603 |
!
|
|
604 |
|
|
605 |
focusSequence
|
|
606 |
"return the sequence in which ALT-CursorRight steps focus"
|
|
607 |
|
|
608 |
|fs|
|
|
609 |
|
|
610 |
fs := Array
|
|
611 |
with:filterField
|
|
612 |
with:fileListView
|
|
613 |
with:subView.
|
|
614 |
|
|
615 |
commandView notNil ifTrue:[
|
|
616 |
fs := fs copyWith:commandView
|
|
617 |
].
|
|
618 |
^fs
|
|
619 |
!
|
|
620 |
|
|
621 |
initEvents
|
|
622 |
super initEvents.
|
|
623 |
self enableEvent:#visibilityChange.
|
|
624 |
!
|
|
625 |
|
36
|
626 |
initialize
|
79
|
627 |
|frame spacing halfSpacing v topFrame labelFrame|
|
36
|
628 |
|
|
629 |
super initialize.
|
|
630 |
|
52
|
631 |
"if true, will replace leading spaces by tabs on
|
|
632 |
file write. If false, they will be written as spaces
|
|
633 |
"
|
|
634 |
compressTabs := resources at:'COMPRESS_TABS' default:true.
|
|
635 |
|
|
636 |
"
|
|
637 |
showing long or short by default
|
|
638 |
"
|
|
639 |
showLongList := resources at:'LONG_LIST' default:false.
|
|
640 |
|
|
641 |
"
|
|
642 |
show type of contents (somwehat slow) or not ?
|
|
643 |
"
|
|
644 |
showVeryLongList := resources at:'VERYLONG_LIST' default:true.
|
|
645 |
|
|
646 |
"
|
|
647 |
show hidden files or not ?
|
|
648 |
"
|
|
649 |
showDotFiles := resources at:'SHOW_DOT_FILES' default:false.
|
|
650 |
|
|
651 |
|
45
|
652 |
lockUpdate := false.
|
|
653 |
|
132
|
654 |
CommandHistory isNil ifTrue:[
|
|
655 |
CommandHistory := OrderedCollection new.
|
|
656 |
CommandHistorySize := 50
|
|
657 |
].
|
36
|
658 |
DirectoryHistory isNil ifTrue:[
|
45
|
659 |
DirectoryHistory := OrderedCollection new.
|
52
|
660 |
DirectoryHistoryWhere := OrderedCollection new.
|
45
|
661 |
HistorySize := 15.
|
36
|
662 |
].
|
132
|
663 |
commandIndex := 0.
|
36
|
664 |
|
|
665 |
myName := (resources string:self class name).
|
|
666 |
self label:myName.
|
45
|
667 |
|
93
|
668 |
labelFrame := View
|
|
669 |
origin:(0.0 @ 0.0)
|
98
|
670 |
corner:(1.0 @ (font height * 2))
|
93
|
671 |
in:self.
|
52
|
672 |
|
105
|
673 |
styleSheet name = #st80 ifTrue:[
|
45
|
674 |
labelFrame level:1
|
|
675 |
].
|
36
|
676 |
|
|
677 |
spacing := ViewSpacing.
|
|
678 |
halfSpacing := spacing // 2.
|
|
679 |
|
|
680 |
checkBlock := [self checkIfDirectoryHasChanged].
|
45
|
681 |
checkDelta := resources at:'CHECK_DELTA' default:10.
|
36
|
682 |
|
|
683 |
currentDirectory := FileDirectory directoryNamed:'.'.
|
|
684 |
|
45
|
685 |
filterField := EditField in:labelFrame.
|
36
|
686 |
filterField origin:[((width // 4 * 3) + halfSpacing) @ halfSpacing]
|
45
|
687 |
corner:(1.0 @ filterField heightIncludingBorder).
|
|
688 |
filterField rightInset:ViewSpacing-halfSpacing.
|
|
689 |
|
36
|
690 |
self initializeFilterPattern.
|
|
691 |
filterField leaveAction:[:key | fileListView scrollToTop. self updateCurrentDirectory].
|
|
692 |
|
45
|
693 |
labelView := Label in:labelFrame.
|
36
|
694 |
labelView origin:(halfSpacing @ halfSpacing)
|
45
|
695 |
extent:[((width // 4 * 3) - spacing - borderWidth)
|
|
696 |
@
|
|
697 |
(filterField heightIncludingBorder)
|
|
698 |
"(font height + font descent)"
|
|
699 |
].
|
36
|
700 |
labelView adjust:#right.
|
|
701 |
labelView borderWidth:0.
|
93
|
702 |
labelView model:self; menu:#labelMenu; aspect:#path; labelMessage:#path.
|
73
|
703 |
labelFrame model:self; menu:#labelMenu.
|
36
|
704 |
|
|
705 |
killButton := Button label:(resources string:'kill') in:self.
|
|
706 |
killButton origin:(halfSpacing @ halfSpacing)
|
45
|
707 |
extent:(killButton width @ filterField height).
|
105
|
708 |
killButton hiddenOnRealize:true.
|
36
|
709 |
|
132
|
710 |
self initializeCommandViewIn:self.
|
|
711 |
|
|
712 |
"/ frame := VariableVerticalPanel
|
|
713 |
"/ origin:[frame borderWidth negated
|
|
714 |
"/ @
|
|
715 |
"/ labelFrame height
|
|
716 |
"/ "/ (labelView height + labelView origin y + spacing)
|
|
717 |
"/ ]
|
|
718 |
"/ corner:(1.0 @ 1.0)
|
|
719 |
"/ in:self.
|
|
720 |
|
|
721 |
frame := VariableVerticalPanel origin:0.0@0.0 corner:1.0@1.0 in:self.
|
|
722 |
frame topInset:labelFrame height.
|
|
723 |
commandView notNil ifTrue:[
|
133
|
724 |
frame bottomInset:(commandView height + spacing + spacing)
|
132
|
725 |
].
|
36
|
726 |
|
|
727 |
topFrame := ScrollableView for:SelectionInListView in:frame.
|
|
728 |
topFrame origin:(0.0 @ 0.0) corner:(1.0 @ 0.3).
|
|
729 |
|
|
730 |
fileListView := topFrame scrolledView.
|
|
731 |
fileListView action:[:lineNr | self fileSelect:lineNr].
|
|
732 |
fileListView doubleClickAction:[:lineNr | self fileSelect:lineNr.
|
45
|
733 |
self fileGet].
|
36
|
734 |
fileListView multipleSelectOk:true.
|
98
|
735 |
fileListView menuHolder:self; menuPerformer:self; menuMessage:#fileListMenu.
|
36
|
736 |
|
|
737 |
v := self initializeSubViewIn:frame.
|
132
|
738 |
|
36
|
739 |
v origin:(0.0 @ 0.3) corner:(1.0 @ 1.0).
|
|
740 |
subView := v scrolledView.
|
|
741 |
(subView respondsTo:#directoryForFileDialog:) ifTrue:[
|
45
|
742 |
subView directoryForFileDialog:currentDirectory
|
36
|
743 |
].
|
|
744 |
|
|
745 |
ObjectMemory addDependent:self.
|
132
|
746 |
|
|
747 |
"Modified: 6.9.1995 / 20:26:06 / claus"
|
36
|
748 |
!
|
|
749 |
|
132
|
750 |
initializeCommandViewIn:frame
|
|
751 |
"set up the command view - can be redefined in subclasses as empty,
|
|
752 |
if no commandView is wanted"
|
|
753 |
|
|
754 |
|
|
755 |
commandView := EditField origin:0.0@1.0 corner:1.0@1.0 in:frame.
|
|
756 |
commandView topInset:(commandView preferredExtent y negated - ViewSpacing).
|
|
757 |
commandView bottomInset:ViewSpacing.
|
|
758 |
commandView horizontalInset:ViewSpacing.
|
|
759 |
|
133
|
760 |
"/ commandView contents:'** no commands which require input here **'.
|
132
|
761 |
|
142
|
762 |
commandView entryCompletionBlock:[:contents |
|
|
763 |
|newString|
|
|
764 |
|
|
765 |
newString := Filename
|
|
766 |
filenameCompletionFor:contents
|
|
767 |
directory:currentDirectory pathName asFilename
|
|
768 |
directoriesOnly:false
|
|
769 |
filesOnly:false
|
|
770 |
ifMultiple:[:dir | commandView flash.].
|
|
771 |
commandView contents:newString.
|
|
772 |
commandView cursorToEndOfLine.
|
132
|
773 |
].
|
|
774 |
commandView leaveAction:[:key |
|
|
775 |
|cmd nCmd empty|
|
|
776 |
|
|
777 |
(key == #CursorDown
|
|
778 |
or:[key == #CursorUp]) ifTrue:[
|
133
|
779 |
nCmd := CommandHistory size.
|
|
780 |
nCmd == 0 ifTrue:[
|
|
781 |
empty := true
|
|
782 |
] ifFalse:[
|
|
783 |
key == #CursorUp ifTrue:[
|
|
784 |
commandIndex == nCmd ifTrue:[
|
|
785 |
commandView flash.
|
|
786 |
].
|
|
787 |
commandIndex := (commandIndex + 1) min:nCmd
|
|
788 |
] ifFalse:[
|
|
789 |
commandIndex == 1 ifTrue:[
|
|
790 |
commandView flash.
|
|
791 |
empty := true.
|
|
792 |
].
|
|
793 |
commandIndex := (commandIndex - 1) max:1.
|
|
794 |
].
|
|
795 |
].
|
|
796 |
empty == true ifTrue:[
|
|
797 |
commandView contents:nil
|
|
798 |
] ifFalse:[
|
|
799 |
commandView contents:(CommandHistory at:commandIndex).
|
|
800 |
]
|
132
|
801 |
].
|
|
802 |
key == #Return ifTrue:[
|
|
803 |
cmd := commandView contents.
|
|
804 |
|
133
|
805 |
subView insertLine:(ColoredListEntry string:('>> ' , cmd) color:Color blue)
|
|
806 |
before:(subView cursorLine).
|
|
807 |
subView cursorDown.
|
|
808 |
|
|
809 |
"/ subView insertStringAtCursor:cmd.
|
|
810 |
"/ subView insertCharAtCursor:(Character cr).
|
132
|
811 |
|
|
812 |
(cmd notNil and:[cmd notEmpty]) ifTrue:[
|
|
813 |
CommandHistory notNil ifTrue:[
|
|
814 |
CommandHistory addFirst:cmd.
|
|
815 |
CommandHistory size > CommandHistorySize ifTrue:[
|
|
816 |
CommandHistory removeLast
|
|
817 |
]
|
|
818 |
].
|
|
819 |
self doExecuteCommand:cmd replace:false.
|
|
820 |
commandView contents:nil.
|
|
821 |
commandIndex := 0
|
|
822 |
]
|
|
823 |
]
|
|
824 |
].
|
|
825 |
|
133
|
826 |
"Modified: 7.9.1995 / 15:48:45 / claus"
|
132
|
827 |
!
|
|
828 |
|
172
|
829 |
initializeFilterPattern
|
|
830 |
"set an initial matchpattern - can be redefined in subclasses"
|
|
831 |
|
|
832 |
filterField contents:'*'
|
|
833 |
!
|
|
834 |
|
|
835 |
initializeSubViewIn:frame
|
|
836 |
"set up the contents view - can be redefined in subclasses for
|
|
837 |
different view types (SoundFileBrowser/ImageBrowsers etc.)"
|
|
838 |
|
|
839 |
^ HVScrollableView for:CodeView miniScrollerH:true miniScrollerV:false in:frame.
|
|
840 |
! !
|
|
841 |
|
|
842 |
!FileBrowser methodsFor:'misc user interaction'!
|
|
843 |
|
|
844 |
destroy
|
|
845 |
"destroy view and boxes"
|
|
846 |
|
|
847 |
ObjectMemory removeDependent:self.
|
|
848 |
Processor removeTimedBlock:checkBlock.
|
|
849 |
checkBlock := nil.
|
|
850 |
super destroy
|
|
851 |
!
|
|
852 |
|
|
853 |
terminate
|
|
854 |
"exit FileBrowser"
|
|
855 |
|
|
856 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when FileBrowser is closed.'
|
|
857 |
yesButton:'close') ifTrue:[self destroy]
|
|
858 |
!
|
|
859 |
|
|
860 |
update:what with:someArgument from:changedObject
|
|
861 |
realized ifFalse:[^ self].
|
36
|
862 |
|
172
|
863 |
(what == #aboutToExit) ifTrue:[
|
|
864 |
"system wants to shut down this
|
|
865 |
- if text was modified, pop up, and ask user and save if requested."
|
|
866 |
|
|
867 |
(subView modified and:[subView contentsWasSaved not]) ifTrue:[
|
|
868 |
self raiseDeiconified.
|
|
869 |
|
|
870 |
self ask:(resources at:'FileBrowser:\\contents has not been saved.\\Save before exiting ?') withCRs
|
|
871 |
yesButton:'save'
|
|
872 |
noButton:'don''t save'
|
|
873 |
action:[
|
|
874 |
subView acceptAction notNil ifTrue:[
|
|
875 |
subView accept
|
|
876 |
] ifFalse:[
|
|
877 |
subView save
|
|
878 |
]
|
|
879 |
]
|
|
880 |
].
|
|
881 |
^ self
|
|
882 |
].
|
|
883 |
changedObject == tabSpec ifTrue:[
|
|
884 |
fileListView redraw
|
|
885 |
].
|
|
886 |
! !
|
|
887 |
|
|
888 |
!FileBrowser methodsFor:'pathField user interaction'!
|
|
889 |
|
|
890 |
changeCurrentDirectory
|
|
891 |
"if text was modified show a queryBox,
|
|
892 |
otherwise change immediately to directory"
|
|
893 |
|
|
894 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.'
|
|
895 |
yesButton:'change') ifTrue:[
|
|
896 |
self queryForDirectoryToChange
|
36
|
897 |
]
|
|
898 |
!
|
|
899 |
|
172
|
900 |
changeDirectoryTo:aDirectoryName
|
|
901 |
"sent from label menu to change back to a previous directory"
|
132
|
902 |
|
172
|
903 |
self doChangeCurrentDirectoryTo:aDirectoryName updateHistory:false
|
|
904 |
!
|
|
905 |
|
|
906 |
changeToHomeDirectory
|
|
907 |
"if text was modified show a queryBox,
|
|
908 |
otherwise change immediately to directory"
|
132
|
909 |
|
172
|
910 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.'
|
|
911 |
yesButton:'change') ifTrue:[
|
|
912 |
self doChangeToHomeDirectory
|
|
913 |
]
|
|
914 |
!
|
45
|
915 |
|
172
|
916 |
changeToParentDirectory
|
|
917 |
"if text was modified show a queryBox,
|
|
918 |
otherwise change immediately to directory"
|
45
|
919 |
|
172
|
920 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.'
|
|
921 |
yesButton:'change') ifTrue:[
|
|
922 |
self doChangeToParentDirectory
|
36
|
923 |
]
|
98
|
924 |
!
|
|
925 |
|
172
|
926 |
copyPath
|
|
927 |
"copy current path into cut & paste buffer"
|
|
928 |
|
|
929 |
Smalltalk at:#CopyBuffer put:currentDirectory pathName
|
|
930 |
!
|
|
931 |
|
|
932 |
labelMenu
|
|
933 |
|labels selectors args menu|
|
|
934 |
|
|
935 |
labels := #(
|
|
936 |
'copy path'
|
|
937 |
'-'
|
|
938 |
'up'
|
|
939 |
'back'
|
|
940 |
'change to home-directory'
|
|
941 |
'change directory ...'
|
|
942 |
).
|
98
|
943 |
|
172
|
944 |
selectors := #(
|
|
945 |
copyPath
|
|
946 |
nil
|
|
947 |
changeToParentDirectory
|
|
948 |
changeToPreviousDirectory
|
|
949 |
changeToHomeDirectory
|
|
950 |
changeCurrentDirectory
|
|
951 |
).
|
123
|
952 |
|
172
|
953 |
args := Array new:(labels size).
|
126
|
954 |
|
172
|
955 |
DirectoryHistory size > 0 ifTrue:[
|
|
956 |
labels := labels copyWith:'-'.
|
|
957 |
selectors := selectors copyWith:nil.
|
|
958 |
args := args copyWith:nil.
|
|
959 |
|
|
960 |
DirectoryHistory do:[:dirName |
|
|
961 |
labels := labels copyWith:dirName.
|
|
962 |
selectors := selectors copyWith:#changeDirectoryTo:.
|
|
963 |
args := args copyWith:dirName
|
|
964 |
]
|
123
|
965 |
].
|
172
|
966 |
|
|
967 |
menu := PopUpMenu
|
|
968 |
labels:(resources array:labels)
|
|
969 |
selectors:selectors
|
|
970 |
args:args
|
|
971 |
receiver:self.
|
|
972 |
|
|
973 |
previousDirectory isNil ifTrue:[
|
|
974 |
menu disable:#changeToPreviousDirectory.
|
132
|
975 |
].
|
172
|
976 |
^menu.
|
|
977 |
!
|
|
978 |
|
|
979 |
queryForDirectoryToChange
|
|
980 |
"query for new directory"
|
123
|
981 |
|
172
|
982 |
|queryBox|
|
98
|
983 |
|
172
|
984 |
queryBox := FilenameEnterBox
|
|
985 |
title:(resources at:'change directory to:') withCRs
|
|
986 |
okText:(resources at:'change')
|
|
987 |
action:[:newName | self doChangeCurrentDirectoryTo:newName updateHistory:true].
|
|
988 |
"/ queryBox initialText:''.
|
|
989 |
queryBox showAtPointer
|
36
|
990 |
! !
|
|
991 |
|
|
992 |
!FileBrowser methodsFor:'private'!
|
|
993 |
|
172
|
994 |
ask:question yesButton:yesButtonText
|
|
995 |
"common method to ask a yes/no question; return true or false"
|
36
|
996 |
|
172
|
997 |
^ self ask:question yesButton:yesButtonText noButton:'cancel'
|
|
998 |
!
|
93
|
999 |
|
172
|
1000 |
ask:question yesButton:yesButtonText noButton:noButtonText
|
|
1001 |
"common method to ask a yes/no question; return true or false"
|
|
1002 |
|
|
1003 |
self
|
|
1004 |
ask:question
|
|
1005 |
yesButton:yesButtonText
|
|
1006 |
noButton:noButtonText
|
|
1007 |
action:[^ true].
|
|
1008 |
^ false
|
36
|
1009 |
!
|
|
1010 |
|
|
1011 |
ask:question yesButton:yesButtonText noButton:noButtonText action:aBlock
|
|
1012 |
"common method to ask a yes/no question"
|
|
1013 |
|
37
|
1014 |
|yesNoBox|
|
|
1015 |
|
49
|
1016 |
yesNoBox := YesNoBox
|
|
1017 |
title:question withCRs
|
|
1018 |
yesText:(resources at:yesButtonText)
|
|
1019 |
noText:(resources at:noButtonText).
|
36
|
1020 |
yesNoBox okAction:aBlock.
|
|
1021 |
yesNoBox showAtPointer
|
|
1022 |
!
|
|
1023 |
|
172
|
1024 |
askForCommandThenDo:aBlock
|
|
1025 |
"setup and launch a querybox to ask for unix command.
|
|
1026 |
Then evaluate aBlock passing the command-string as argument."
|
93
|
1027 |
|
172
|
1028 |
|fileName sel box|
|
93
|
1029 |
|
172
|
1030 |
box := FilenameEnterBox
|
|
1031 |
title:(resources at:'execute unix command:')
|
|
1032 |
okText:(resources at:'execute')
|
|
1033 |
action:aBlock.
|
79
|
1034 |
|
172
|
1035 |
sel := fileListView selection.
|
|
1036 |
sel size == 1 ifTrue:[
|
|
1037 |
fileName := fileList at:sel first
|
|
1038 |
].
|
|
1039 |
fileName notNil ifTrue:[
|
|
1040 |
self initialCommandFor:fileName into:box.
|
|
1041 |
].
|
|
1042 |
box directory:currentDirectory pathName asFilename.
|
|
1043 |
box showAtPointer
|
36
|
1044 |
|
172
|
1045 |
"Modified: 7.9.1995 / 10:31:54 / claus"
|
36
|
1046 |
!
|
|
1047 |
|
98
|
1048 |
askIfModified:question yesButton:yesButtonText
|
|
1049 |
"tell user, that code has been modified - let her confirm"
|
|
1050 |
|
|
1051 |
(subView modified not or:[subView contentsWasSaved]) ifTrue:[
|
|
1052 |
^ true
|
|
1053 |
].
|
|
1054 |
^ self
|
|
1055 |
ask:(resources string:question)
|
|
1056 |
yesButton:yesButtonText
|
|
1057 |
!
|
|
1058 |
|
172
|
1059 |
binaryFileAction:aFilename
|
|
1060 |
"for some binary files, if double clicked, we can do some useful
|
|
1061 |
action ..."
|
|
1062 |
|
|
1063 |
|isImage img|
|
36
|
1064 |
|
172
|
1065 |
(currentDirectory pathName , '/' , aFilename) asFilename isExecutable ifTrue:[
|
|
1066 |
(OperatingSystem executeCommand:'cd ',currentDirectory pathName, '; ',aFilename)
|
|
1067 |
ifTrue:[^true].
|
|
1068 |
].
|
|
1069 |
isImage := false.
|
|
1070 |
(aFilename endsWith:'.gif') ifTrue:[isImage := true].
|
|
1071 |
(aFilename endsWith:'.tiff') ifTrue:[isImage := true].
|
|
1072 |
(aFilename endsWith:'.pnm') ifTrue:[isImage := true].
|
|
1073 |
(aFilename endsWith:'.xbm') ifTrue:[isImage := true].
|
|
1074 |
isImage ifTrue:[
|
|
1075 |
img := Image fromFile:(currentDirectory pathName , '/' , aFilename).
|
|
1076 |
img notNil ifTrue:[
|
|
1077 |
img inspect.
|
|
1078 |
^ true
|
120
|
1079 |
]
|
36
|
1080 |
].
|
172
|
1081 |
^ false
|
|
1082 |
|
|
1083 |
"Created: 14.9.1995 / 10:23:10 / claus"
|
36
|
1084 |
!
|
|
1085 |
|
172
|
1086 |
changeToPreviousDirectory
|
|
1087 |
"if text was modified show a queryBox,
|
|
1088 |
otherwise change immediately to previous directory."
|
93
|
1089 |
|
172
|
1090 |
previousDirectory isNil ifTrue:[^ self].
|
|
1091 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.'
|
|
1092 |
yesButton:'change') ifTrue:[
|
|
1093 |
self doChangeCurrentDirectoryTo:previousDirectory updateHistory:false
|
|
1094 |
]
|
36
|
1095 |
!
|
|
1096 |
|
98
|
1097 |
checkIfDirectoryHasChanged
|
|
1098 |
"every checkDelta secs, check if directoy has changed and update the list if so.
|
|
1099 |
Also, we check if the file shown has been touched in the meanwhile (for example,
|
|
1100 |
from another browser) and say 'outdated' in the label if so.
|
|
1101 |
This avoids confusion if the same file is being edited by two browsers. (or other editors).
|
|
1102 |
If the text shown in the codeView has been edited, 'modified' is shown.
|
|
1103 |
"
|
|
1104 |
|
|
1105 |
|oldSelection nOld here newState msg newLabel|
|
|
1106 |
|
|
1107 |
shown ifTrue:[
|
|
1108 |
currentDirectory notNil ifTrue:[
|
|
1109 |
lockUpdate ifTrue:[
|
|
1110 |
Processor removeTimedBlock:checkBlock.
|
|
1111 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta.
|
|
1112 |
^ self
|
|
1113 |
].
|
|
1114 |
|
|
1115 |
subView modified ifTrue:[
|
|
1116 |
newState := ' (modified)'
|
|
1117 |
].
|
|
1118 |
|
|
1119 |
here := currentDirectory pathName.
|
|
1120 |
(OperatingSystem isReadable:here) ifTrue:[
|
|
1121 |
Processor removeTimedBlock:checkBlock.
|
|
1122 |
|
|
1123 |
(currentDirectory timeOfLastChange > timeOfLastCheck) ifTrue:[
|
|
1124 |
nOld := fileListView numberOfSelections.
|
|
1125 |
oldSelection := fileListView selectionValue.
|
|
1126 |
self updateCurrentDirectory.
|
|
1127 |
nOld ~~ 0 ifTrue:[
|
|
1128 |
nOld > 1 ifTrue:[
|
|
1129 |
oldSelection do:[:element |
|
|
1130 |
fileListView addElementToSelection:element
|
|
1131 |
]
|
|
1132 |
] ifFalse:[
|
|
1133 |
fileListView selectElementWithoutScroll:oldSelection
|
|
1134 |
]
|
|
1135 |
].
|
|
1136 |
] ifFalse:[
|
|
1137 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta
|
|
1138 |
].
|
|
1139 |
|
|
1140 |
currentFileName notNil ifTrue:[
|
|
1141 |
(currentDirectory exists:currentFileName) ifFalse:[
|
|
1142 |
newState := ' (removed)'.
|
|
1143 |
] ifTrue:[
|
|
1144 |
(currentDirectory timeOfLastChange:currentFileName) > timeOfFileRead ifTrue:[
|
|
1145 |
newState := ' (outdated)'.
|
|
1146 |
subView modified ifTrue:[
|
|
1147 |
newState := ' (modified & outdated)'
|
|
1148 |
]
|
|
1149 |
].
|
|
1150 |
].
|
|
1151 |
].
|
|
1152 |
|
|
1153 |
] ifFalse:[
|
|
1154 |
"
|
|
1155 |
if the directory has been deleted, or is not readable ...
|
|
1156 |
"
|
|
1157 |
(OperatingSystem isValidPath:here) ifFalse:[
|
|
1158 |
msg := 'FileBrowser:\\directory %1 is gone ?!!?'
|
|
1159 |
] ifTrue:[
|
|
1160 |
msg := 'FileBrowser:\\directory %1 is no longer readable ?!!?'
|
|
1161 |
].
|
|
1162 |
self warn:(resources string:msg with:here) withCRs.
|
|
1163 |
|
|
1164 |
fileListView contents:nil.
|
|
1165 |
newLabel := myName , ': directory is gone !!'.
|
|
1166 |
"/ Processor addTimedBlock:checkBlock afterSeconds:checkDelta
|
|
1167 |
].
|
|
1168 |
|
|
1169 |
newState notNil ifTrue:[
|
|
1170 |
newLabel := myName.
|
|
1171 |
currentFileName notNil ifTrue:[
|
|
1172 |
newLabel := newLabel , ': ' , currentFileName
|
|
1173 |
].
|
|
1174 |
newLabel := newLabel , newState.
|
|
1175 |
].
|
|
1176 |
newLabel notNil ifTrue:[
|
|
1177 |
self label:newLabel.
|
|
1178 |
]
|
|
1179 |
]
|
|
1180 |
]
|
|
1181 |
!
|
|
1182 |
|
172
|
1183 |
defineTabulatorsForLongList
|
|
1184 |
"define the tabs for the long list"
|
|
1185 |
|
|
1186 |
tabSpec := TabulatorSpecification new.
|
|
1187 |
tabSpec unit:#inch.
|
|
1188 |
"/ tabSpec positions:#(0 2 2.3 4.3 5.3 6.0 6.5).
|
|
1189 |
tabSpec widths: #(2 0.3 1.7 1 0.5 0.5 1"any").
|
|
1190 |
" name type mode owner group size type"
|
|
1191 |
tabSpec align: #(#left #left #left #right #right #decimal #left).
|
|
1192 |
tabSpec addDependent:self
|
|
1193 |
!
|
|
1194 |
|
|
1195 |
doChangeCurrentDirectoryTo:fileName updateHistory:updateHistory
|
|
1196 |
"verify argument is name of a readable & executable directory
|
|
1197 |
and if so, go there"
|
|
1198 |
|
|
1199 |
|msg path idx|
|
|
1200 |
|
|
1201 |
self label:myName; iconLabel:myName.
|
|
1202 |
fileName notNil ifTrue:[
|
|
1203 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
1204 |
(currentDirectory isReadable:fileName) ifTrue:[
|
|
1205 |
(currentDirectory isExecutable:fileName) ifTrue:[
|
|
1206 |
|
|
1207 |
path := currentDirectory pathName.
|
|
1208 |
previousDirectory := path.
|
|
1209 |
|
|
1210 |
"
|
|
1211 |
remember where we are in the fileList
|
|
1212 |
(in case we want to return)
|
|
1213 |
"
|
|
1214 |
idx := DirectoryHistory indexOf:path.
|
|
1215 |
idx ~~ 0 ifTrue:[
|
|
1216 |
DirectoryHistoryWhere at:idx put:fileListView firstLineShown
|
|
1217 |
].
|
|
1218 |
|
|
1219 |
self setCurrentDirectory:fileName.
|
|
1220 |
|
|
1221 |
path := currentDirectory pathName.
|
|
1222 |
|
|
1223 |
"
|
|
1224 |
if we have already been there, look for the
|
|
1225 |
position offset, and scroll the fileList
|
|
1226 |
"
|
|
1227 |
idx := DirectoryHistory indexOf:path.
|
|
1228 |
idx ~~ 0 ifTrue:[
|
|
1229 |
|pos|
|
|
1230 |
|
|
1231 |
pos := DirectoryHistoryWhere at:idx.
|
|
1232 |
pos notNil ifTrue:[
|
|
1233 |
fileListView scrollToLine:pos
|
|
1234 |
]
|
|
1235 |
].
|
|
1236 |
|
|
1237 |
updateHistory ifTrue:[
|
|
1238 |
|pos|
|
|
1239 |
|
|
1240 |
(DirectoryHistory includes:path) ifFalse:[
|
|
1241 |
DirectoryHistory size >= HistorySize ifTrue:[
|
|
1242 |
DirectoryHistory removeLast.
|
|
1243 |
DirectoryHistoryWhere removeLast
|
|
1244 |
]
|
|
1245 |
] ifTrue:[
|
|
1246 |
"already been there before; move the entry to
|
|
1247 |
the beginning, so it will fall out later."
|
|
1248 |
|
|
1249 |
idx := DirectoryHistory indexOf:path.
|
|
1250 |
DirectoryHistory removeIndex:idx.
|
|
1251 |
pos := DirectoryHistoryWhere at:idx.
|
|
1252 |
DirectoryHistoryWhere removeIndex:idx.
|
|
1253 |
].
|
|
1254 |
DirectoryHistory addFirst:path.
|
|
1255 |
DirectoryHistoryWhere addFirst:pos.
|
|
1256 |
].
|
|
1257 |
|
|
1258 |
^ self
|
|
1259 |
].
|
|
1260 |
msg := 'cannot change directory to ''%1'' !!'
|
|
1261 |
] ifFalse:[
|
|
1262 |
msg := 'cannot read directory ''%1'' !!'
|
|
1263 |
]
|
|
1264 |
] ifFalse:[
|
|
1265 |
msg := '''%1'' is not a directory !!'
|
|
1266 |
].
|
|
1267 |
self showAlert:(resources string:msg with:fileName) with:nil
|
|
1268 |
]
|
|
1269 |
!
|
|
1270 |
|
|
1271 |
doChangeToHomeDirectory
|
|
1272 |
"go to home directory"
|
|
1273 |
|
|
1274 |
self doChangeCurrentDirectoryTo:(OperatingSystem getHomeDirectory) updateHistory:true
|
|
1275 |
!
|
|
1276 |
|
|
1277 |
doChangeToParentDirectory
|
|
1278 |
"go to home directory"
|
36
|
1279 |
|
172
|
1280 |
self doChangeCurrentDirectoryTo:'..' updateHistory:true
|
|
1281 |
!
|
|
1282 |
|
|
1283 |
doCreateDirectory:newName
|
|
1284 |
(currentDirectory includes:newName) ifTrue:[
|
|
1285 |
self warn:'%1 already exists.' with:newName.
|
|
1286 |
^ self
|
|
1287 |
].
|
|
1288 |
|
|
1289 |
(currentDirectory createDirectory:newName) ifTrue:[
|
|
1290 |
self updateCurrentDirectory
|
|
1291 |
] ifFalse:[
|
|
1292 |
self showAlert:(resources string:'cannot create directory ''%1'' !!' with:newName)
|
|
1293 |
with:(OperatingSystem lastErrorString)
|
|
1294 |
]
|
|
1295 |
!
|
|
1296 |
|
|
1297 |
doCreateFile:newName
|
|
1298 |
|aStream|
|
|
1299 |
|
|
1300 |
(currentDirectory includes:newName) ifTrue:[
|
|
1301 |
(self
|
|
1302 |
ask:(resources string:'%1 already exists\\truncate ?' with:newName)
|
|
1303 |
yesButton:'truncate'
|
|
1304 |
noButton:'cancel'
|
|
1305 |
) ifFalse:[^ self].
|
|
1306 |
].
|
|
1307 |
|
|
1308 |
aStream := FileStream newFileNamed:newName in:currentDirectory.
|
|
1309 |
aStream notNil ifTrue:[
|
|
1310 |
aStream close.
|
|
1311 |
self updateCurrentDirectory
|
|
1312 |
] ifFalse:[
|
|
1313 |
self showAlert:(resources string:'cannot create file ''%1'' !!' with:newName)
|
|
1314 |
with:(FileStream lastErrorString)
|
|
1315 |
]
|
|
1316 |
!
|
|
1317 |
|
|
1318 |
doExecuteCommand:command replace:replace
|
|
1319 |
"execute a unix command inserting the output of the command.
|
|
1320 |
If replace is true, all text is replaced by the commands output;
|
|
1321 |
otherwise, its inserted as selected text at the cursor position."
|
|
1322 |
|
|
1323 |
|stream line lnr myProcess myPriority startLine startCol stopSignal
|
|
1324 |
access|
|
|
1325 |
|
|
1326 |
access := Semaphore forMutualExclusion.
|
|
1327 |
stopSignal := Signal new.
|
|
1328 |
|
|
1329 |
"
|
|
1330 |
must take killButton out of my group
|
|
1331 |
"
|
|
1332 |
windowGroup removeView:killButton.
|
|
1333 |
"
|
|
1334 |
bring it to front, and turn hidden-mode off
|
|
1335 |
"
|
|
1336 |
killButton raise.
|
|
1337 |
killButton hiddenOnRealize:false.
|
|
1338 |
"
|
|
1339 |
it will make me raise stopSignal when pressed
|
|
1340 |
"
|
|
1341 |
killButton
|
|
1342 |
action:[
|
|
1343 |
stream notNil ifTrue:[
|
|
1344 |
access critical:[
|
|
1345 |
myProcess interruptWith:[stopSignal raise].
|
|
1346 |
]
|
|
1347 |
]
|
|
1348 |
].
|
|
1349 |
"
|
|
1350 |
start it up under its own windowgroup
|
|
1351 |
"
|
|
1352 |
killButton openAutonomous.
|
|
1353 |
|
|
1354 |
"
|
|
1355 |
go fork a pipe and read it
|
|
1356 |
"
|
|
1357 |
self label:(myName , ': executing ' , (command copyTo:(20 min:command size)) , ' ...').
|
|
1358 |
[
|
|
1359 |
self withWaitCursorDo:[
|
|
1360 |
stopSignal catch:[
|
|
1361 |
startLine := subView cursorLine.
|
|
1362 |
startCol := subView cursorCol.
|
|
1363 |
|
|
1364 |
stream := PipeStream readingFrom:('cd '
|
|
1365 |
, currentDirectory pathName
|
|
1366 |
, '; '
|
|
1367 |
, command
|
|
1368 |
, ' 2>&1' ).
|
|
1369 |
stream notNil ifTrue:[
|
|
1370 |
"
|
|
1371 |
this can be a time consuming operation; therefore lower my priority
|
|
1372 |
"
|
|
1373 |
myProcess := Processor activeProcess.
|
|
1374 |
myPriority := myProcess priority.
|
|
1375 |
myProcess priority:(Processor userBackgroundPriority).
|
36
|
1376 |
|
172
|
1377 |
[
|
|
1378 |
|codeView lines|
|
|
1379 |
|
|
1380 |
codeView := subView.
|
|
1381 |
|
|
1382 |
replace ifTrue:[
|
|
1383 |
codeView list:nil.
|
|
1384 |
lnr := 1.
|
|
1385 |
].
|
|
1386 |
|
|
1387 |
[stream atEnd] whileFalse:[
|
|
1388 |
(stream readWaitWithTimeoutMs:250) ifFalse:[
|
|
1389 |
"
|
|
1390 |
data available
|
|
1391 |
"
|
|
1392 |
lines := OrderedCollection new:50.
|
|
1393 |
line := stream nextLine.
|
|
1394 |
line notNil ifTrue:[lines add:line].
|
|
1395 |
|
|
1396 |
[stream atEnd not
|
|
1397 |
and:[stream canReadWithoutBlocking
|
|
1398 |
and:[lines size < 50]]] whileTrue:[
|
|
1399 |
line := stream nextLine.
|
|
1400 |
line notNil ifTrue:[lines add:line].
|
|
1401 |
].
|
|
1402 |
|
|
1403 |
"
|
|
1404 |
need this critical section; otherwise,
|
|
1405 |
we could get the signal while waiting for
|
|
1406 |
an expose event ...
|
|
1407 |
"
|
|
1408 |
access critical:[
|
|
1409 |
lines size > 0 ifTrue:[
|
|
1410 |
replace ifTrue:[
|
|
1411 |
lines do:[:line |
|
|
1412 |
codeView at:lnr put:line withTabsExpanded.
|
|
1413 |
codeView cursorToBottom; cursorDown.
|
|
1414 |
lnr := lnr + 1.
|
|
1415 |
].
|
|
1416 |
] ifFalse:[
|
|
1417 |
codeView insertLines:lines before:codeView cursorLine.
|
|
1418 |
codeView cursorDown:lines size.
|
|
1419 |
"/ lines do:[:line |
|
|
1420 |
"/ codeView insertLine:line withTabsExpanded before:codeView cursorLine.
|
|
1421 |
"/ codeView cursorDown.
|
|
1422 |
"/ ]
|
|
1423 |
"/ codeView insertStringAtCursor:line.
|
|
1424 |
"/ codeView insertCharAtCursor:(Character cr).
|
|
1425 |
]
|
|
1426 |
].
|
|
1427 |
].
|
|
1428 |
].
|
|
1429 |
|
|
1430 |
shown ifTrue:[windowGroup processExposeEvents].
|
|
1431 |
"
|
|
1432 |
give others running at same prio a chance too
|
|
1433 |
(especially other FileBrowsers doing the same)
|
|
1434 |
"
|
|
1435 |
Processor yield
|
|
1436 |
].
|
|
1437 |
] valueNowOrOnUnwindDo:[
|
|
1438 |
stream close. stream := nil.
|
|
1439 |
].
|
|
1440 |
self updateCurrentDirectory
|
|
1441 |
].
|
|
1442 |
replace ifTrue:[
|
|
1443 |
subView modified:false.
|
|
1444 |
].
|
45
|
1445 |
]
|
172
|
1446 |
]
|
|
1447 |
] valueNowOrOnUnwindDo:[
|
|
1448 |
|wg|
|
|
1449 |
|
|
1450 |
self label:myName; iconLabel:myName.
|
|
1451 |
myProcess notNil ifTrue:[myProcess priority:myPriority].
|
|
1452 |
|
|
1453 |
"
|
|
1454 |
remove the killButton from its group
|
|
1455 |
(otherwise, it will be destroyed when we shut down the group)
|
|
1456 |
"
|
|
1457 |
wg := killButton windowGroup.
|
|
1458 |
killButton windowGroup:nil.
|
|
1459 |
"
|
|
1460 |
shut down the windowgroup
|
|
1461 |
"
|
|
1462 |
wg notNil ifTrue:[
|
|
1463 |
wg process terminate.
|
|
1464 |
].
|
|
1465 |
"
|
|
1466 |
hide the button, and make sure it will stay
|
|
1467 |
hidden when we are realized again
|
|
1468 |
"
|
|
1469 |
killButton unrealize.
|
|
1470 |
killButton hiddenOnRealize:true.
|
|
1471 |
"
|
|
1472 |
clear its action (actually not needed, but
|
|
1473 |
releases reference to thisContext earlier)
|
|
1474 |
"
|
|
1475 |
killButton action:nil.
|
36
|
1476 |
].
|
172
|
1477 |
|
|
1478 |
currentFileName isNil ifTrue:[
|
|
1479 |
subView modified:false.
|
|
1480 |
].
|
|
1481 |
|
|
1482 |
subView size > 10000 ifTrue:[
|
|
1483 |
self warn:'text quite large now - please cut off some lines'
|
|
1484 |
]
|
|
1485 |
|
|
1486 |
"Modified: 21.9.1995 / 11:18:46 / claus"
|
|
1487 |
!
|
|
1488 |
|
|
1489 |
doFileGet
|
|
1490 |
"get selected file - show contents in subView"
|
|
1491 |
|
|
1492 |
|fileName|
|
|
1493 |
|
|
1494 |
self withCursor:(Cursor read) do:[
|
|
1495 |
fileName := self getSelectedFileName.
|
|
1496 |
fileName notNil ifTrue:[
|
|
1497 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
1498 |
self doChangeCurrentDirectoryTo:fileName updateHistory:true.
|
|
1499 |
self label:myName.
|
|
1500 |
self iconLabel:myName
|
|
1501 |
] ifFalse:[
|
|
1502 |
(currentDirectory exists:fileName) ifFalse:[
|
|
1503 |
self warn:(resources string:'oops, ''%1'' is gone' with:fileName).
|
|
1504 |
^ self
|
|
1505 |
].
|
|
1506 |
timeOfFileRead := currentDirectory timeOfLastChange:fileName.
|
|
1507 |
self showFile:fileName insert:false.
|
|
1508 |
currentFileName := fileName.
|
|
1509 |
|
|
1510 |
subView acceptAction:[:theCode |
|
|
1511 |
self writeFile:fileName text:theCode.
|
|
1512 |
timeOfFileRead := currentDirectory timeOfLastChange:fileName.
|
|
1513 |
self label:myName , ': ' , currentFileName
|
|
1514 |
].
|
|
1515 |
|
|
1516 |
(currentDirectory isWritable:fileName) ifFalse:[
|
|
1517 |
self label:(myName , ': ' , fileName , ' (readonly)')
|
|
1518 |
] ifTrue:[
|
|
1519 |
self label:(myName , ': ' , fileName)
|
|
1520 |
].
|
|
1521 |
self iconLabel:fileName
|
|
1522 |
]
|
|
1523 |
]
|
|
1524 |
]
|
|
1525 |
!
|
|
1526 |
|
|
1527 |
doRemove
|
|
1528 |
"remove the selected file(s) - no questions asked"
|
|
1529 |
|
|
1530 |
|ok msg dir|
|
|
1531 |
|
|
1532 |
lockUpdate := true.
|
|
1533 |
[
|
|
1534 |
self selectedFilesDo:[:fileName |
|
|
1535 |
ok := false.
|
|
1536 |
(currentDirectory isDirectory:fileName) ifTrue:[
|
|
1537 |
dir := FileDirectory directoryNamed:fileName in:currentDirectory.
|
|
1538 |
dir isEmpty ifFalse:[
|
|
1539 |
(self ask:(resources string:'directory ''%1'' is not empty\remove anyway ?' with:fileName)
|
|
1540 |
yesButton:'remove') ifTrue:[
|
|
1541 |
ok := currentDirectory removeDirectory:fileName
|
|
1542 |
]
|
|
1543 |
] ifTrue:[
|
|
1544 |
ok := currentDirectory removeDirectory:fileName
|
|
1545 |
].
|
|
1546 |
] ifFalse:[
|
|
1547 |
ok := currentDirectory remove:fileName.
|
|
1548 |
].
|
|
1549 |
ok ifFalse:[
|
|
1550 |
"was not able to remove it"
|
|
1551 |
msg := (resources string:'cannot remove ''%1'' !!' with:fileName).
|
|
1552 |
self showAlert:msg with:(OperatingSystem lastErrorString)
|
|
1553 |
] ifTrue:[
|
|
1554 |
"
|
|
1555 |
self show:nil
|
|
1556 |
"
|
|
1557 |
]
|
|
1558 |
].
|
|
1559 |
] valueNowOrOnUnwindDo:[
|
|
1560 |
lockUpdate := false.
|
|
1561 |
fileListView deselect.
|
|
1562 |
self updateCurrentDirectory.
|
|
1563 |
]
|
|
1564 |
!
|
|
1565 |
|
|
1566 |
doRename:oldName to:newName
|
|
1567 |
(oldName notNil and:[newName notNil]) ifTrue:[
|
|
1568 |
(oldName isBlank or:[newName isBlank]) ifFalse:[
|
|
1569 |
currentDirectory renameFile:oldName newName:newName.
|
|
1570 |
self updateCurrentDirectory.
|
|
1571 |
]
|
|
1572 |
]
|
36
|
1573 |
!
|
|
1574 |
|
|
1575 |
getFileInfoString:longInfo
|
|
1576 |
"get stat info on selected file - return a string which can be
|
|
1577 |
shown in a box"
|
|
1578 |
|
133
|
1579 |
|fileName f fullPath text info fileOutput type modeBits modeString s ts|
|
36
|
1580 |
|
|
1581 |
fileName := self getSelectedFileName.
|
|
1582 |
fileName isNil ifTrue:[^ nil].
|
|
1583 |
|
133
|
1584 |
f := currentDirectory pathName asFilename construct:fileName.
|
|
1585 |
info := f info.
|
|
1586 |
|
|
1587 |
"/ info := currentDirectory infoOf:fileName.
|
36
|
1588 |
info isNil ifTrue:[
|
45
|
1589 |
self showAlert:(resources string:'cannot get info of ''%1'' !!' with:fileName)
|
|
1590 |
with:(OperatingSystem lastErrorString).
|
|
1591 |
^ nil
|
36
|
1592 |
].
|
|
1593 |
|
59
|
1594 |
text := StringCollection new.
|
133
|
1595 |
f isSymbolicLink ifTrue:[
|
|
1596 |
text add:(resources string:'symbolic link to: %1' with:(f linkInfo at:#path))
|
|
1597 |
].
|
|
1598 |
|
36
|
1599 |
type := info at:#type.
|
|
1600 |
(longInfo and:[type == #regular]) ifTrue:[
|
45
|
1601 |
fullPath := currentDirectory pathName , '/' , fileName.
|
49
|
1602 |
fileOutput := fullPath asFilename fileType.
|
36
|
1603 |
].
|
|
1604 |
|
|
1605 |
s := (resources at:'type: ').
|
|
1606 |
fileOutput isNil ifTrue:[
|
45
|
1607 |
s := s , type asString
|
36
|
1608 |
] ifFalse:[
|
45
|
1609 |
s := s , 'regular (' , fileOutput , ')'
|
36
|
1610 |
].
|
|
1611 |
text add:s.
|
133
|
1612 |
text add:(resources string:'size: %1' with:(info at:#size) printString).
|
36
|
1613 |
|
|
1614 |
modeBits := (info at:#mode).
|
|
1615 |
modeString := self getModeString:modeBits.
|
|
1616 |
longInfo ifTrue:[
|
133
|
1617 |
text add:(resources string:'access: %1 (%2)'
|
|
1618 |
with:modeString
|
|
1619 |
with:(modeBits printStringRadix:8))
|
36
|
1620 |
] ifFalse:[
|
133
|
1621 |
text add:(resources string:'access: %1' with:modeString)
|
36
|
1622 |
].
|
133
|
1623 |
text add:(resources string:'owner: %1'
|
|
1624 |
with:(OperatingSystem getUserNameFromID:(info at:#uid))).
|
36
|
1625 |
longInfo ifTrue:[
|
133
|
1626 |
text add:(resources string:'group: %1'
|
|
1627 |
with:(OperatingSystem getGroupNameFromID:(info at:#gid))).
|
36
|
1628 |
|
133
|
1629 |
ts := info at:#accessed.
|
|
1630 |
text add:(resources string:'last access: %1 %2'
|
|
1631 |
with:(ts asTime printString)
|
|
1632 |
with:(ts asDate printString)).
|
|
1633 |
|
|
1634 |
ts := info at:#modified.
|
|
1635 |
text add:(resources string:'last modification: %1 %2'
|
|
1636 |
with:(ts asTime printString)
|
|
1637 |
with:(ts asDate printString)).
|
36
|
1638 |
].
|
|
1639 |
^ text asString
|
133
|
1640 |
|
|
1641 |
"Modified: 8.9.1995 / 11:59:28 / claus"
|
36
|
1642 |
!
|
|
1643 |
|
172
|
1644 |
getInfoFile
|
|
1645 |
"get filename of a description-file (.dir.info, README etc.);
|
|
1646 |
This file is automatically shown when a directory is enterred.
|
|
1647 |
You can add more names below if you like."
|
|
1648 |
|
|
1649 |
#( '.dir.info'
|
|
1650 |
'README'
|
|
1651 |
'ReadMe'
|
|
1652 |
'Readme'
|
|
1653 |
'readme'
|
|
1654 |
) do:[:f |
|
|
1655 |
(currentDirectory isReadable:f) ifTrue:[
|
|
1656 |
(currentDirectory isDirectory:f) ifFalse:[^ f].
|
|
1657 |
]
|
|
1658 |
].
|
|
1659 |
^ nil
|
|
1660 |
!
|
|
1661 |
|
|
1662 |
getModeString:modeBits
|
|
1663 |
"convert file-mode bits into a more user-friendly string.
|
|
1664 |
This is wrong here - should be moved into OperatingSystem."
|
|
1665 |
|
|
1666 |
^ self getModeString:modeBits
|
|
1667 |
with:#( 'owner:' $r $w $x
|
|
1668 |
' group:' $r $w $x
|
|
1669 |
' others:' $r $w $x )
|
|
1670 |
!
|
|
1671 |
|
37
|
1672 |
getModeString:modeBits with:texts
|
36
|
1673 |
"convert file-mode bits into a more user-friendly string.
|
|
1674 |
This is wrong here - should be moved into OperatingSystem."
|
|
1675 |
|
|
1676 |
|bits modeString|
|
|
1677 |
|
|
1678 |
bits := modeBits bitAnd:8r777.
|
|
1679 |
modeString := ''.
|
|
1680 |
|
|
1681 |
#( nil 8r400 8r200 8r100 nil 8r040 8r020 8r010 nil 8r004 8r002 8r001 )
|
37
|
1682 |
with: texts do:[:bitMask :access |
|
116
|
1683 |
|ch|
|
|
1684 |
|
45
|
1685 |
bitMask isNil ifTrue:[
|
|
1686 |
modeString := modeString , (resources string:access)
|
|
1687 |
] ifFalse:[
|
|
1688 |
(bits bitAnd:bitMask) == 0 ifTrue:[
|
116
|
1689 |
ch := $-
|
45
|
1690 |
] ifFalse:[
|
116
|
1691 |
ch := access
|
|
1692 |
].
|
|
1693 |
modeString := modeString copyWith:ch
|
45
|
1694 |
]
|
36
|
1695 |
].
|
|
1696 |
^ modeString
|
|
1697 |
!
|
|
1698 |
|
172
|
1699 |
getSelectedFileName
|
|
1700 |
"returns the currently selected file; shows an error if
|
|
1701 |
multiple files are selected"
|
|
1702 |
|
|
1703 |
|sel|
|
|
1704 |
|
|
1705 |
sel := fileListView selection.
|
|
1706 |
(sel size > 1) ifTrue:[
|
|
1707 |
self onlyOneSelection
|
|
1708 |
] ifFalse:[
|
|
1709 |
sel notNil ifTrue:[
|
|
1710 |
^ fileList at:sel first
|
|
1711 |
]
|
|
1712 |
].
|
|
1713 |
^ nil
|
|
1714 |
!
|
|
1715 |
|
|
1716 |
initialCommandFor:fileName into:aBox
|
|
1717 |
"set a useful initial command for execute box.
|
|
1718 |
|
|
1719 |
XXX should be changed to take stuff from a config file
|
|
1720 |
XXX or from resources."
|
|
1721 |
|
|
1722 |
((currentDirectory typeOf:fileName) == #regular) ifTrue:[
|
|
1723 |
|
|
1724 |
(currentDirectory isExecutable:fileName) ifTrue:[
|
|
1725 |
aBox initialText:(fileName , '<arguments>').
|
|
1726 |
^ self
|
|
1727 |
].
|
|
1728 |
|
|
1729 |
"some heuristics - my personal preferences ...
|
|
1730 |
(actually this should come from a configfile)"
|
|
1731 |
|
|
1732 |
(fileName endsWith:'akefile') ifTrue:[
|
|
1733 |
aBox initialText:'make target' selectFrom:6 to:11.
|
|
1734 |
^ self
|
|
1735 |
].
|
|
1736 |
(fileName endsWith:'.tar.Z') ifTrue:[
|
|
1737 |
aBox initialText:'zcat ' , fileName , ' | tar tvf -'.
|
|
1738 |
^ self
|
|
1739 |
].
|
|
1740 |
(fileName endsWith:'.taz') ifTrue:[
|
|
1741 |
aBox initialText:'zcat ' , fileName , ' | tar tvf -'.
|
|
1742 |
^ self
|
|
1743 |
].
|
|
1744 |
(fileName endsWith:'.tar') ifTrue:[
|
|
1745 |
aBox initialText:'tar tvf ' , fileName selectFrom:1 to:7.
|
|
1746 |
^ self
|
|
1747 |
].
|
|
1748 |
(fileName endsWith:'.zoo') ifTrue:[
|
|
1749 |
aBox initialText:'zoo -list ' , fileName selectFrom:1 to:9.
|
|
1750 |
^ self
|
|
1751 |
].
|
|
1752 |
(fileName endsWith:'.zip') ifTrue:[
|
|
1753 |
aBox initialText:'unzip -l ' , fileName selectFrom:1 to:8.
|
|
1754 |
^ self
|
|
1755 |
].
|
|
1756 |
(fileName endsWith:'.Z') ifTrue:[
|
|
1757 |
aBox initialText:'uncompress ' , fileName selectFrom:1 to:10.
|
|
1758 |
^ self
|
|
1759 |
].
|
|
1760 |
(fileName endsWith:'tar.gz') ifTrue:[
|
|
1761 |
aBox initialText:('gunzip <' , fileName , ' | tar tvf -' ).
|
|
1762 |
^ self
|
|
1763 |
].
|
|
1764 |
(fileName endsWith:'.gz') ifTrue:[
|
|
1765 |
aBox initialText:('gunzip <' , fileName , ' >' , (fileName copyWithoutLast:3 "copyTo:(fileName size - 3)")).
|
|
1766 |
^ self
|
|
1767 |
].
|
|
1768 |
(fileName endsWith:'.html') ifTrue:[
|
|
1769 |
aBox initialText:'chimera ' , fileName .
|
|
1770 |
^ self
|
|
1771 |
].
|
|
1772 |
(fileName endsWith:'.uue') ifTrue:[
|
|
1773 |
aBox initialText:'uudecode ' , fileName selectFrom:1 to:8.
|
|
1774 |
^ self
|
|
1775 |
].
|
|
1776 |
(fileName endsWith:'.c') ifTrue:[
|
|
1777 |
aBox initialText:'cc -c ' , fileName selectFrom:1 to:5.
|
|
1778 |
^ self
|
|
1779 |
].
|
|
1780 |
(fileName endsWith:'.cc') ifTrue:[
|
|
1781 |
aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6.
|
|
1782 |
^ self
|
|
1783 |
].
|
|
1784 |
(fileName endsWith:'.C') ifTrue:[
|
|
1785 |
aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6.
|
|
1786 |
^ self
|
|
1787 |
].
|
|
1788 |
(fileName endsWith:'.xbm') ifTrue:[
|
|
1789 |
aBox initialText:'bitmap ' , fileName selectFrom:1 to:6.
|
|
1790 |
^ self
|
|
1791 |
].
|
|
1792 |
((fileName endsWith:'.ps') or:[fileName endsWith:'.PS']) ifTrue:[
|
|
1793 |
aBox initialText:'ghostview ' , fileName selectFrom:1 to:9.
|
|
1794 |
^ self
|
|
1795 |
].
|
|
1796 |
((fileName endsWith:'.1')
|
|
1797 |
or:[fileName endsWith:'.man']) ifTrue:[
|
|
1798 |
aBox initialText:'nroff -man ' , fileName selectFrom:1 to:10.
|
|
1799 |
^ self
|
|
1800 |
].
|
|
1801 |
aBox initialText:'<cmd> ' , fileName selectFrom:1 to:5
|
|
1802 |
]
|
|
1803 |
!
|
|
1804 |
|
|
1805 |
onlyOneSelection
|
|
1806 |
"show a warning, that only one file must be selected for
|
|
1807 |
this operation"
|
|
1808 |
|
|
1809 |
self warn:'exactly one file must be selected !!'
|
|
1810 |
!
|
|
1811 |
|
|
1812 |
readFile:fileName
|
|
1813 |
"read in the file, answer its contents as StringCollection"
|
|
1814 |
|
|
1815 |
^ self readFile:fileName lineDelimiter:Character cr
|
|
1816 |
!
|
|
1817 |
|
|
1818 |
readFile:fileName lineDelimiter:aCharacter
|
|
1819 |
"read in the file, answer its contents as StringCollection.
|
|
1820 |
The files lines are delimited by aCharacter."
|
|
1821 |
|
|
1822 |
|stream text msg sz|
|
|
1823 |
|
|
1824 |
stream := FileStream readonlyFileNamed:fileName in:currentDirectory.
|
|
1825 |
stream isNil ifTrue:[
|
|
1826 |
msg := (resources string:'cannot read file ''%1'' !!' with:fileName).
|
|
1827 |
self showAlert:msg with:(FileStream lastErrorString).
|
|
1828 |
^ nil
|
|
1829 |
].
|
|
1830 |
|
|
1831 |
"
|
|
1832 |
for very big files, give ObjectMemory a hint, to preallocate more
|
|
1833 |
"
|
|
1834 |
(sz := stream size) > 1000000 ifTrue:[
|
|
1835 |
Processor activeProcess withLowerPriorityDo:[
|
|
1836 |
ObjectMemory announceSpaceNeed:(sz + (sz // 5)) "/ add 20% for tab expansion
|
|
1837 |
].
|
|
1838 |
].
|
|
1839 |
|
|
1840 |
text := self readStream:stream lineDelimiter:aCharacter.
|
|
1841 |
stream close.
|
|
1842 |
^ text
|
|
1843 |
!
|
|
1844 |
|
|
1845 |
readStream:aStream
|
|
1846 |
"read in from aStream, answer its contents as StringCollection"
|
|
1847 |
|
|
1848 |
^ self readStream:aStream lineDelimiter:Character cr
|
|
1849 |
!
|
|
1850 |
|
|
1851 |
readStream:aStream lineDelimiter:aCharacter
|
|
1852 |
"read from aStream, answer its contents as StringCollection.
|
|
1853 |
The files lines are delimited by aCharacter."
|
|
1854 |
|
|
1855 |
|text line|
|
37
|
1856 |
|
172
|
1857 |
text := StringCollection new.
|
|
1858 |
aCharacter == Character cr ifTrue:[
|
|
1859 |
[aStream atEnd] whileFalse:[
|
|
1860 |
line := aStream nextLine withTabsExpanded.
|
|
1861 |
text add:line
|
|
1862 |
].
|
|
1863 |
] ifFalse:[
|
|
1864 |
[aStream atEnd] whileFalse:[
|
|
1865 |
line := (aStream upTo:aCharacter) withTabsExpanded.
|
|
1866 |
text add:line
|
|
1867 |
].
|
|
1868 |
].
|
|
1869 |
^ text
|
|
1870 |
|
|
1871 |
"Created: 10.9.1995 / 21:54:12 / claus"
|
|
1872 |
!
|
|
1873 |
|
|
1874 |
selectedFilesDo:aBlock
|
|
1875 |
"evaluate aBlock on all selected files;
|
|
1876 |
show a wait cursor while doing this"
|
|
1877 |
|
|
1878 |
|sel|
|
|
1879 |
|
|
1880 |
sel := fileListView selection.
|
|
1881 |
sel notNil ifTrue:[
|
|
1882 |
self withWaitCursorDo:[
|
|
1883 |
sel do:[:aSelectionIndex |
|
|
1884 |
aBlock value:(fileList at:aSelectionIndex )
|
|
1885 |
]
|
|
1886 |
]
|
|
1887 |
]
|
|
1888 |
|
|
1889 |
!
|
|
1890 |
|
|
1891 |
setCurrentDirectory:aPathName
|
|
1892 |
"setup for another directory"
|
|
1893 |
|
|
1894 |
|newDirectory|
|
|
1895 |
|
|
1896 |
aPathName isEmpty ifTrue:[^ self].
|
|
1897 |
(currentDirectory isDirectory:aPathName) ifTrue:[
|
|
1898 |
newDirectory := FileDirectory directoryNamed:aPathName in:currentDirectory.
|
|
1899 |
newDirectory notNil ifTrue:[
|
|
1900 |
self currentDirectory:newDirectory pathName.
|
|
1901 |
currentFileName notNil ifTrue:[
|
|
1902 |
fileListView contents:nil.
|
|
1903 |
currentFileName := nil.
|
|
1904 |
] ifFalse:[
|
|
1905 |
fileListView selection:nil.
|
|
1906 |
fileListView scrollToTop.
|
|
1907 |
].
|
|
1908 |
self updateCurrentDirectory.
|
|
1909 |
self showInfo.
|
|
1910 |
]
|
|
1911 |
]
|
|
1912 |
|
|
1913 |
"Modified: 21.9.1995 / 11:22:45 / claus"
|
|
1914 |
!
|
|
1915 |
|
|
1916 |
show:something
|
|
1917 |
"show something in subview and undef acceptAction"
|
|
1918 |
|
|
1919 |
subView contents:something.
|
|
1920 |
subView acceptAction:nil.
|
|
1921 |
subView modified:false.
|
|
1922 |
currentFileName := nil
|
|
1923 |
!
|
|
1924 |
|
|
1925 |
showAlert:aString with:anErrorString
|
|
1926 |
"show an alertbox, displaying the last Unix-error"
|
|
1927 |
|
|
1928 |
|msg|
|
|
1929 |
|
|
1930 |
anErrorString isNil ifTrue:[
|
|
1931 |
msg := aString
|
|
1932 |
] ifFalse:[
|
|
1933 |
msg := aString , '\\(' , anErrorString , ')'
|
|
1934 |
].
|
|
1935 |
self warn:msg withCRs
|
|
1936 |
!
|
|
1937 |
|
|
1938 |
showFile:fileName
|
|
1939 |
"show contents of fileName in subView"
|
|
1940 |
|
|
1941 |
self showFile:fileName insert:false
|
|
1942 |
!
|
|
1943 |
|
|
1944 |
showFile:fileName insert:insert
|
|
1945 |
"show/insert contents of fileName in subView"
|
|
1946 |
|
|
1947 |
|buffer s n i ok convert text msg|
|
|
1948 |
|
|
1949 |
((currentDirectory typeOf:fileName) == #regular) ifFalse:[
|
|
1950 |
"asked for a non-file - ignore it ..."
|
|
1951 |
(currentDirectory exists:fileName) ifFalse:[
|
|
1952 |
msg := '''%1'' does not exist !!'.
|
|
1953 |
] ifTrue:[
|
|
1954 |
msg := '''%1'' is not a regular file !!'.
|
|
1955 |
].
|
|
1956 |
self warn:(resources string:msg with:fileName).
|
|
1957 |
^ self
|
|
1958 |
].
|
|
1959 |
"
|
|
1960 |
check if file is a text file
|
|
1961 |
"
|
|
1962 |
s := FileStream readonlyFileNamed:fileName in:currentDirectory.
|
|
1963 |
s isNil ifTrue:[
|
|
1964 |
self showAlert:(resources string:'cannot read file ''%1'' !!' with:fileName)
|
|
1965 |
with:(FileStream lastErrorString).
|
|
1966 |
^ nil
|
|
1967 |
].
|
|
1968 |
|
|
1969 |
buffer := String new:300.
|
|
1970 |
n := s nextBytes:300 into:buffer.
|
|
1971 |
s close.
|
|
1972 |
|
|
1973 |
ok := true.
|
|
1974 |
1 to:n do:[:i |
|
|
1975 |
(buffer at:i) isPrintable ifFalse:[ok := false].
|
|
1976 |
].
|
|
1977 |
ok ifFalse:[
|
|
1978 |
(self binaryFileAction:fileName) ifTrue:[^ self].
|
|
1979 |
(self confirm:(resources string:'''%1'' seems to be a binary file - continue anyway ?' with:fileName))
|
|
1980 |
ifFalse:[^ self]
|
|
1981 |
].
|
|
1982 |
|
|
1983 |
convert := false.
|
|
1984 |
ok ifTrue:[
|
|
1985 |
"
|
|
1986 |
check if line delimiter is a cr
|
|
1987 |
"
|
|
1988 |
i := buffer indexOf:Character cr.
|
|
1989 |
i == 0 ifTrue:[
|
|
1990 |
"
|
|
1991 |
no newline found - try cr
|
|
1992 |
"
|
|
1993 |
i := buffer indexOf:(Character value:13).
|
|
1994 |
i ~~ 0 ifTrue:[
|
|
1995 |
convert := self confirm:(resources string:'''%1'' seems to have CR as line delimiter - convert to NL ?' with:fileName).
|
|
1996 |
]
|
|
1997 |
]
|
|
1998 |
].
|
|
1999 |
|
|
2000 |
insert ifFalse:[
|
|
2001 |
"release old text first - we might need the memory in case of huge files
|
|
2002 |
(helps if you have a 4Mb file in the view, and click on another biggy)"
|
|
2003 |
subView contents:nil.
|
|
2004 |
].
|
|
2005 |
|
|
2006 |
convert ifTrue:[
|
|
2007 |
text := self readFile:fileName lineDelimiter:(Character value:13)
|
|
2008 |
] ifFalse:[
|
|
2009 |
text := self readFile:fileName.
|
|
2010 |
].
|
|
2011 |
insert ifFalse:[
|
|
2012 |
self show:text
|
|
2013 |
] ifTrue:[
|
|
2014 |
subView insertSelectedStringAtCursor:text asString
|
|
2015 |
].
|
|
2016 |
!
|
|
2017 |
|
|
2018 |
showInfo
|
|
2019 |
"show directory info when dir has changed"
|
|
2020 |
|
|
2021 |
|info txt|
|
|
2022 |
|
|
2023 |
info := self getInfoFile.
|
|
2024 |
info notNil ifTrue:[
|
|
2025 |
txt := self readFile:info
|
|
2026 |
].
|
|
2027 |
self show:txt.
|
37
|
2028 |
!
|
|
2029 |
|
36
|
2030 |
sizePrintString:size
|
|
2031 |
"helper for update-directory to return a string with a files size.
|
|
2032 |
This one gives the size in byte, Kb or Mb depending on size.
|
|
2033 |
If you dont like this, just uncomment the first statement below."
|
|
2034 |
|
93
|
2035 |
|unitString n|
|
36
|
2036 |
|
|
2037 |
"
|
|
2038 |
^ size printString.
|
|
2039 |
"
|
|
2040 |
unitString := ''.
|
|
2041 |
size < (500 * 1024) ifTrue:[
|
93
|
2042 |
size < 1024 ifTrue:[
|
|
2043 |
n := size
|
45
|
2044 |
] ifFalse:[
|
93
|
2045 |
n := (size * 10 // 1024 / 10.0).
|
45
|
2046 |
unitString := ' Kb'
|
|
2047 |
]
|
36
|
2048 |
] ifFalse:[
|
93
|
2049 |
n := (size * 10 // 1024 // 1024 / 10.0).
|
45
|
2050 |
unitString := ' Mb'
|
36
|
2051 |
].
|
93
|
2052 |
^ (n printStringLeftPaddedTo:5) , unitString.
|
36
|
2053 |
!
|
|
2054 |
|
|
2055 |
updateCurrentDirectory
|
|
2056 |
"update listView with directory contents"
|
|
2057 |
|
142
|
2058 |
|files text len line info modeString
|
53
|
2059 |
prevUid prevGid nameString groupString matchPattern|
|
36
|
2060 |
|
49
|
2061 |
"the code below may look somewhat complex -
|
|
2062 |
it reads the directory first for the names,
|
|
2063 |
then (in a second sweep over the files) gets the
|
|
2064 |
files type and info. This makes the Filebrowsers
|
|
2065 |
list update seem faster, since the fileInfo (i.e. stat-calls)
|
|
2066 |
may take long - especially on NFS-mounted directories.
|
|
2067 |
The file reading is done at lower priority, to let user continue
|
|
2068 |
his work in other views. However, to be fair to other fileBrowser,
|
|
2069 |
which may also read directories at low prio, give up the processor
|
|
2070 |
after every entry. This shares the cpu among all fileBrowsers, so
|
|
2071 |
that browsers reading short directories will finish first.
|
|
2072 |
ST/X users love this behavior ;-)
|
|
2073 |
"
|
|
2074 |
|
36
|
2075 |
self withCursor:(Cursor read) do:[
|
45
|
2076 |
Processor removeTimedBlock:checkBlock.
|
36
|
2077 |
|
58
|
2078 |
timeOfLastCheck := AbsoluteTime now.
|
45
|
2079 |
|
|
2080 |
files := currentDirectory asOrderedCollection.
|
36
|
2081 |
|
45
|
2082 |
matchPattern := filterField contents.
|
|
2083 |
(matchPattern notNil and:[
|
|
2084 |
matchPattern isEmpty not and:[
|
|
2085 |
matchPattern ~= '*']]) ifTrue:[
|
|
2086 |
files := files select:[:aName |
|
|
2087 |
((currentDirectory typeOf:aName) == #directory)
|
|
2088 |
or:[matchPattern match:aName]
|
|
2089 |
].
|
|
2090 |
].
|
|
2091 |
files sort.
|
36
|
2092 |
|
45
|
2093 |
files size == 0 ifTrue:[
|
108
|
2094 |
self information:('directory ', currentDirectory pathName, ' vanished').
|
45
|
2095 |
^ self
|
|
2096 |
].
|
|
2097 |
files := self withoutHiddenFiles:files.
|
49
|
2098 |
fileList := files copy.
|
45
|
2099 |
|
|
2100 |
"
|
|
2101 |
this is a time consuming operation (especially, if reading an
|
|
2102 |
NFS-mounted directory); therefore lower my priority while getting
|
|
2103 |
the files info ...
|
|
2104 |
"
|
|
2105 |
Processor activeProcess withLowerPriorityDo:[
|
49
|
2106 |
|
|
2107 |
"
|
|
2108 |
first show the names only - this is relatively fast
|
|
2109 |
"
|
|
2110 |
fileListView setList:files expandTabs:false.
|
37
|
2111 |
|
49
|
2112 |
"
|
|
2113 |
then walk over the files, adding more info
|
|
2114 |
(since we have to stat each file, this may take a while longer
|
|
2115 |
"
|
|
2116 |
showLongList ifTrue:[
|
53
|
2117 |
tabSpec isNil ifTrue:[self defineTabulatorsForLongList].
|
37
|
2118 |
|
45
|
2119 |
text := OrderedCollection new.
|
49
|
2120 |
files keysAndValuesDo:[:lineIndex :aFileName |
|
142
|
2121 |
|entry col typ f p typeString|
|
37
|
2122 |
|
49
|
2123 |
entry := MultiColListEntry new.
|
|
2124 |
entry tabulatorSpecification:tabSpec.
|
37
|
2125 |
|
45
|
2126 |
"
|
|
2127 |
if multiple FileBrowsers are reading, let others
|
|
2128 |
make some progress too
|
|
2129 |
"
|
49
|
2130 |
windowGroup notNil ifTrue:[windowGroup processExposeEvents].
|
45
|
2131 |
Processor yield.
|
49
|
2132 |
"
|
|
2133 |
could be destroyed in the meanwhile ...
|
|
2134 |
"
|
|
2135 |
realized ifFalse:[^ self].
|
36
|
2136 |
|
45
|
2137 |
len := aFileName size.
|
|
2138 |
(len < 20) ifTrue:[
|
|
2139 |
line := aFileName , (String new:(22 - len))
|
|
2140 |
] ifFalse:[
|
|
2141 |
"can happen on BSD only"
|
|
2142 |
line := (aFileName copyTo:20) , ' '
|
|
2143 |
].
|
49
|
2144 |
entry colAt:1 put:line.
|
37
|
2145 |
|
45
|
2146 |
info := currentDirectory infoOf:aFileName.
|
|
2147 |
info isNil ifTrue:[
|
|
2148 |
"not accessable - usually a symlink,
|
49
|
2149 |
to a nonexisting/nonreadable file
|
45
|
2150 |
"
|
49
|
2151 |
entry colAt:2 put:'?'.
|
|
2152 |
entry colAt:3 put:'(bad symbolic link ?)'.
|
45
|
2153 |
] ifFalse:[
|
142
|
2154 |
typ := (info at:#type).
|
|
2155 |
(typ == #regular) ifFalse:[
|
|
2156 |
entry colAt:2 put:(typ at:1) asString.
|
45
|
2157 |
] ifTrue:[
|
49
|
2158 |
entry colAt:2 put:' '.
|
45
|
2159 |
].
|
36
|
2160 |
|
45
|
2161 |
modeString := self getModeString:(info at:#mode)
|
|
2162 |
with:#( '' $r $w $x
|
|
2163 |
' ' $r $w $x
|
|
2164 |
' ' $r $w $x ).
|
49
|
2165 |
entry colAt:3 put:modeString.
|
36
|
2166 |
|
45
|
2167 |
((info at:#uid) ~~ prevUid) ifTrue:[
|
|
2168 |
prevUid := (info at:#uid).
|
|
2169 |
nameString := OperatingSystem getUserNameFromID:prevUid.
|
|
2170 |
nameString := nameString , (String new:(10 - nameString size))
|
|
2171 |
].
|
49
|
2172 |
entry colAt:4 put:nameString withoutSpaces.
|
45
|
2173 |
((info at:#gid) ~~ prevGid) ifTrue:[
|
|
2174 |
prevGid := (info at:#gid).
|
|
2175 |
groupString := OperatingSystem getGroupNameFromID:prevGid.
|
|
2176 |
groupString := groupString , (String new:(10 - groupString size))
|
|
2177 |
].
|
49
|
2178 |
entry colAt:5 put:groupString withoutSpaces.
|
36
|
2179 |
|
142
|
2180 |
(typ == #regular) ifTrue:[
|
49
|
2181 |
entry colAt:6 put:(self sizePrintString:(info at:#size)).
|
45
|
2182 |
].
|
49
|
2183 |
|
142
|
2184 |
f := currentDirectory asFilename:aFileName.
|
|
2185 |
f isSymbolicLink ifTrue:[
|
|
2186 |
p := f linkInfo at:#path.
|
|
2187 |
typeString := 'symbolic link to ' , p
|
|
2188 |
] ifFalse:[
|
|
2189 |
(showVeryLongList not or:[typ == #directory]) ifTrue:[
|
|
2190 |
typeString := typ asString
|
|
2191 |
] ifFalse:[
|
|
2192 |
typeString := f fileType.
|
|
2193 |
].
|
52
|
2194 |
].
|
142
|
2195 |
entry colAt:7 put:typeString.
|
49
|
2196 |
text add:entry
|
45
|
2197 |
].
|
49
|
2198 |
fileListView at:lineIndex put:entry
|
45
|
2199 |
].
|
|
2200 |
] ifFalse:[
|
49
|
2201 |
files keysAndValuesDo:[:lineIndex :aName |
|
|
2202 |
|entry|
|
|
2203 |
|
45
|
2204 |
"
|
|
2205 |
if multiple FileBrowsers are reading, let others
|
|
2206 |
make some progress too
|
|
2207 |
"
|
49
|
2208 |
windowGroup notNil ifTrue:[windowGroup processExposeEvents].
|
45
|
2209 |
Processor yield.
|
49
|
2210 |
realized ifFalse:[^ self].
|
|
2211 |
|
142
|
2212 |
((currentDirectory isDirectory:aName) and:[
|
45
|
2213 |
(aName ~= '..') and:[aName ~= '.']]) ifTrue:[
|
49
|
2214 |
entry := aName , ' ...'
|
45
|
2215 |
] ifFalse:[
|
49
|
2216 |
entry := aName
|
|
2217 |
].
|
|
2218 |
fileListView at:lineIndex put:entry
|
45
|
2219 |
].
|
|
2220 |
].
|
|
2221 |
].
|
36
|
2222 |
|
45
|
2223 |
"
|
|
2224 |
install a new check after some time
|
|
2225 |
"
|
|
2226 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta
|
36
|
2227 |
]
|
142
|
2228 |
|
|
2229 |
"Modified: 21.9.1995 / 11:40:23 / claus"
|
36
|
2230 |
!
|
|
2231 |
|
172
|
2232 |
withoutHiddenFiles:aCollection
|
|
2233 |
"remove hidden files (i.e. those that start with '.') from
|
|
2234 |
the list in aCollection"
|
36
|
2235 |
|
172
|
2236 |
|newCollection|
|
52
|
2237 |
|
172
|
2238 |
newCollection := aCollection species new.
|
|
2239 |
aCollection do:[:fname |
|
|
2240 |
((fname startsWith:'.') and:[(fname = '..') not]) ifTrue:[
|
|
2241 |
showDotFiles ifTrue:[
|
|
2242 |
newCollection add:fname
|
45
|
2243 |
]
|
|
2244 |
] ifFalse:[
|
172
|
2245 |
newCollection add:fname
|
45
|
2246 |
]
|
36
|
2247 |
].
|
172
|
2248 |
^ newCollection
|
36
|
2249 |
!
|
|
2250 |
|
|
2251 |
writeFile:fileName text:someText
|
|
2252 |
|stream msg startNr nLines string|
|
|
2253 |
|
|
2254 |
self withCursor:(Cursor write) do:[
|
45
|
2255 |
stream := FileStream newFileNamed:fileName in:currentDirectory.
|
|
2256 |
stream isNil ifTrue:[
|
|
2257 |
msg := (resources string:'cannot write file ''%1'' !!' with:fileName).
|
|
2258 |
self showAlert:msg with:(FileStream lastErrorString)
|
|
2259 |
] ifFalse:[
|
|
2260 |
someText isString ifTrue:[
|
|
2261 |
stream nextPutAll:someText.
|
|
2262 |
] ifFalse:[
|
|
2263 |
"
|
|
2264 |
on some systems, writing linewise is very slow (via NFS)
|
|
2265 |
therefore we convert to a string and write it in chunks
|
|
2266 |
to avoid creating huge strings, we do it in blocks of 1000 lines
|
|
2267 |
"
|
|
2268 |
startNr := 1.
|
|
2269 |
nLines := someText size.
|
|
2270 |
[startNr <= nLines] whileTrue:[
|
65
|
2271 |
string := someText asStringWithCRsFrom:startNr
|
|
2272 |
to:((startNr + 1000) min:nLines)
|
|
2273 |
compressTabs:compressTabs.
|
45
|
2274 |
stream nextPutAll:string.
|
|
2275 |
startNr := startNr + 1000 + 1.
|
|
2276 |
].
|
36
|
2277 |
"/ someText do:[:line |
|
|
2278 |
"/ line notNil ifTrue:[
|
|
2279 |
"/ stream nextPutAll:line.
|
|
2280 |
"/ ].
|
|
2281 |
"/ stream cr.
|
|
2282 |
"/ ]
|
45
|
2283 |
].
|
|
2284 |
stream close.
|
|
2285 |
subView modified:false
|
|
2286 |
]
|
36
|
2287 |
]
|
|
2288 |
! !
|
|
2289 |
|
172
|
2290 |
!FileBrowser methodsFor:'queries'!
|
73
|
2291 |
|
172
|
2292 |
path
|
|
2293 |
"return my currentDirectories pathName;
|
|
2294 |
sent from the pathField label to aquire pathname when I changed directory"
|
49
|
2295 |
|
172
|
2296 |
^ currentDirectory pathName
|
49
|
2297 |
! !
|
|
2298 |
|