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