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