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