author | Claus Gittinger <cg@exept.de> |
Wed, 29 May 1996 13:23:56 +0200 | |
changeset 581 | d1a1ae9d49e4 |
parent 564 | 28b766ce6ec5 |
child 585 | be0241bf7268 |
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 |
]. |
|
551 | 263 |
Transcript showCR:'unloading old ' , p , ' ...'. |
487 | 264 |
ObjectFileLoader unloadObjectFile:p. |
265 |
]. |
|
266 |
||
551 | 267 |
Transcript showCR:'loading ' , p , ' ...'. |
487 | 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:[ |
|
525 | 282 |
JavaClassReader loadFile:(currentDirectory pathName , '/' , fileName) |
487 | 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 |
||
551 | 307 |
"Modified: 18.5.1996 / 15:45:31 / 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 |
|
556 | 675 |
self openTool:HTMLDocumentView |
676 |
||
677 |
"Modified: 20.5.1996 / 20:30:58 / cg" |
|
267 | 678 |
! |
679 |
||
680 |
openImageInspector |
|
681 |
|img| |
|
682 |
||
683 |
self selectedFilesDo:[:fileName | |
|
684 |
(currentDirectory isDirectory:fileName) ifFalse:[ |
|
685 |
img := Image fromFile:(currentDirectory pathName , '/' , fileName). |
|
686 |
img notNil ifTrue:[ |
|
687 |
img inspect |
|
688 |
] ifFalse:[ |
|
689 |
self warn:'unknown format: ' , fileName |
|
690 |
] |
|
691 |
] |
|
692 |
]. |
|
693 |
||
694 |
"Modified: 17.9.1995 / 17:41:24 / claus" |
|
695 |
! |
|
696 |
||
697 |
openTool:aToolClass |
|
698 |
"open a tool on the selected file(s)" |
|
699 |
||
700 |
self selectedFilesDo:[:fileName | |
|
701 |
(currentDirectory isDirectory:fileName) ifFalse:[ |
|
702 |
aToolClass openOn:(currentDirectory pathName , '/' , fileName). |
|
703 |
] |
|
704 |
]. |
|
172 | 705 |
! ! |
706 |
||
707 |
!FileBrowser methodsFor:'help '! |
|
708 |
||
709 |
helpTextFor:aComponent |
|
710 |
|s| |
|
711 |
||
712 |
aComponent == subView ifTrue:[ |
|
713 |
s := 'HELP_SUBVIEW' |
|
714 |
]. |
|
715 |
aComponent == fileListView ifTrue:[ |
|
716 |
s := 'HELP_FILELIST' |
|
717 |
]. |
|
718 |
aComponent == filterField ifTrue:[ |
|
719 |
s := 'HELP_FILTER' |
|
720 |
]. |
|
721 |
aComponent == labelView ifTrue:[ |
|
722 |
s := 'HELP_PATHFIELD' |
|
723 |
]. |
|
724 |
aComponent == commandView ifTrue:[ |
|
725 |
s := 'HELP_COMMANDVIEW' |
|
726 |
]. |
|
727 |
s notNil ifTrue:[ |
|
728 |
^ resources string:s |
|
729 |
]. |
|
730 |
^ nil |
|
731 |
! ! |
|
732 |
||
36 | 733 |
!FileBrowser methodsFor:'initialization'! |
734 |
||
172 | 735 |
currentDirectory:aDirectoryPath |
736 |
"set the directory to be browsed" |
|
737 |
||
738 |
currentDirectory := FileDirectory directoryNamed:aDirectoryPath. |
|
739 |
self changed:#path. |
|
740 |
" |
|
741 |
tell my subview (whatever that is) to start its file-dialog |
|
742 |
(i.e. save-as etc.) in that directory |
|
743 |
" |
|
744 |
(subView respondsTo:#directoryForFileDialog:) ifTrue:[ |
|
745 |
subView directoryForFileDialog:currentDirectory |
|
746 |
] |
|
747 |
! |
|
748 |
||
749 |
focusSequence |
|
750 |
"return the sequence in which ALT-CursorRight steps focus" |
|
751 |
||
752 |
|fs| |
|
753 |
||
754 |
fs := Array |
|
755 |
with:filterField |
|
756 |
with:fileListView |
|
757 |
with:subView. |
|
758 |
||
759 |
commandView notNil ifTrue:[ |
|
760 |
fs := fs copyWith:commandView |
|
761 |
]. |
|
762 |
^fs |
|
763 |
! |
|
764 |
||
765 |
initEvents |
|
766 |
super initEvents. |
|
767 |
self enableEvent:#visibilityChange. |
|
768 |
! |
|
769 |
||
36 | 770 |
initialize |
344
3f881dbee13a
use a model for the filter field
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
771 |
|frame spacing halfSpacing v topFrame labelFrame filterModel| |
36 | 772 |
|
773 |
super initialize. |
|
774 |
||
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
775 |
fileEncoding := nil. "/ native ST/X encoding |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
776 |
|
52 | 777 |
"if true, will replace leading spaces by tabs on |
778 |
file write. If false, they will be written as spaces |
|
779 |
" |
|
780 |
compressTabs := resources at:'COMPRESS_TABS' default:true. |
|
781 |
||
782 |
" |
|
783 |
showing long or short by default |
|
784 |
" |
|
785 |
showLongList := resources at:'LONG_LIST' default:false. |
|
786 |
||
787 |
" |
|
788 |
show type of contents (somwehat slow) or not ? |
|
789 |
" |
|
790 |
showVeryLongList := resources at:'VERYLONG_LIST' default:true. |
|
791 |
||
792 |
" |
|
793 |
show hidden files or not ? |
|
794 |
" |
|
795 |
showDotFiles := resources at:'SHOW_DOT_FILES' default:false. |
|
796 |
||
797 |
||
45 | 798 |
lockUpdate := false. |
799 |
||
132 | 800 |
CommandHistory isNil ifTrue:[ |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
801 |
CommandHistory := OrderedCollection new. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
802 |
CommandHistorySize := 50 |
132 | 803 |
]. |
36 | 804 |
DirectoryHistory isNil ifTrue:[ |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
805 |
DirectoryHistory := OrderedCollection new. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
806 |
DirectoryHistoryWhere := OrderedCollection new. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
807 |
HistorySize := 15. |
36 | 808 |
]. |
132 | 809 |
commandIndex := 0. |
36 | 810 |
|
811 |
myName := (resources string:self class name). |
|
812 |
self label:myName. |
|
45 | 813 |
|
93 | 814 |
labelFrame := View |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
815 |
origin:(0.0 @ 0.0) |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
816 |
corner:(1.0 @ (font height * 2)) |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
817 |
in:self. |
52 | 818 |
|
105 | 819 |
styleSheet name = #st80 ifTrue:[ |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
820 |
labelFrame level:1 |
45 | 821 |
]. |
36 | 822 |
|
823 |
spacing := ViewSpacing. |
|
824 |
halfSpacing := spacing // 2. |
|
825 |
||
826 |
checkBlock := [self checkIfDirectoryHasChanged]. |
|
45 | 827 |
checkDelta := resources at:'CHECK_DELTA' default:10. |
36 | 828 |
|
829 |
currentDirectory := FileDirectory directoryNamed:'.'. |
|
830 |
||
344
3f881dbee13a
use a model for the filter field
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
831 |
filterModel := '*' asValue. |
45 | 832 |
filterField := EditField in:labelFrame. |
36 | 833 |
filterField origin:[((width // 4 * 3) + halfSpacing) @ halfSpacing] |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
834 |
corner:(1.0 @ filterField heightIncludingBorder). |
45 | 835 |
filterField rightInset:ViewSpacing-halfSpacing. |
344
3f881dbee13a
use a model for the filter field
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
836 |
filterField model:filterModel. |
45 | 837 |
|
36 | 838 |
self initializeFilterPattern. |
344
3f881dbee13a
use a model for the filter field
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
839 |
filterModel onChangeSend:#filterPatternChanged to:self. |
3f881dbee13a
use a model for the filter field
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
840 |
"/ filterField leaveAction:[:key | fileListView scrollToTop. self updateCurrentDirectory]. |
36 | 841 |
|
45 | 842 |
labelView := Label in:labelFrame. |
36 | 843 |
labelView origin:(halfSpacing @ halfSpacing) |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
844 |
extent:[((width // 4 * 3) - spacing - borderWidth) |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
845 |
@ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
846 |
(filterField heightIncludingBorder) |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
847 |
"(font height + font descent)" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
848 |
]. |
36 | 849 |
labelView adjust:#right. |
850 |
labelView borderWidth:0. |
|
93 | 851 |
labelView model:self; menu:#labelMenu; aspect:#path; labelMessage:#path. |
73 | 852 |
labelFrame model:self; menu:#labelMenu. |
36 | 853 |
|
854 |
killButton := Button label:(resources string:'kill') in:self. |
|
855 |
killButton origin:(halfSpacing @ halfSpacing) |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
856 |
extent:(killButton width @ filterField height). |
331 | 857 |
killButton beInvisible. |
36 | 858 |
|
132 | 859 |
self initializeCommandViewIn:self. |
860 |
||
861 |
"/ frame := VariableVerticalPanel |
|
862 |
"/ origin:[frame borderWidth negated |
|
863 |
"/ @ |
|
864 |
"/ labelFrame height |
|
865 |
"/ "/ (labelView height + labelView origin y + spacing) |
|
866 |
"/ ] |
|
867 |
"/ corner:(1.0 @ 1.0) |
|
868 |
"/ in:self. |
|
869 |
||
870 |
frame := VariableVerticalPanel origin:0.0@0.0 corner:1.0@1.0 in:self. |
|
871 |
frame topInset:labelFrame height. |
|
872 |
commandView notNil ifTrue:[ |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
873 |
frame bottomInset:(commandView height + spacing + spacing) |
132 | 874 |
]. |
36 | 875 |
|
876 |
topFrame := ScrollableView for:SelectionInListView in:frame. |
|
877 |
topFrame origin:(0.0 @ 0.0) corner:(1.0 @ 0.3). |
|
878 |
||
879 |
fileListView := topFrame scrolledView. |
|
880 |
fileListView action:[:lineNr | self fileSelect:lineNr]. |
|
881 |
fileListView doubleClickAction:[:lineNr | self fileSelect:lineNr. |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
882 |
self fileGet]. |
36 | 883 |
fileListView multipleSelectOk:true. |
98 | 884 |
fileListView menuHolder:self; menuPerformer:self; menuMessage:#fileListMenu. |
36 | 885 |
|
886 |
v := self initializeSubViewIn:frame. |
|
132 | 887 |
|
36 | 888 |
v origin:(0.0 @ 0.3) corner:(1.0 @ 1.0). |
889 |
subView := v scrolledView. |
|
890 |
(subView respondsTo:#directoryForFileDialog:) ifTrue:[ |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
891 |
subView directoryForFileDialog:currentDirectory |
36 | 892 |
]. |
893 |
||
894 |
ObjectMemory addDependent:self. |
|
132 | 895 |
|
896 |
"Modified: 6.9.1995 / 20:26:06 / claus" |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
897 |
"Modified: 22.2.1996 / 14:46:14 / cg" |
36 | 898 |
! |
899 |
||
132 | 900 |
initializeCommandViewIn:frame |
901 |
"set up the command view - can be redefined in subclasses as empty, |
|
902 |
if no commandView is wanted" |
|
903 |
||
904 |
||
905 |
commandView := EditField origin:0.0@1.0 corner:1.0@1.0 in:frame. |
|
381 | 906 |
commandView allInset:ViewSpacing. |
132 | 907 |
commandView topInset:(commandView preferredExtent y negated - ViewSpacing). |
908 |
||
133 | 909 |
"/ commandView contents:'** no commands which require input here **'. |
132 | 910 |
|
142 | 911 |
commandView entryCompletionBlock:[:contents | |
381 | 912 |
|newString| |
142 | 913 |
|
381 | 914 |
newString := Filename |
915 |
filenameCompletionFor:contents |
|
916 |
directory:currentDirectory pathName asFilename |
|
917 |
directoriesOnly:false |
|
918 |
filesOnly:false |
|
919 |
ifMultiple:[:dir | commandView flash.]. |
|
920 |
commandView contents:newString. |
|
921 |
commandView cursorToEndOfLine. |
|
132 | 922 |
]. |
923 |
commandView leaveAction:[:key | |
|
381 | 924 |
|cmd nCmd empty| |
132 | 925 |
|
381 | 926 |
(key == #CursorDown |
927 |
or:[key == #CursorUp]) ifTrue:[ |
|
928 |
nCmd := CommandHistory size. |
|
929 |
nCmd == 0 ifTrue:[ |
|
930 |
empty := true |
|
931 |
] ifFalse:[ |
|
932 |
key == #CursorUp ifTrue:[ |
|
933 |
commandIndex == nCmd ifTrue:[ |
|
934 |
commandView flash. |
|
935 |
]. |
|
936 |
commandIndex := (commandIndex + 1) min:nCmd |
|
937 |
] ifFalse:[ |
|
938 |
commandIndex == 1 ifTrue:[ |
|
939 |
commandView flash. |
|
940 |
empty := true. |
|
941 |
]. |
|
942 |
commandIndex := (commandIndex - 1) max:1. |
|
943 |
]. |
|
944 |
]. |
|
945 |
empty == true ifTrue:[ |
|
946 |
commandView contents:nil |
|
947 |
] ifFalse:[ |
|
948 |
commandView contents:(CommandHistory at:commandIndex). |
|
949 |
] |
|
950 |
]. |
|
951 |
key == #Return ifTrue:[ |
|
952 |
cmd := commandView contents. |
|
132 | 953 |
|
539
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
954 |
subView insertLine:( |
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
955 |
Text string:('>> ' , cmd) |
540 | 956 |
emphasis:(Array with:#bold with:#underline with:(#color->Color blue)) |
539
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
957 |
"/ ColoredListEntry string:('>> ' , cmd) color:Color blue |
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
958 |
) |
381 | 959 |
before:(subView cursorLine). |
539
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
960 |
subView cursorDown:1. |
133 | 961 |
|
962 |
"/ subView insertStringAtCursor:cmd. |
|
963 |
"/ subView insertCharAtCursor:(Character cr). |
|
132 | 964 |
|
381 | 965 |
(cmd notNil and:[cmd notEmpty]) ifTrue:[ |
966 |
CommandHistory notNil ifTrue:[ |
|
967 |
CommandHistory addFirst:cmd. |
|
968 |
CommandHistory size > CommandHistorySize ifTrue:[ |
|
969 |
CommandHistory removeLast |
|
970 |
] |
|
971 |
]. |
|
972 |
self doExecuteCommand:cmd replace:false. |
|
973 |
commandView contents:nil. |
|
974 |
commandIndex := 0 |
|
975 |
] |
|
976 |
] |
|
132 | 977 |
]. |
978 |
||
133 | 979 |
"Modified: 7.9.1995 / 15:48:45 / claus" |
540 | 980 |
"Modified: 12.5.1996 / 17:09:45 / cg" |
132 | 981 |
! |
982 |
||
172 | 983 |
initializeFilterPattern |
984 |
"set an initial matchpattern - can be redefined in subclasses" |
|
985 |
||
344
3f881dbee13a
use a model for the filter field
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
986 |
filterField model value:'*' |
172 | 987 |
! |
988 |
||
989 |
initializeSubViewIn:frame |
|
990 |
"set up the contents view - can be redefined in subclasses for |
|
991 |
different view types (SoundFileBrowser/ImageBrowsers etc.)" |
|
992 |
||
993 |
^ HVScrollableView for:CodeView miniScrollerH:true miniScrollerV:false in:frame. |
|
994 |
! ! |
|
995 |
||
996 |
!FileBrowser methodsFor:'misc user interaction'! |
|
997 |
||
998 |
destroy |
|
999 |
"destroy view and boxes" |
|
1000 |
||
1001 |
ObjectMemory removeDependent:self. |
|
1002 |
Processor removeTimedBlock:checkBlock. |
|
1003 |
checkBlock := nil. |
|
1004 |
super destroy |
|
1005 |
! |
|
1006 |
||
346 | 1007 |
filterPatternChanged |
1008 |
fileListView scrollToTop. |
|
1009 |
self updateCurrentDirectory |
|
1010 |
! |
|
1011 |
||
172 | 1012 |
terminate |
1013 |
"exit FileBrowser" |
|
1014 |
||
1015 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when FileBrowser is closed.' |
|
1016 |
yesButton:'close') ifTrue:[self destroy] |
|
1017 |
! |
|
1018 |
||
1019 |
update:what with:someArgument from:changedObject |
|
1020 |
realized ifFalse:[^ self]. |
|
36 | 1021 |
|
172 | 1022 |
(what == #aboutToExit) ifTrue:[ |
380 | 1023 |
"system wants to shut down this |
1024 |
- if text was modified, pop up, and ask user and save if requested." |
|
172 | 1025 |
|
380 | 1026 |
(subView modified and:[subView contentsWasSaved not]) ifTrue:[ |
1027 |
self raiseDeiconified. |
|
172 | 1028 |
|
380 | 1029 |
(self |
1030 |
ask:(resources at:'FileBrowser:\\contents has not been saved.\\Save before exiting ?') |
|
1031 |
yesButton:'save' |
|
1032 |
noButton:'don''t save') |
|
1033 |
ifTrue:[ |
|
1034 |
subView acceptAction notNil ifTrue:[ |
|
1035 |
subView accept |
|
1036 |
] ifFalse:[ |
|
1037 |
subView save |
|
1038 |
] |
|
1039 |
] |
|
1040 |
]. |
|
1041 |
^ self |
|
172 | 1042 |
]. |
1043 |
changedObject == tabSpec ifTrue:[ |
|
380 | 1044 |
fileListView redraw |
172 | 1045 |
]. |
380 | 1046 |
|
1047 |
"Modified: 21.2.1996 / 01:17:53 / cg" |
|
172 | 1048 |
! ! |
1049 |
||
1050 |
!FileBrowser methodsFor:'pathField user interaction'! |
|
1051 |
||
1052 |
changeCurrentDirectory |
|
1053 |
"if text was modified show a queryBox, |
|
1054 |
otherwise change immediately to directory" |
|
1055 |
||
1056 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.' |
|
1057 |
yesButton:'change') ifTrue:[ |
|
1058 |
self queryForDirectoryToChange |
|
36 | 1059 |
] |
1060 |
! |
|
1061 |
||
172 | 1062 |
changeDirectoryTo:aDirectoryName |
1063 |
"sent from label menu to change back to a previous directory" |
|
132 | 1064 |
|
172 | 1065 |
self doChangeCurrentDirectoryTo:aDirectoryName updateHistory:false |
1066 |
! |
|
1067 |
||
1068 |
changeToHomeDirectory |
|
1069 |
"if text was modified show a queryBox, |
|
1070 |
otherwise change immediately to directory" |
|
132 | 1071 |
|
172 | 1072 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.' |
1073 |
yesButton:'change') ifTrue:[ |
|
1074 |
self doChangeToHomeDirectory |
|
1075 |
] |
|
1076 |
! |
|
45 | 1077 |
|
172 | 1078 |
changeToParentDirectory |
1079 |
"if text was modified show a queryBox, |
|
1080 |
otherwise change immediately to directory" |
|
45 | 1081 |
|
172 | 1082 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.' |
1083 |
yesButton:'change') ifTrue:[ |
|
1084 |
self doChangeToParentDirectory |
|
36 | 1085 |
] |
98 | 1086 |
! |
1087 |
||
172 | 1088 |
copyPath |
1089 |
"copy current path into cut & paste buffer" |
|
1090 |
||
1091 |
Smalltalk at:#CopyBuffer put:currentDirectory pathName |
|
1092 |
! |
|
1093 |
||
1094 |
labelMenu |
|
1095 |
|labels selectors args menu| |
|
1096 |
||
1097 |
labels := #( |
|
1098 |
'copy path' |
|
1099 |
'-' |
|
1100 |
'up' |
|
1101 |
'back' |
|
1102 |
'change to home-directory' |
|
1103 |
'change directory ...' |
|
1104 |
). |
|
98 | 1105 |
|
172 | 1106 |
selectors := #( |
1107 |
copyPath |
|
1108 |
nil |
|
1109 |
changeToParentDirectory |
|
1110 |
changeToPreviousDirectory |
|
1111 |
changeToHomeDirectory |
|
1112 |
changeCurrentDirectory |
|
1113 |
). |
|
123 | 1114 |
|
172 | 1115 |
args := Array new:(labels size). |
126 | 1116 |
|
172 | 1117 |
DirectoryHistory size > 0 ifTrue:[ |
1118 |
labels := labels copyWith:'-'. |
|
1119 |
selectors := selectors copyWith:nil. |
|
1120 |
args := args copyWith:nil. |
|
1121 |
||
1122 |
DirectoryHistory do:[:dirName | |
|
1123 |
labels := labels copyWith:dirName. |
|
1124 |
selectors := selectors copyWith:#changeDirectoryTo:. |
|
1125 |
args := args copyWith:dirName |
|
1126 |
] |
|
123 | 1127 |
]. |
172 | 1128 |
|
1129 |
menu := PopUpMenu |
|
1130 |
labels:(resources array:labels) |
|
1131 |
selectors:selectors |
|
1132 |
args:args |
|
1133 |
receiver:self. |
|
1134 |
||
1135 |
previousDirectory isNil ifTrue:[ |
|
1136 |
menu disable:#changeToPreviousDirectory. |
|
132 | 1137 |
]. |
172 | 1138 |
^menu. |
1139 |
! |
|
1140 |
||
1141 |
queryForDirectoryToChange |
|
1142 |
"query for new directory" |
|
123 | 1143 |
|
172 | 1144 |
|queryBox| |
98 | 1145 |
|
172 | 1146 |
queryBox := FilenameEnterBox |
1147 |
title:(resources at:'change directory to:') withCRs |
|
1148 |
okText:(resources at:'change') |
|
1149 |
action:[:newName | self doChangeCurrentDirectoryTo:newName updateHistory:true]. |
|
1150 |
"/ queryBox initialText:''. |
|
1151 |
queryBox showAtPointer |
|
36 | 1152 |
! ! |
1153 |
||
1154 |
!FileBrowser methodsFor:'private'! |
|
1155 |
||
172 | 1156 |
ask:question yesButton:yesButtonText |
1157 |
"common method to ask a yes/no question; return true or false" |
|
36 | 1158 |
|
172 | 1159 |
^ self ask:question yesButton:yesButtonText noButton:'cancel' |
1160 |
! |
|
93 | 1161 |
|
172 | 1162 |
ask:question yesButton:yesButtonText noButton:noButtonText |
36 | 1163 |
"common method to ask a yes/no question" |
1164 |
||
380 | 1165 |
^ Dialog |
1166 |
confirm:question withCRs |
|
1167 |
yesLabel:(resources at:yesButtonText) |
|
1168 |
noLabel:(resources at:noButtonText) |
|
37 | 1169 |
|
380 | 1170 |
"Modified: 21.2.1996 / 01:19:21 / cg" |
36 | 1171 |
! |
1172 |
||
172 | 1173 |
askForCommandThenDo:aBlock |
1174 |
"setup and launch a querybox to ask for unix command. |
|
1175 |
Then evaluate aBlock passing the command-string as argument." |
|
93 | 1176 |
|
172 | 1177 |
|fileName sel box| |
93 | 1178 |
|
172 | 1179 |
box := FilenameEnterBox |
1180 |
title:(resources at:'execute unix command:') |
|
1181 |
okText:(resources at:'execute') |
|
1182 |
action:aBlock. |
|
79 | 1183 |
|
172 | 1184 |
sel := fileListView selection. |
1185 |
sel size == 1 ifTrue:[ |
|
1186 |
fileName := fileList at:sel first |
|
1187 |
]. |
|
1188 |
fileName notNil ifTrue:[ |
|
1189 |
self initialCommandFor:fileName into:box. |
|
1190 |
]. |
|
1191 |
box directory:currentDirectory pathName asFilename. |
|
1192 |
box showAtPointer |
|
36 | 1193 |
|
172 | 1194 |
"Modified: 7.9.1995 / 10:31:54 / claus" |
36 | 1195 |
! |
1196 |
||
98 | 1197 |
askIfModified:question yesButton:yesButtonText |
1198 |
"tell user, that code has been modified - let her confirm" |
|
1199 |
||
1200 |
(subView modified not or:[subView contentsWasSaved]) ifTrue:[ |
|
1201 |
^ true |
|
1202 |
]. |
|
1203 |
^ self |
|
1204 |
ask:(resources string:question) |
|
1205 |
yesButton:yesButtonText |
|
1206 |
! |
|
1207 |
||
172 | 1208 |
binaryFileAction:aFilename |
1209 |
"for some binary files, if double clicked, we can do some useful |
|
1210 |
action ..." |
|
1211 |
||
1212 |
|isImage img| |
|
36 | 1213 |
|
172 | 1214 |
(currentDirectory pathName , '/' , aFilename) asFilename isExecutable ifTrue:[ |
1215 |
(OperatingSystem executeCommand:'cd ',currentDirectory pathName, '; ',aFilename) |
|
1216 |
ifTrue:[^true]. |
|
1217 |
]. |
|
1218 |
isImage := false. |
|
1219 |
(aFilename endsWith:'.gif') ifTrue:[isImage := true]. |
|
1220 |
(aFilename endsWith:'.tiff') ifTrue:[isImage := true]. |
|
1221 |
(aFilename endsWith:'.pnm') ifTrue:[isImage := true]. |
|
1222 |
(aFilename endsWith:'.xbm') ifTrue:[isImage := true]. |
|
1223 |
isImage ifTrue:[ |
|
1224 |
img := Image fromFile:(currentDirectory pathName , '/' , aFilename). |
|
1225 |
img notNil ifTrue:[ |
|
1226 |
img inspect. |
|
1227 |
^ true |
|
120 | 1228 |
] |
36 | 1229 |
]. |
172 | 1230 |
^ false |
1231 |
||
1232 |
"Created: 14.9.1995 / 10:23:10 / claus" |
|
36 | 1233 |
! |
1234 |
||
172 | 1235 |
changeToPreviousDirectory |
1236 |
"if text was modified show a queryBox, |
|
1237 |
otherwise change immediately to previous directory." |
|
93 | 1238 |
|
172 | 1239 |
previousDirectory isNil ifTrue:[^ self]. |
1240 |
(self askIfModified:'contents has not been saved.\\Modifications will be lost when directory is changed.' |
|
1241 |
yesButton:'change') ifTrue:[ |
|
1242 |
self doChangeCurrentDirectoryTo:previousDirectory updateHistory:false |
|
1243 |
] |
|
36 | 1244 |
! |
1245 |
||
98 | 1246 |
checkIfDirectoryHasChanged |
1247 |
"every checkDelta secs, check if directoy has changed and update the list if so. |
|
1248 |
Also, we check if the file shown has been touched in the meanwhile (for example, |
|
1249 |
from another browser) and say 'outdated' in the label if so. |
|
1250 |
This avoids confusion if the same file is being edited by two browsers. (or other editors). |
|
1251 |
If the text shown in the codeView has been edited, 'modified' is shown. |
|
1252 |
" |
|
1253 |
||
1254 |
|oldSelection nOld here newState msg newLabel| |
|
1255 |
||
1256 |
shown ifTrue:[ |
|
1257 |
currentDirectory notNil ifTrue:[ |
|
1258 |
lockUpdate ifTrue:[ |
|
1259 |
Processor removeTimedBlock:checkBlock. |
|
1260 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta. |
|
1261 |
^ self |
|
1262 |
]. |
|
1263 |
||
1264 |
subView modified ifTrue:[ |
|
1265 |
newState := ' (modified)' |
|
1266 |
]. |
|
1267 |
||
1268 |
here := currentDirectory pathName. |
|
1269 |
(OperatingSystem isReadable:here) ifTrue:[ |
|
1270 |
Processor removeTimedBlock:checkBlock. |
|
1271 |
||
1272 |
(currentDirectory timeOfLastChange > timeOfLastCheck) ifTrue:[ |
|
1273 |
nOld := fileListView numberOfSelections. |
|
1274 |
oldSelection := fileListView selectionValue. |
|
1275 |
self updateCurrentDirectory. |
|
1276 |
nOld ~~ 0 ifTrue:[ |
|
1277 |
nOld > 1 ifTrue:[ |
|
1278 |
oldSelection do:[:element | |
|
1279 |
fileListView addElementToSelection:element |
|
1280 |
] |
|
1281 |
] ifFalse:[ |
|
1282 |
fileListView selectElementWithoutScroll:oldSelection |
|
1283 |
] |
|
1284 |
]. |
|
1285 |
] ifFalse:[ |
|
1286 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta |
|
1287 |
]. |
|
1288 |
||
1289 |
currentFileName notNil ifTrue:[ |
|
1290 |
(currentDirectory exists:currentFileName) ifFalse:[ |
|
1291 |
newState := ' (removed)'. |
|
1292 |
] ifTrue:[ |
|
1293 |
(currentDirectory timeOfLastChange:currentFileName) > timeOfFileRead ifTrue:[ |
|
1294 |
newState := ' (outdated)'. |
|
1295 |
subView modified ifTrue:[ |
|
1296 |
newState := ' (modified & outdated)' |
|
1297 |
] |
|
1298 |
]. |
|
1299 |
]. |
|
1300 |
]. |
|
1301 |
||
1302 |
] ifFalse:[ |
|
1303 |
" |
|
1304 |
if the directory has been deleted, or is not readable ... |
|
1305 |
" |
|
1306 |
(OperatingSystem isValidPath:here) ifFalse:[ |
|
1307 |
msg := 'FileBrowser:\\directory %1 is gone ?!!?' |
|
1308 |
] ifTrue:[ |
|
1309 |
msg := 'FileBrowser:\\directory %1 is no longer readable ?!!?' |
|
1310 |
]. |
|
1311 |
self warn:(resources string:msg with:here) withCRs. |
|
1312 |
||
1313 |
fileListView contents:nil. |
|
1314 |
newLabel := myName , ': directory is gone !!'. |
|
1315 |
"/ Processor addTimedBlock:checkBlock afterSeconds:checkDelta |
|
1316 |
]. |
|
1317 |
||
1318 |
newState notNil ifTrue:[ |
|
1319 |
newLabel := myName. |
|
1320 |
currentFileName notNil ifTrue:[ |
|
1321 |
newLabel := newLabel , ': ' , currentFileName |
|
1322 |
]. |
|
1323 |
newLabel := newLabel , newState. |
|
1324 |
]. |
|
1325 |
newLabel notNil ifTrue:[ |
|
1326 |
self label:newLabel. |
|
1327 |
] |
|
1328 |
] |
|
1329 |
] |
|
1330 |
! |
|
1331 |
||
172 | 1332 |
defineTabulatorsForLongList |
1333 |
"define the tabs for the long list" |
|
1334 |
||
1335 |
tabSpec := TabulatorSpecification new. |
|
1336 |
tabSpec unit:#inch. |
|
1337 |
"/ tabSpec positions:#(0 2 2.3 4.3 5.3 6.0 6.5). |
|
1338 |
tabSpec widths: #(2 0.3 1.7 1 0.5 0.5 1"any"). |
|
1339 |
" name type mode owner group size type" |
|
1340 |
tabSpec align: #(#left #left #left #right #right #decimal #left). |
|
1341 |
tabSpec addDependent:self |
|
1342 |
! |
|
1343 |
||
1344 |
doChangeCurrentDirectoryTo:fileName updateHistory:updateHistory |
|
1345 |
"verify argument is name of a readable & executable directory |
|
1346 |
and if so, go there" |
|
1347 |
||
1348 |
|msg path idx| |
|
1349 |
||
1350 |
self label:myName; iconLabel:myName. |
|
1351 |
fileName notNil ifTrue:[ |
|
1352 |
(currentDirectory isDirectory:fileName) ifTrue:[ |
|
1353 |
(currentDirectory isReadable:fileName) ifTrue:[ |
|
1354 |
(currentDirectory isExecutable:fileName) ifTrue:[ |
|
1355 |
||
1356 |
path := currentDirectory pathName. |
|
1357 |
previousDirectory := path. |
|
1358 |
||
1359 |
" |
|
1360 |
remember where we are in the fileList |
|
1361 |
(in case we want to return) |
|
1362 |
" |
|
1363 |
idx := DirectoryHistory indexOf:path. |
|
1364 |
idx ~~ 0 ifTrue:[ |
|
1365 |
DirectoryHistoryWhere at:idx put:fileListView firstLineShown |
|
1366 |
]. |
|
1367 |
||
1368 |
self setCurrentDirectory:fileName. |
|
1369 |
||
1370 |
path := currentDirectory pathName. |
|
1371 |
||
1372 |
" |
|
1373 |
if we have already been there, look for the |
|
1374 |
position offset, and scroll the fileList |
|
1375 |
" |
|
1376 |
idx := DirectoryHistory indexOf:path. |
|
1377 |
idx ~~ 0 ifTrue:[ |
|
1378 |
|pos| |
|
1379 |
||
1380 |
pos := DirectoryHistoryWhere at:idx. |
|
1381 |
pos notNil ifTrue:[ |
|
1382 |
fileListView scrollToLine:pos |
|
1383 |
] |
|
1384 |
]. |
|
1385 |
||
1386 |
updateHistory ifTrue:[ |
|
1387 |
|pos| |
|
1388 |
||
1389 |
(DirectoryHistory includes:path) ifFalse:[ |
|
1390 |
DirectoryHistory size >= HistorySize ifTrue:[ |
|
1391 |
DirectoryHistory removeLast. |
|
1392 |
DirectoryHistoryWhere removeLast |
|
1393 |
] |
|
1394 |
] ifTrue:[ |
|
1395 |
"already been there before; move the entry to |
|
1396 |
the beginning, so it will fall out later." |
|
1397 |
||
1398 |
idx := DirectoryHistory indexOf:path. |
|
1399 |
DirectoryHistory removeIndex:idx. |
|
1400 |
pos := DirectoryHistoryWhere at:idx. |
|
1401 |
DirectoryHistoryWhere removeIndex:idx. |
|
1402 |
]. |
|
1403 |
DirectoryHistory addFirst:path. |
|
1404 |
DirectoryHistoryWhere addFirst:pos. |
|
1405 |
]. |
|
1406 |
||
1407 |
^ self |
|
1408 |
]. |
|
1409 |
msg := 'cannot change directory to ''%1'' !!' |
|
1410 |
] ifFalse:[ |
|
1411 |
msg := 'cannot read directory ''%1'' !!' |
|
1412 |
] |
|
1413 |
] ifFalse:[ |
|
1414 |
msg := '''%1'' is not a directory !!' |
|
1415 |
]. |
|
1416 |
self showAlert:(resources string:msg with:fileName) with:nil |
|
1417 |
] |
|
1418 |
! |
|
1419 |
||
1420 |
doChangeToHomeDirectory |
|
1421 |
"go to home directory" |
|
1422 |
||
1423 |
self doChangeCurrentDirectoryTo:(OperatingSystem getHomeDirectory) updateHistory:true |
|
1424 |
! |
|
1425 |
||
1426 |
doChangeToParentDirectory |
|
1427 |
"go to home directory" |
|
36 | 1428 |
|
172 | 1429 |
self doChangeCurrentDirectoryTo:'..' updateHistory:true |
1430 |
! |
|
1431 |
||
1432 |
doCreateDirectory:newName |
|
1433 |
(currentDirectory includes:newName) ifTrue:[ |
|
1434 |
self warn:'%1 already exists.' with:newName. |
|
1435 |
^ self |
|
1436 |
]. |
|
1437 |
||
1438 |
(currentDirectory createDirectory:newName) ifTrue:[ |
|
1439 |
self updateCurrentDirectory |
|
1440 |
] ifFalse:[ |
|
1441 |
self showAlert:(resources string:'cannot create directory ''%1'' !!' with:newName) |
|
1442 |
with:(OperatingSystem lastErrorString) |
|
1443 |
] |
|
1444 |
! |
|
1445 |
||
1446 |
doCreateFile:newName |
|
1447 |
|aStream| |
|
1448 |
||
1449 |
(currentDirectory includes:newName) ifTrue:[ |
|
380 | 1450 |
(self |
1451 |
ask:(resources string:'%1 already exists\\truncate ?' with:newName) |
|
1452 |
yesButton:'truncate' |
|
1453 |
) ifFalse:[^ self]. |
|
172 | 1454 |
]. |
1455 |
||
1456 |
aStream := FileStream newFileNamed:newName in:currentDirectory. |
|
1457 |
aStream notNil ifTrue:[ |
|
380 | 1458 |
aStream close. |
1459 |
self updateCurrentDirectory |
|
172 | 1460 |
] ifFalse:[ |
380 | 1461 |
self showAlert:(resources string:'cannot create file ''%1'' !!' with:newName) |
1462 |
with:(FileStream lastErrorString) |
|
172 | 1463 |
] |
380 | 1464 |
|
1465 |
"Modified: 21.2.1996 / 01:24:16 / cg" |
|
172 | 1466 |
! |
1467 |
||
1468 |
doExecuteCommand:command replace:replace |
|
1469 |
"execute a unix command inserting the output of the command. |
|
1470 |
If replace is true, all text is replaced by the commands output; |
|
1471 |
otherwise, its inserted as selected text at the cursor position." |
|
1472 |
||
1473 |
|stream line lnr myProcess myPriority startLine startCol stopSignal |
|
1474 |
access| |
|
1475 |
||
1476 |
access := Semaphore forMutualExclusion. |
|
1477 |
stopSignal := Signal new. |
|
1478 |
||
1479 |
" |
|
1480 |
must take killButton out of my group |
|
1481 |
" |
|
1482 |
windowGroup removeView:killButton. |
|
1483 |
" |
|
1484 |
bring it to front, and turn hidden-mode off |
|
1485 |
" |
|
1486 |
killButton raise. |
|
331 | 1487 |
killButton beVisible. |
172 | 1488 |
" |
1489 |
it will make me raise stopSignal when pressed |
|
1490 |
" |
|
1491 |
killButton |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1492 |
action:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1493 |
stream notNil ifTrue:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1494 |
access critical:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1495 |
myProcess interruptWith:[stopSignal raise]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1496 |
] |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1497 |
] |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1498 |
]. |
172 | 1499 |
" |
1500 |
start it up under its own windowgroup |
|
1501 |
" |
|
1502 |
killButton openAutonomous. |
|
1503 |
||
1504 |
" |
|
1505 |
go fork a pipe and read it |
|
1506 |
" |
|
1507 |
self label:(myName , ': executing ' , (command copyTo:(20 min:command size)) , ' ...'). |
|
1508 |
[ |
|
1509 |
self withWaitCursorDo:[ |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1510 |
stopSignal catch:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1511 |
startLine := subView cursorLine. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1512 |
startCol := subView cursorCol. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1513 |
|
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1514 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1515 |
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
|
1516 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1517 |
myProcess := Processor activeProcess. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1518 |
myPriority := myProcess priority. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1519 |
myProcess priority:(Processor userBackgroundPriority). |
172 | 1520 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1521 |
stream := PipeStream readingFrom:('cd ' |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1522 |
, currentDirectory pathName |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1523 |
, '; ' |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1524 |
, command |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1525 |
, ' 2>&1' ). |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1526 |
stream notNil ifTrue:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1527 |
[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1528 |
|codeView lines| |
36 | 1529 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1530 |
codeView := subView. |
172 | 1531 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1532 |
replace ifTrue:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1533 |
codeView list:nil. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1534 |
lnr := 1. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1535 |
]. |
172 | 1536 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1537 |
[stream atEnd] whileFalse:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1538 |
(stream readWaitWithTimeoutMs:50) ifFalse:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1539 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1540 |
data available |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1541 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1542 |
lines := OrderedCollection new:50. |
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]. |
172 | 1545 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1546 |
[stream atEnd not |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1547 |
and:[stream canReadWithoutBlocking |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1548 |
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
|
1549 |
line := stream nextLine. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1550 |
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
|
1551 |
]. |
172 | 1552 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1553 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1554 |
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
|
1555 |
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
|
1556 |
an expose event ... |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1557 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1558 |
access critical:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1559 |
lines size > 0 ifTrue:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1560 |
replace ifTrue:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1561 |
lines do:[:line | |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1562 |
codeView at:lnr put:line withTabsExpanded. |
539
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
1563 |
codeView cursorToBottom; cursorDown:1. |
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1564 |
lnr := lnr + 1. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1565 |
]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1566 |
] ifFalse:[ |
172 | 1567 |
codeView insertLines:lines before:codeView cursorLine. |
1568 |
codeView cursorDown:lines size. |
|
539
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
1569 |
|
172 | 1570 |
"/ lines do:[:line | |
1571 |
"/ codeView insertLine:line withTabsExpanded before:codeView cursorLine. |
|
539
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
1572 |
"/ codeView cursorDown:1. |
172 | 1573 |
"/ ] |
1574 |
"/ codeView insertStringAtCursor:line. |
|
1575 |
"/ 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
|
1576 |
] |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1577 |
]. |
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 |
]. |
172 | 1580 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1581 |
shown ifTrue:[windowGroup processExposeEvents]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1582 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1583 |
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
|
1584 |
(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
|
1585 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1586 |
Processor yield |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1587 |
]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1588 |
] valueNowOrOnUnwindDo:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1589 |
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
|
1590 |
]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1591 |
self updateCurrentDirectory |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1592 |
]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1593 |
replace ifTrue:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1594 |
subView modified:false. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1595 |
]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1596 |
] |
172 | 1597 |
] |
1598 |
] valueNowOrOnUnwindDo:[ |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1599 |
|wg| |
172 | 1600 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1601 |
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
|
1602 |
myProcess notNil ifTrue:[myProcess priority:myPriority]. |
172 | 1603 |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1604 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1605 |
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
|
1606 |
(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
|
1607 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1608 |
wg := killButton windowGroup. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1609 |
killButton windowGroup:nil. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1610 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1611 |
shut down the windowgroup |
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 |
wg notNil ifTrue:[ |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1614 |
wg process terminate. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1615 |
]. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1616 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1617 |
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
|
1618 |
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
|
1619 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1620 |
killButton beInvisible. |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1621 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1622 |
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
|
1623 |
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
|
1624 |
" |
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1625 |
killButton action:nil. |
36 | 1626 |
]. |
172 | 1627 |
|
1628 |
currentFileName isNil ifTrue:[ |
|
355
55f1bac567eb
command execution kill fixed (for pipes where nothing ever arrives)
Claus Gittinger <cg@exept.de>
parents:
346
diff
changeset
|
1629 |
subView modified:false. |
172 | 1630 |
]. |
1631 |
||
1632 |
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
|
1633 |
self warn:'text quite large now - please cut off some lines' |
172 | 1634 |
] |
1635 |
||
1636 |
"Modified: 21.9.1995 / 11:18:46 / claus" |
|
539
33b603dd30ba
replaced ColoredListEntry by Text
Claus Gittinger <cg@exept.de>
parents:
525
diff
changeset
|
1637 |
"Modified: 12.5.1996 / 16:56:06 / cg" |
172 | 1638 |
! |
1639 |
||
1640 |
doFileGet |
|
1641 |
"get selected file - show contents in subView" |
|
1642 |
||
380 | 1643 |
|fileName iconLbl winLbl| |
172 | 1644 |
|
294 | 1645 |
self withReadCursorDo:[ |
380 | 1646 |
fileName := self getSelectedFileName. |
1647 |
fileName notNil ifTrue:[ |
|
1648 |
(currentDirectory isDirectory:fileName) ifTrue:[ |
|
1649 |
self doChangeCurrentDirectoryTo:fileName updateHistory:true. |
|
1650 |
winLbl := myName. |
|
1651 |
iconLbl := myName |
|
1652 |
] ifFalse:[ |
|
1653 |
(currentDirectory exists:fileName) ifFalse:[ |
|
1654 |
self warn:(resources string:'oops, ''%1'' is gone' with:fileName). |
|
1655 |
^ self |
|
1656 |
]. |
|
1657 |
timeOfFileRead := currentDirectory timeOfLastChange:fileName. |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
1658 |
self showFile:fileName insert:false encoding:fileEncoding. |
380 | 1659 |
currentFileName := fileName. |
172 | 1660 |
|
380 | 1661 |
subView acceptAction:[:theCode | |
1662 |
self withCursor:(Cursor write) do:[ |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
1663 |
self writeFile:fileName text:theCode encoding:fileEncoding. |
380 | 1664 |
timeOfFileRead := currentDirectory timeOfLastChange:fileName. |
1665 |
self label:myName , ': ' , currentFileName |
|
1666 |
] |
|
1667 |
]. |
|
172 | 1668 |
|
380 | 1669 |
winLbl := myName , ': ' , fileName. |
1670 |
(currentDirectory isWritable:fileName) ifFalse:[ |
|
1671 |
winLbl := winLbl , ' (readonly)' |
|
1672 |
]. |
|
1673 |
iconLbl := fileName |
|
1674 |
]. |
|
1675 |
self label:winLbl. |
|
1676 |
self iconLabel:iconLbl. |
|
1677 |
] |
|
172 | 1678 |
] |
294 | 1679 |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
1680 |
"Modified: 22.2.1996 / 15:02:55 / cg" |
172 | 1681 |
! |
1682 |
||
1683 |
doRemove |
|
1684 |
"remove the selected file(s) - no questions asked" |
|
1685 |
||
1686 |
|ok msg dir| |
|
1687 |
||
1688 |
lockUpdate := true. |
|
1689 |
[ |
|
380 | 1690 |
self selectedFilesDo:[:fileName | |
1691 |
ok := false. |
|
1692 |
(currentDirectory isDirectory:fileName) ifTrue:[ |
|
1693 |
dir := FileDirectory directoryNamed:fileName in:currentDirectory. |
|
1694 |
(dir isEmpty |
|
1695 |
or:[ |
|
1696 |
(self |
|
1697 |
ask:(resources string:'directory ''%1'' is not empty\remove anyway ?' with:fileName) |
|
1698 |
yesButton:'remove')]) |
|
1699 |
ifTrue:[ |
|
1700 |
ok := currentDirectory removeDirectory:fileName |
|
1701 |
]. |
|
1702 |
] ifFalse:[ |
|
1703 |
ok := currentDirectory remove:fileName. |
|
1704 |
]. |
|
1705 |
ok ifFalse:[ |
|
1706 |
"was not able to remove it" |
|
1707 |
msg := (resources string:'cannot remove ''%1'' !!' with:fileName). |
|
1708 |
self showAlert:msg with:(OperatingSystem lastErrorString) |
|
1709 |
] ifTrue:[ |
|
172 | 1710 |
" |
380 | 1711 |
self show:nil |
172 | 1712 |
" |
380 | 1713 |
] |
1714 |
]. |
|
172 | 1715 |
] valueNowOrOnUnwindDo:[ |
380 | 1716 |
lockUpdate := false. |
564 | 1717 |
fileListView setSelection:nil. |
380 | 1718 |
self updateCurrentDirectory. |
1719 |
] |
|
1720 |
||
564 | 1721 |
"Modified: 25.5.1996 / 13:02:51 / cg" |
172 | 1722 |
! |
1723 |
||
1724 |
doRename:oldName to:newName |
|
1725 |
(oldName notNil and:[newName notNil]) ifTrue:[ |
|
1726 |
(oldName isBlank or:[newName isBlank]) ifFalse:[ |
|
1727 |
currentDirectory renameFile:oldName newName:newName. |
|
1728 |
self updateCurrentDirectory. |
|
1729 |
] |
|
1730 |
] |
|
36 | 1731 |
! |
1732 |
||
1733 |
getFileInfoString:longInfo |
|
1734 |
"get stat info on selected file - return a string which can be |
|
1735 |
shown in a box" |
|
1736 |
||
133 | 1737 |
|fileName f fullPath text info fileOutput type modeBits modeString s ts| |
36 | 1738 |
|
1739 |
fileName := self getSelectedFileName. |
|
1740 |
fileName isNil ifTrue:[^ nil]. |
|
1741 |
||
133 | 1742 |
f := currentDirectory pathName asFilename construct:fileName. |
1743 |
info := f info. |
|
1744 |
||
1745 |
"/ info := currentDirectory infoOf:fileName. |
|
36 | 1746 |
info isNil ifTrue:[ |
45 | 1747 |
self showAlert:(resources string:'cannot get info of ''%1'' !!' with:fileName) |
1748 |
with:(OperatingSystem lastErrorString). |
|
1749 |
^ nil |
|
36 | 1750 |
]. |
1751 |
||
59 | 1752 |
text := StringCollection new. |
133 | 1753 |
f isSymbolicLink ifTrue:[ |
1754 |
text add:(resources string:'symbolic link to: %1' with:(f linkInfo at:#path)) |
|
1755 |
]. |
|
1756 |
||
36 | 1757 |
type := info at:#type. |
1758 |
(longInfo and:[type == #regular]) ifTrue:[ |
|
45 | 1759 |
fullPath := currentDirectory pathName , '/' , fileName. |
49 | 1760 |
fileOutput := fullPath asFilename fileType. |
36 | 1761 |
]. |
1762 |
||
1763 |
s := (resources at:'type: '). |
|
1764 |
fileOutput isNil ifTrue:[ |
|
45 | 1765 |
s := s , type asString |
36 | 1766 |
] ifFalse:[ |
45 | 1767 |
s := s , 'regular (' , fileOutput , ')' |
36 | 1768 |
]. |
1769 |
text add:s. |
|
133 | 1770 |
text add:(resources string:'size: %1' with:(info at:#size) printString). |
36 | 1771 |
|
1772 |
modeBits := (info at:#mode). |
|
1773 |
modeString := self getModeString:modeBits. |
|
1774 |
longInfo ifTrue:[ |
|
133 | 1775 |
text add:(resources string:'access: %1 (%2)' |
1776 |
with:modeString |
|
1777 |
with:(modeBits printStringRadix:8)) |
|
36 | 1778 |
] ifFalse:[ |
133 | 1779 |
text add:(resources string:'access: %1' with:modeString) |
36 | 1780 |
]. |
133 | 1781 |
text add:(resources string:'owner: %1' |
1782 |
with:(OperatingSystem getUserNameFromID:(info at:#uid))). |
|
36 | 1783 |
longInfo ifTrue:[ |
133 | 1784 |
text add:(resources string:'group: %1' |
1785 |
with:(OperatingSystem getGroupNameFromID:(info at:#gid))). |
|
36 | 1786 |
|
133 | 1787 |
ts := info at:#accessed. |
1788 |
text add:(resources string:'last access: %1 %2' |
|
1789 |
with:(ts asTime printString) |
|
1790 |
with:(ts asDate printString)). |
|
1791 |
||
1792 |
ts := info at:#modified. |
|
1793 |
text add:(resources string:'last modification: %1 %2' |
|
1794 |
with:(ts asTime printString) |
|
1795 |
with:(ts asDate printString)). |
|
36 | 1796 |
]. |
1797 |
^ text asString |
|
133 | 1798 |
|
1799 |
"Modified: 8.9.1995 / 11:59:28 / claus" |
|
36 | 1800 |
! |
1801 |
||
172 | 1802 |
getInfoFile |
1803 |
"get filename of a description-file (.dir.info, README etc.); |
|
1804 |
This file is automatically shown when a directory is enterred. |
|
1805 |
You can add more names below if you like." |
|
1806 |
||
1807 |
#( '.dir.info' |
|
1808 |
'README' |
|
1809 |
'ReadMe' |
|
1810 |
'Readme' |
|
1811 |
'readme' |
|
1812 |
) do:[:f | |
|
1813 |
(currentDirectory isReadable:f) ifTrue:[ |
|
1814 |
(currentDirectory isDirectory:f) ifFalse:[^ f]. |
|
1815 |
] |
|
1816 |
]. |
|
1817 |
^ nil |
|
1818 |
! |
|
1819 |
||
1820 |
getModeString:modeBits |
|
1821 |
"convert file-mode bits into a more user-friendly string. |
|
1822 |
This is wrong here - should be moved into OperatingSystem." |
|
1823 |
||
1824 |
^ self getModeString:modeBits |
|
1825 |
with:#( 'owner:' $r $w $x |
|
1826 |
' group:' $r $w $x |
|
1827 |
' others:' $r $w $x ) |
|
1828 |
! |
|
1829 |
||
37 | 1830 |
getModeString:modeBits with:texts |
36 | 1831 |
"convert file-mode bits into a more user-friendly string. |
1832 |
This is wrong here - should be moved into OperatingSystem." |
|
1833 |
||
1834 |
|bits modeString| |
|
1835 |
||
1836 |
bits := modeBits bitAnd:8r777. |
|
1837 |
modeString := ''. |
|
1838 |
||
1839 |
#( nil 8r400 8r200 8r100 nil 8r040 8r020 8r010 nil 8r004 8r002 8r001 ) |
|
37 | 1840 |
with: texts do:[:bitMask :access | |
116 | 1841 |
|ch| |
1842 |
||
45 | 1843 |
bitMask isNil ifTrue:[ |
1844 |
modeString := modeString , (resources string:access) |
|
1845 |
] ifFalse:[ |
|
1846 |
(bits bitAnd:bitMask) == 0 ifTrue:[ |
|
116 | 1847 |
ch := $- |
45 | 1848 |
] ifFalse:[ |
116 | 1849 |
ch := access |
1850 |
]. |
|
1851 |
modeString := modeString copyWith:ch |
|
45 | 1852 |
] |
36 | 1853 |
]. |
1854 |
^ modeString |
|
1855 |
! |
|
1856 |
||
172 | 1857 |
getSelectedFileName |
1858 |
"returns the currently selected file; shows an error if |
|
1859 |
multiple files are selected" |
|
1860 |
||
1861 |
|sel| |
|
1862 |
||
1863 |
sel := fileListView selection. |
|
1864 |
(sel size > 1) ifTrue:[ |
|
1865 |
self onlyOneSelection |
|
1866 |
] ifFalse:[ |
|
1867 |
sel notNil ifTrue:[ |
|
1868 |
^ fileList at:sel first |
|
1869 |
] |
|
1870 |
]. |
|
1871 |
^ nil |
|
1872 |
! |
|
1873 |
||
395 | 1874 |
guessEncodingFrom:aBuffer |
1875 |
|n "{Class: SmallInteger }" |
|
1876 |
binary| |
|
1877 |
||
1878 |
binary := false. |
|
1879 |
n := aBuffer size. |
|
1880 |
||
1881 |
1 to:n do:[:i | |
|
1882 |
(aBuffer at:i) isPrintable ifFalse:[binary := true]. |
|
1883 |
]. |
|
1884 |
binary ifTrue:[ |
|
1885 |
"/ look for JIS7 / EUC encoding |
|
1886 |
||
1887 |
(aBuffer findString:(JISEncodedString jis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
|
1888 |
^ #jis7 |
|
1889 |
]. |
|
396 | 1890 |
(aBuffer findString:(JISEncodedString oldJis7KanjiEscapeSequence)) ~~ 0 ifTrue:[ |
1891 |
^ #jis7 |
|
1892 |
]. |
|
395 | 1893 |
^ #binary |
1894 |
]. |
|
1895 |
^ #ascii |
|
1896 |
||
1897 |
"Created: 26.2.1996 / 17:43:08 / cg" |
|
396 | 1898 |
"Modified: 26.2.1996 / 21:53:39 / cg" |
395 | 1899 |
! |
1900 |
||
172 | 1901 |
initialCommandFor:fileName into:aBox |
1902 |
"set a useful initial command for execute box. |
|
1903 |
||
1904 |
XXX should be changed to take stuff from a config file |
|
1905 |
XXX or from resources." |
|
1906 |
||
1907 |
((currentDirectory typeOf:fileName) == #regular) ifTrue:[ |
|
1908 |
||
1909 |
(currentDirectory isExecutable:fileName) ifTrue:[ |
|
1910 |
aBox initialText:(fileName , '<arguments>'). |
|
1911 |
^ self |
|
1912 |
]. |
|
1913 |
||
1914 |
"some heuristics - my personal preferences ... |
|
1915 |
(actually this should come from a configfile)" |
|
1916 |
||
1917 |
(fileName endsWith:'akefile') ifTrue:[ |
|
1918 |
aBox initialText:'make target' selectFrom:6 to:11. |
|
1919 |
^ self |
|
1920 |
]. |
|
1921 |
(fileName endsWith:'.tar.Z') ifTrue:[ |
|
1922 |
aBox initialText:'zcat ' , fileName , ' | tar tvf -'. |
|
1923 |
^ self |
|
1924 |
]. |
|
1925 |
(fileName endsWith:'.taz') ifTrue:[ |
|
1926 |
aBox initialText:'zcat ' , fileName , ' | tar tvf -'. |
|
1927 |
^ self |
|
1928 |
]. |
|
1929 |
(fileName endsWith:'.tar') ifTrue:[ |
|
1930 |
aBox initialText:'tar tvf ' , fileName selectFrom:1 to:7. |
|
1931 |
^ self |
|
1932 |
]. |
|
1933 |
(fileName endsWith:'.zoo') ifTrue:[ |
|
1934 |
aBox initialText:'zoo -list ' , fileName selectFrom:1 to:9. |
|
1935 |
^ self |
|
1936 |
]. |
|
1937 |
(fileName endsWith:'.zip') ifTrue:[ |
|
1938 |
aBox initialText:'unzip -l ' , fileName selectFrom:1 to:8. |
|
1939 |
^ self |
|
1940 |
]. |
|
1941 |
(fileName endsWith:'.Z') ifTrue:[ |
|
1942 |
aBox initialText:'uncompress ' , fileName selectFrom:1 to:10. |
|
1943 |
^ self |
|
1944 |
]. |
|
1945 |
(fileName endsWith:'tar.gz') ifTrue:[ |
|
1946 |
aBox initialText:('gunzip <' , fileName , ' | tar tvf -' ). |
|
1947 |
^ self |
|
1948 |
]. |
|
1949 |
(fileName endsWith:'.gz') ifTrue:[ |
|
1950 |
aBox initialText:('gunzip <' , fileName , ' >' , (fileName copyWithoutLast:3 "copyTo:(fileName size - 3)")). |
|
1951 |
^ self |
|
1952 |
]. |
|
1953 |
(fileName endsWith:'.html') ifTrue:[ |
|
1954 |
aBox initialText:'chimera ' , fileName . |
|
1955 |
^ self |
|
1956 |
]. |
|
1957 |
(fileName endsWith:'.uue') ifTrue:[ |
|
1958 |
aBox initialText:'uudecode ' , fileName selectFrom:1 to:8. |
|
1959 |
^ self |
|
1960 |
]. |
|
1961 |
(fileName endsWith:'.c') ifTrue:[ |
|
1962 |
aBox initialText:'cc -c ' , fileName selectFrom:1 to:5. |
|
1963 |
^ self |
|
1964 |
]. |
|
1965 |
(fileName endsWith:'.cc') ifTrue:[ |
|
1966 |
aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6. |
|
1967 |
^ self |
|
1968 |
]. |
|
1969 |
(fileName endsWith:'.C') ifTrue:[ |
|
1970 |
aBox initialText:'g++ -c ' , fileName selectFrom:1 to:6. |
|
1971 |
^ self |
|
1972 |
]. |
|
1973 |
(fileName endsWith:'.xbm') ifTrue:[ |
|
1974 |
aBox initialText:'bitmap ' , fileName selectFrom:1 to:6. |
|
1975 |
^ self |
|
1976 |
]. |
|
1977 |
((fileName endsWith:'.ps') or:[fileName endsWith:'.PS']) ifTrue:[ |
|
1978 |
aBox initialText:'ghostview ' , fileName selectFrom:1 to:9. |
|
1979 |
^ self |
|
1980 |
]. |
|
1981 |
((fileName endsWith:'.1') |
|
1982 |
or:[fileName endsWith:'.man']) ifTrue:[ |
|
1983 |
aBox initialText:'nroff -man ' , fileName selectFrom:1 to:10. |
|
1984 |
^ self |
|
1985 |
]. |
|
1986 |
aBox initialText:'<cmd> ' , fileName selectFrom:1 to:5 |
|
1987 |
] |
|
1988 |
! |
|
1989 |
||
1990 |
onlyOneSelection |
|
1991 |
"show a warning, that only one file must be selected for |
|
1992 |
this operation" |
|
1993 |
||
1994 |
self warn:'exactly one file must be selected !!' |
|
1995 |
! |
|
1996 |
||
1997 |
selectedFilesDo:aBlock |
|
1998 |
"evaluate aBlock on all selected files; |
|
1999 |
show a wait cursor while doing this" |
|
2000 |
||
2001 |
|sel| |
|
2002 |
||
2003 |
sel := fileListView selection. |
|
2004 |
sel notNil ifTrue:[ |
|
2005 |
self withWaitCursorDo:[ |
|
2006 |
sel do:[:aSelectionIndex | |
|
2007 |
aBlock value:(fileList at:aSelectionIndex ) |
|
2008 |
] |
|
2009 |
] |
|
2010 |
] |
|
2011 |
||
2012 |
! |
|
2013 |
||
2014 |
setCurrentDirectory:aPathName |
|
2015 |
"setup for another directory" |
|
2016 |
||
2017 |
|newDirectory| |
|
2018 |
||
2019 |
aPathName isEmpty ifTrue:[^ self]. |
|
2020 |
(currentDirectory isDirectory:aPathName) ifTrue:[ |
|
564 | 2021 |
newDirectory := FileDirectory directoryNamed:aPathName in:currentDirectory. |
2022 |
newDirectory notNil ifTrue:[ |
|
2023 |
self currentDirectory:newDirectory pathName. |
|
2024 |
currentFileName notNil ifTrue:[ |
|
2025 |
fileListView contents:nil. |
|
2026 |
currentFileName := nil. |
|
2027 |
] ifFalse:[ |
|
2028 |
fileListView setSelection:nil. |
|
2029 |
fileListView scrollToTop. |
|
2030 |
]. |
|
2031 |
self updateCurrentDirectory. |
|
2032 |
self showInfo. |
|
2033 |
] |
|
172 | 2034 |
] |
2035 |
||
2036 |
"Modified: 21.9.1995 / 11:22:45 / claus" |
|
564 | 2037 |
"Modified: 25.5.1996 / 12:27:01 / cg" |
172 | 2038 |
! |
2039 |
||
2040 |
show:something |
|
2041 |
"show something in subview and undef acceptAction" |
|
2042 |
||
2043 |
subView contents:something. |
|
2044 |
subView acceptAction:nil. |
|
2045 |
subView modified:false. |
|
2046 |
currentFileName := nil |
|
2047 |
! |
|
2048 |
||
2049 |
showAlert:aString with:anErrorString |
|
2050 |
"show an alertbox, displaying the last Unix-error" |
|
2051 |
||
2052 |
|msg| |
|
2053 |
||
2054 |
anErrorString isNil ifTrue:[ |
|
2055 |
msg := aString |
|
2056 |
] ifFalse:[ |
|
2057 |
msg := aString , '\\(' , anErrorString , ')' |
|
2058 |
]. |
|
2059 |
self warn:msg withCRs |
|
2060 |
! |
|
2061 |
||
2062 |
showInfo |
|
2063 |
"show directory info when dir has changed" |
|
2064 |
||
2065 |
|info txt| |
|
2066 |
||
2067 |
info := self getInfoFile. |
|
2068 |
info notNil ifTrue:[ |
|
2069 |
txt := self readFile:info |
|
2070 |
]. |
|
2071 |
self show:txt. |
|
37 | 2072 |
! |
2073 |
||
36 | 2074 |
sizePrintString:size |
2075 |
"helper for update-directory to return a string with a files size. |
|
2076 |
This one gives the size in byte, Kb or Mb depending on size. |
|
2077 |
If you dont like this, just uncomment the first statement below." |
|
2078 |
||
93 | 2079 |
|unitString n| |
36 | 2080 |
|
2081 |
" |
|
2082 |
^ size printString. |
|
2083 |
" |
|
2084 |
unitString := ''. |
|
2085 |
size < (500 * 1024) ifTrue:[ |
|
93 | 2086 |
size < 1024 ifTrue:[ |
2087 |
n := size |
|
45 | 2088 |
] ifFalse:[ |
93 | 2089 |
n := (size * 10 // 1024 / 10.0). |
45 | 2090 |
unitString := ' Kb' |
2091 |
] |
|
36 | 2092 |
] ifFalse:[ |
93 | 2093 |
n := (size * 10 // 1024 // 1024 / 10.0). |
45 | 2094 |
unitString := ' Mb' |
36 | 2095 |
]. |
93 | 2096 |
^ (n printStringLeftPaddedTo:5) , unitString. |
36 | 2097 |
! |
2098 |
||
2099 |
updateCurrentDirectory |
|
2100 |
"update listView with directory contents" |
|
2101 |
||
142 | 2102 |
|files text len line info modeString |
53 | 2103 |
prevUid prevGid nameString groupString matchPattern| |
36 | 2104 |
|
49 | 2105 |
"the code below may look somewhat complex - |
2106 |
it reads the directory first for the names, |
|
2107 |
then (in a second sweep over the files) gets the |
|
2108 |
files type and info. This makes the Filebrowsers |
|
2109 |
list update seem faster, since the fileInfo (i.e. stat-calls) |
|
2110 |
may take long - especially on NFS-mounted directories. |
|
2111 |
The file reading is done at lower priority, to let user continue |
|
2112 |
his work in other views. However, to be fair to other fileBrowser, |
|
2113 |
which may also read directories at low prio, give up the processor |
|
2114 |
after every entry. This shares the cpu among all fileBrowsers, so |
|
2115 |
that browsers reading short directories will finish first. |
|
2116 |
ST/X users love this behavior ;-) |
|
2117 |
" |
|
2118 |
||
294 | 2119 |
self withReadCursorDo:[ |
333 | 2120 |
Processor removeTimedBlock:checkBlock. |
36 | 2121 |
|
333 | 2122 |
timeOfLastCheck := AbsoluteTime now. |
45 | 2123 |
|
333 | 2124 |
files := currentDirectory asOrderedCollection. |
36 | 2125 |
|
333 | 2126 |
matchPattern := filterField contents. |
2127 |
(matchPattern notNil and:[ |
|
2128 |
matchPattern isEmpty not and:[ |
|
2129 |
matchPattern ~= '*']]) ifTrue:[ |
|
2130 |
files := files select:[:aName | |
|
2131 |
((currentDirectory typeOf:aName) == #directory) |
|
2132 |
or:[matchPattern match:aName] |
|
2133 |
]. |
|
2134 |
]. |
|
2135 |
files sort. |
|
36 | 2136 |
|
333 | 2137 |
files size == 0 ifTrue:[ |
2138 |
self information:('directory ', currentDirectory pathName, ' vanished'). |
|
2139 |
^ self |
|
2140 |
]. |
|
2141 |
files := self withoutHiddenFiles:files. |
|
2142 |
fileList := files copy. |
|
45 | 2143 |
|
333 | 2144 |
" |
2145 |
this is a time consuming operation (especially, if reading an |
|
2146 |
NFS-mounted directory); therefore lower my priority while getting |
|
2147 |
the files info ... |
|
2148 |
" |
|
2149 |
Processor activeProcess withLowerPriorityDo:[ |
|
49 | 2150 |
|
333 | 2151 |
" |
2152 |
first show the names only - this is relatively fast |
|
2153 |
" |
|
2154 |
fileListView setList:files expandTabs:false. |
|
37 | 2155 |
|
333 | 2156 |
" |
2157 |
then walk over the files, adding more info |
|
2158 |
(since we have to stat each file, this may take a while longer |
|
2159 |
" |
|
2160 |
showLongList ifTrue:[ |
|
2161 |
tabSpec isNil ifTrue:[self defineTabulatorsForLongList]. |
|
37 | 2162 |
|
333 | 2163 |
text := OrderedCollection new. |
2164 |
files keysAndValuesDo:[:lineIndex :aFileName | |
|
2165 |
|entry col typ f p typeString| |
|
37 | 2166 |
|
333 | 2167 |
entry := MultiColListEntry new. |
2168 |
entry tabulatorSpecification:tabSpec. |
|
37 | 2169 |
|
333 | 2170 |
" |
2171 |
if multiple FileBrowsers are reading, let others |
|
2172 |
make some progress too |
|
2173 |
" |
|
2174 |
windowGroup notNil ifTrue:[windowGroup processExposeEvents]. |
|
2175 |
Processor yield. |
|
2176 |
" |
|
2177 |
could be destroyed in the meanwhile ... |
|
2178 |
" |
|
2179 |
realized ifFalse:[^ self]. |
|
36 | 2180 |
|
333 | 2181 |
len := aFileName size. |
2182 |
(len < 20) ifTrue:[ |
|
2183 |
line := aFileName , (String new:(22 - len)) |
|
2184 |
] ifFalse:[ |
|
2185 |
"can happen on BSD only" |
|
2186 |
line := (aFileName copyTo:20) , ' ' |
|
2187 |
]. |
|
2188 |
entry colAt:1 put:line. |
|
37 | 2189 |
|
333 | 2190 |
info := currentDirectory infoOf:aFileName. |
2191 |
info isNil ifTrue:[ |
|
2192 |
"not accessable - usually a symlink, |
|
2193 |
to a nonexisting/nonreadable file |
|
2194 |
" |
|
2195 |
entry colAt:2 put:'?'. |
|
2196 |
entry colAt:3 put:'(bad symbolic link ?)'. |
|
2197 |
] ifFalse:[ |
|
2198 |
typ := (info at:#type). |
|
2199 |
(typ == #regular) ifFalse:[ |
|
2200 |
entry colAt:2 put:(typ at:1) asString. |
|
2201 |
] ifTrue:[ |
|
2202 |
entry colAt:2 put:' '. |
|
2203 |
]. |
|
36 | 2204 |
|
333 | 2205 |
modeString := self getModeString:(info at:#mode) |
2206 |
with:#( '' $r $w $x |
|
2207 |
' ' $r $w $x |
|
2208 |
' ' $r $w $x ). |
|
2209 |
entry colAt:3 put:modeString. |
|
36 | 2210 |
|
333 | 2211 |
((info at:#uid) ~~ prevUid) ifTrue:[ |
2212 |
prevUid := (info at:#uid). |
|
2213 |
nameString := OperatingSystem getUserNameFromID:prevUid. |
|
2214 |
nameString := nameString , (String new:(10 - nameString size)) |
|
2215 |
]. |
|
2216 |
entry colAt:4 put:nameString withoutSpaces. |
|
2217 |
((info at:#gid) ~~ prevGid) ifTrue:[ |
|
2218 |
prevGid := (info at:#gid). |
|
2219 |
groupString := OperatingSystem getGroupNameFromID:prevGid. |
|
2220 |
groupString := groupString , (String new:(10 - groupString size)) |
|
2221 |
]. |
|
2222 |
entry colAt:5 put:groupString withoutSpaces. |
|
36 | 2223 |
|
333 | 2224 |
(typ == #regular) ifTrue:[ |
2225 |
entry colAt:6 put:(self sizePrintString:(info at:#size)). |
|
2226 |
]. |
|
49 | 2227 |
|
333 | 2228 |
f := currentDirectory asFilename:aFileName. |
2229 |
f isSymbolicLink ifTrue:[ |
|
2230 |
p := f linkInfo at:#path. |
|
2231 |
typeString := 'symbolic link to ' , p |
|
2232 |
] ifFalse:[ |
|
2233 |
(showVeryLongList not or:[typ == #directory]) ifTrue:[ |
|
2234 |
typeString := typ asString |
|
2235 |
] ifFalse:[ |
|
2236 |
typeString := f fileType. |
|
2237 |
]. |
|
2238 |
]. |
|
2239 |
entry colAt:7 put:typeString. |
|
2240 |
text add:entry |
|
2241 |
]. |
|
2242 |
fileListView at:lineIndex put:entry |
|
2243 |
]. |
|
2244 |
] ifFalse:[ |
|
2245 |
files keysAndValuesDo:[:lineIndex :aName | |
|
2246 |
|entry| |
|
49 | 2247 |
|
333 | 2248 |
" |
2249 |
if multiple FileBrowsers are reading, let others |
|
2250 |
make some progress too |
|
2251 |
" |
|
2252 |
windowGroup notNil ifTrue:[windowGroup processExposeEvents]. |
|
2253 |
Processor yield. |
|
2254 |
realized ifFalse:[^ self]. |
|
49 | 2255 |
|
333 | 2256 |
((currentDirectory isDirectory:aName) and:[ |
2257 |
(aName ~= '..') and:[aName ~= '.']]) ifTrue:[ |
|
2258 |
entry := aName , ' ...' |
|
2259 |
] ifFalse:[ |
|
2260 |
entry := aName |
|
2261 |
]. |
|
2262 |
fileListView at:lineIndex put:entry |
|
2263 |
]. |
|
2264 |
]. |
|
2265 |
]. |
|
36 | 2266 |
|
333 | 2267 |
" |
2268 |
install a new check after some time |
|
2269 |
" |
|
2270 |
Processor addTimedBlock:checkBlock afterSeconds:checkDelta |
|
36 | 2271 |
] |
142 | 2272 |
|
2273 |
"Modified: 21.9.1995 / 11:40:23 / claus" |
|
294 | 2274 |
"Modified: 14.12.1995 / 20:59:09 / cg" |
36 | 2275 |
! |
2276 |
||
482 | 2277 |
validateFontEncodingFor:newEncoding |
2278 |
"if required, query user if he/she wants to change to another font, |
|
2279 |
which is able to display text encoded as specified by newEncoding" |
|
2280 |
||
2281 |
|fontsEncoding msg filter f| |
|
2282 |
||
2283 |
fontsEncoding := subView font encoding. |
|
2284 |
||
2285 |
((newEncoding == #jis7) or:[newEncoding == #euc]) ifTrue:[ |
|
2286 |
(fontsEncoding notNil and:[fontsEncoding startsWith:'jis']) ifFalse:[ |
|
2287 |
msg := 'switch to a JIS encoded font ?'. |
|
2288 |
filter := [:f | f encoding notNil |
|
2289 |
and:['jis*' match:f encoding]]. |
|
2290 |
] |
|
2291 |
] ifFalse:[ |
|
2292 |
(newEncoding == #gb) ifTrue:[ |
|
2293 |
(fontsEncoding notNil and:[fontsEncoding startsWith:'gb']) ifFalse:[ |
|
2294 |
msg := 'switch to a GB encoded font ?'. |
|
2295 |
filter := [:f | f encoding notNil |
|
2296 |
and:['gb*' match:f encoding]]. |
|
2297 |
] |
|
2298 |
] ifFalse:[ |
|
2299 |
(newEncoding == #big5) ifTrue:[ |
|
2300 |
(fontsEncoding notNil and:[fontsEncoding startsWith:'big5']) ifFalse:[ |
|
2301 |
msg := 'switch to a BIG-5 encoded font ?'. |
|
2302 |
filter := [:f | f encoding notNil |
|
2303 |
and:['big5*' match:f encoding]]. |
|
2304 |
] |
|
2305 |
] ifFalse:[ |
|
2306 |
fontsEncoding notNil ifTrue:[ |
|
2307 |
((fontsEncoding startsWith:'jis') |
|
2308 |
or:[(fontsEncoding startsWith:'gb') |
|
2309 |
or:[(fontsEncoding startsWith:'big5')]]) |
|
2310 |
ifTrue:[ |
|
2311 |
msg := 'switch back to an ASCII encoded font ?'. |
|
2312 |
filter := [:f | f encoding notNil |
|
2313 |
and:[('ascii' match:f encoding) |
|
2314 |
or:['iso*' match:f encoding]]]. |
|
2315 |
] |
|
2316 |
] |
|
2317 |
] |
|
2318 |
] |
|
2319 |
]. |
|
2320 |
||
2321 |
msg notNil ifTrue:[ |
|
2322 |
(self confirm:(resources string:msg) withCRs) |
|
2323 |
ifTrue:[ |
|
2324 |
f := FontPanel |
|
2325 |
fontFromUserInitial:nil |
|
2326 |
title:(resources string:'font selection') |
|
2327 |
filter:filter. |
|
2328 |
f notNil ifTrue:[ |
|
2329 |
subView font:f |
|
2330 |
] |
|
2331 |
] |
|
2332 |
] |
|
2333 |
||
2334 |
"Modified: 17.4.1996 / 18:45:58 / cg" |
|
2335 |
"Created: 17.4.1996 / 18:48:29 / cg" |
|
2336 |
! |
|
2337 |
||
172 | 2338 |
withoutHiddenFiles:aCollection |
2339 |
"remove hidden files (i.e. those that start with '.') from |
|
2340 |
the list in aCollection" |
|
36 | 2341 |
|
172 | 2342 |
|newCollection| |
52 | 2343 |
|
172 | 2344 |
newCollection := aCollection species new. |
2345 |
aCollection do:[:fname | |
|
380 | 2346 |
|ignore| |
2347 |
||
2348 |
ignore := false. |
|
2349 |
||
2350 |
((fname startsWith:'.') and:[fname ~= '..']) ifTrue:[ |
|
2351 |
showDotFiles ifFalse:[ |
|
2352 |
ignore := true |
|
2353 |
] |
|
2354 |
]. |
|
2355 |
ignore ifFalse:[ |
|
2356 |
newCollection add:fname |
|
2357 |
] |
|
36 | 2358 |
]. |
172 | 2359 |
^ newCollection |
380 | 2360 |
|
2361 |
"Modified: 21.2.1996 / 01:33:18 / cg" |
|
386
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 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2364 |
!FileBrowser methodsFor:'private-file-I/O'! |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2365 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2366 |
readFile:fileName |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2367 |
"read in the file, answer its contents as StringCollection" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2368 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2369 |
^ self readFile:fileName lineDelimiter:Character cr encoding:nil |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2370 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2371 |
"Modified: 22.2.1996 / 14:57:08 / cg" |
36 | 2372 |
! |
2373 |
||
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2374 |
readFile:fileName lineDelimiter:aCharacter encoding:encoding |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2375 |
"read in the file, return its contents as StringCollection. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2376 |
The files lines are delimited by aCharacter. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2377 |
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
|
2378 |
that symbol, and #decodeString: should be able to convert it." |
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 |
|stream text msg sz| |
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 |
stream := FileStream readonlyFileNamed:fileName in:currentDirectory. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2383 |
stream isNil ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2384 |
msg := (resources string:'cannot read file ''%1'' !!' with:fileName). |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2385 |
self showAlert:msg with:(FileStream lastErrorString). |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2386 |
^ nil |
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 |
for very big files, give ObjectMemory a hint, to preallocate more |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2391 |
" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2392 |
(sz := stream size) > 1000000 ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2393 |
Processor activeProcess withLowerPriorityDo:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2394 |
ObjectMemory announceSpaceNeed:(sz + (sz // 5)) "/ add 20% for tab expansion |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2395 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2396 |
]. |
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 |
text := self readStream:stream lineDelimiter:aCharacter encoding:encoding. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2399 |
stream close. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2400 |
^ text |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2401 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2402 |
"Created: 22.2.1996 / 14:56:48 / cg" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2403 |
"Modified: 22.2.1996 / 14:58:16 / 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 |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2407 |
"read in from aStream, answer its contents as StringCollection" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2408 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2409 |
^ self readStream:aStream lineDelimiter:Character cr encoding:nil |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2410 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2411 |
"Modified: 22.2.1996 / 14:58:40 / cg" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2412 |
! |
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 |
readStream:aStream lineDelimiter:aCharacter encoding:encoding |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2415 |
"read from aStream, answer its contents as StringCollection. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2416 |
The files lines are delimited by aCharacter. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2417 |
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
|
2418 |
that symbol, and #decodeString: should be able to convert it." |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2419 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2420 |
|text line| |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2421 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2422 |
text := StringCollection new. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2423 |
aCharacter == Character cr ifTrue:[ |
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 nextLine 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 |
] ifFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2432 |
[aStream atEnd] whileFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2433 |
line := (aStream upTo:aCharacter) withTabsExpanded. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2434 |
encoding notNil ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2435 |
line := line decodeFrom:encoding |
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 |
text add:line |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2438 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2439 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2440 |
^ text |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2441 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2442 |
"Created: 22.2.1996 / 14:58:25 / cg" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2443 |
"Modified: 22.2.1996 / 15:07:53 / 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 |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2447 |
"show contents of fileName in subView" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2448 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2449 |
self showFile:fileName insert:false encoding:fileEncoding |
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 |
"Modified: 22.2.1996 / 14:47:10 / cg" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2452 |
! |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2453 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2454 |
showFile:fileName insert:insert encoding:encoding |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2455 |
"show/insert contents of fileName in subView" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2456 |
|
395 | 2457 |
|buffer s n i ok convert text msg eol guess| |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2458 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2459 |
((currentDirectory typeOf:fileName) == #regular) ifFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2460 |
"asked for a non-file - ignore it ..." |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2461 |
(currentDirectory exists:fileName) ifFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2462 |
msg := '''%1'' does not exist !!'. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2463 |
] ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2464 |
msg := '''%1'' is not a regular file !!'. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2465 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2466 |
self warn:(resources string:msg with:fileName). |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2467 |
^ self |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2468 |
]. |
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 |
check if file is a text file |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2471 |
" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2472 |
s := FileStream readonlyFileNamed:fileName in:currentDirectory. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2473 |
s isNil ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2474 |
self showAlert:(resources string:'cannot read file ''%1'' !!' with:fileName) |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2475 |
with:(FileStream lastErrorString). |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2476 |
^ nil |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2477 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2478 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2479 |
buffer := String new:300. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2480 |
n := s nextBytes:300 into:buffer. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2481 |
s close. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2482 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2483 |
ok := true. |
395 | 2484 |
guess := self guessEncodingFrom:buffer. |
2485 |
guess == #binary ifTrue:[ |
|
2486 |
ok := false. |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2487 |
(self binaryFileAction:fileName) ifTrue:[^ self]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2488 |
(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
|
2489 |
ifFalse:[^ self] |
395 | 2490 |
] ifFalse:[ |
2491 |
guess ~~ #ascii ifTrue:[ |
|
2492 |
fileEncoding ~~ guess ifTrue:[ |
|
2493 |
(self confirm:(resources string:'''%1'' seems to be ' , guess , ' encoded - show anyway ?' with:fileName)) |
|
2494 |
ifFalse:[^ self] |
|
2495 |
] |
|
2496 |
]. |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2497 |
]. |
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 |
convert := false. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2500 |
ok ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2501 |
" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2502 |
check if line delimiter is a cr |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2503 |
" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2504 |
i := buffer indexOf:Character cr. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2505 |
i == 0 ifTrue:[ |
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 |
no newline found - try cr |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2508 |
" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2509 |
i := buffer indexOf:(Character value:13). |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2510 |
i ~~ 0 ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2511 |
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
|
2512 |
] |
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 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2516 |
insert ifFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2517 |
"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
|
2518 |
(helps if you have a 4Mb file in the view, and click on another biggy)" |
395 | 2519 |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2520 |
subView contents:nil. |
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 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2523 |
convert ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2524 |
eol := Character value:13 |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2525 |
] ifFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2526 |
eol := Character cr |
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 |
text := self readFile:fileName lineDelimiter:eol encoding:encoding. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2529 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2530 |
insert ifFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2531 |
self show:text |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2532 |
] ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2533 |
subView insertSelectedStringAtCursor:text asString |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2534 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2535 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2536 |
"Created: 22.2.1996 / 14:46:57 / cg" |
395 | 2537 |
"Modified: 26.2.1996 / 17:48:24 / cg" |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2538 |
! |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2539 |
|
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2540 |
writeFile:fileName text:someText encoding:encoding |
36 | 2541 |
|stream msg startNr nLines string| |
2542 |
||
310 | 2543 |
stream := FileStream newFileNamed:fileName in:currentDirectory. |
2544 |
stream isNil ifTrue:[ |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2545 |
msg := (resources string:'cannot write file ''%1'' !!' with:fileName). |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2546 |
self showAlert:msg with:(FileStream lastErrorString) |
310 | 2547 |
] ifFalse:[ |
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2548 |
someText isString ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2549 |
stream nextPutAll:someText. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2550 |
] ifFalse:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2551 |
" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2552 |
on some systems, writing linewise is very slow (via NFS) |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2553 |
therefore we convert to a string and write it in chunks |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2554 |
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
|
2555 |
" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2556 |
startNr := 1. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2557 |
nLines := someText size. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2558 |
[startNr <= nLines] whileTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2559 |
string := someText asStringWithCRsFrom:startNr |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2560 |
to:((startNr + 1000) min:nLines) |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2561 |
compressTabs:compressTabs. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2562 |
encoding notNil ifTrue:[ |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2563 |
string := string encodeInto:encoding |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2564 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2565 |
stream nextPutAll:string. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2566 |
startNr := startNr + 1000 + 1. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2567 |
]. |
36 | 2568 |
"/ someText do:[:line | |
2569 |
"/ line notNil ifTrue:[ |
|
2570 |
"/ stream nextPutAll:line. |
|
2571 |
"/ ]. |
|
2572 |
"/ stream cr. |
|
2573 |
"/ ] |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2574 |
]. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2575 |
stream close. |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2576 |
subView modified:false |
36 | 2577 |
] |
310 | 2578 |
|
386
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2579 |
"Created: 22.2.1996 / 15:03:10 / cg" |
3fd24d9116b3
added encodings (experimental)
Claus Gittinger <cg@exept.de>
parents:
381
diff
changeset
|
2580 |
"Modified: 22.2.1996 / 15:08:31 / cg" |
36 | 2581 |
! ! |
2582 |
||
172 | 2583 |
!FileBrowser methodsFor:'queries'! |
73 | 2584 |
|
172 | 2585 |
path |
2586 |
"return my currentDirectories pathName; |
|
2587 |
sent from the pathField label to aquire pathname when I changed directory" |
|
49 | 2588 |
|
172 | 2589 |
^ currentDirectory pathName |
49 | 2590 |
! ! |
2591 |
||
203 | 2592 |
!FileBrowser class methodsFor:'documentation'! |
2593 |
||
2594 |
version |
|
564 | 2595 |
^ '$Header: /cvs/stx/stx/libtool/FileBrowser.st,v 1.90 1996-05-25 11:32:05 cg Exp $' |
381 | 2596 |
! ! |