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