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