changeset 351 | 24a527f86c7b |
parent 296 | e1b9431b3aef |
child 438 | 8df6f72d1569 |
350:e3512322cb87 | 351:24a527f86c7b |
---|---|
9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 |
12 |
13 ListSelectionBox subclass:#FileSelectionBox |
13 ListSelectionBox subclass:#FileSelectionBox |
14 instanceVariableNames:'patternField' |
14 instanceVariableNames:'patternField selectingDirectory' |
15 classVariableNames:'' |
15 classVariableNames:'' |
16 poolDictionaries:'' |
16 poolDictionaries:'' |
17 category:'Views-DialogBoxes' |
17 category:'Views-DialogBoxes' |
18 ! |
18 ! |
19 |
19 |
20 !FileSelectionBox class methodsFor:'documentation'! |
20 !FileSelectionBox class methodsFor:'documentation'! |
21 |
21 |
22 copyright |
22 copyright |
66 examples |
66 examples |
67 " |
67 " |
68 simple standard queries |
68 simple standard queries |
69 |
69 |
70 very simple: |
70 very simple: |
71 |name| |
71 |name| |
72 |
72 |
73 name := FileSelectionBox requestFilename. |
73 name := FileSelectionBox requestFilename. |
74 Transcript showCr:name |
74 Transcript showCr:name |
75 |
75 |
76 |
76 |
77 simple: |
77 simple: |
78 |name| |
78 |name| |
79 |
79 |
80 name := FileSelectionBox requestFilename:'which file ?'. |
80 name := FileSelectionBox requestFilename:'which file ?'. |
81 Transcript showCr:name |
81 Transcript showCr:name |
82 |
82 |
83 |
83 |
84 with initial selection: |
84 with initial selection: |
85 |name| |
85 |name| |
86 |
86 |
87 name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'. |
87 name := FileSelectionBox requestFilename:'which file ?' default:'Make.proto'. |
88 Transcript showCr:name |
88 Transcript showCr:name |
89 |
89 |
90 |
90 |
91 |
91 |
92 more detailed setup |
92 more detailed setup |
93 |
93 |
94 setting title: |
94 setting title: |
95 |
95 |
96 |box| |
96 |box| |
97 box := FileSelectionBox new. |
97 box := FileSelectionBox new. |
98 box title:'Which file ?'. |
98 box title:'Which file ?'. |
99 box open. |
99 box open. |
100 box accepted ifTrue:[ |
100 box accepted ifTrue:[ |
101 Transcript showCr:'you selected: ' , box |
101 Transcript showCr:'you selected: ' , box |
102 ] |
102 ] |
103 |
103 |
104 setting a matchpattern: |
104 setting a matchpattern: |
105 |
105 |
106 |box| |
106 |box| |
107 box := FileSelectionBox new. |
107 box := FileSelectionBox new. |
108 box title:'Which file ?'. |
108 box title:'Which file ?'. |
109 box pattern:'*.rc'. |
109 box pattern:'*.rc'. |
110 box open |
110 box open |
111 |
|
112 setting multiple patterns: |
|
113 |
|
114 |box| |
|
115 box := FileSelectionBox new. |
|
116 box title:'Which file ?'. |
|
117 box pattern:'*.rc;*.st'. |
|
118 box open |
|
111 |
119 |
112 setting a matchblock: |
120 setting a matchblock: |
113 |
121 |
114 |box| |
122 |box| |
115 box := FileSelectionBox new. |
123 box := FileSelectionBox new. |
116 box title:'Which file ?'. |
124 box title:'Which file ?'. |
117 box pattern:'*'. |
125 box directory:'/etc'. |
118 box matchBlock:[:name | name first isLowercase]. |
126 box pattern:'*'. |
119 box open |
127 box matchBlock:[:name | name asFilename baseName first between:$a and:$z]. |
128 box open |
|
120 |
129 |
121 both pattern and matchBlock: |
130 both pattern and matchBlock: |
122 |
131 |
123 |box| |
132 |box| |
124 box := FileSelectionBox new. |
133 box := FileSelectionBox new. |
125 box title:'Which directory ?'. |
134 box title:'Which directory ?'. |
126 box pattern:'l*'. |
135 box selectingDirectory:true. |
127 box matchBlock:[:name | OperatingSystem isDirectory:name]. |
136 box pattern:'l*'. |
128 box open |
137 box matchBlock:[:name | OperatingSystem isDirectory:name]. |
138 box action:[:fn | Transcript showCr:fn]. |
|
139 box open |
|
129 |
140 |
130 dont show the parent directory: |
141 dont show the parent directory: |
131 |
142 |
132 |box| |
143 |box| |
133 box := FileSelectionBox new. |
144 box := FileSelectionBox new. |
134 box title:'Which directory ?'. |
145 box title:'Which directory ?'. |
135 box listView ignoreParentDirectory:true. |
146 box listView ignoreParentDirectory:true. |
136 box open |
147 box open |
137 |
148 |
138 dont show any directory: |
149 dont show any directory: |
139 |
150 |
140 |box| |
151 |box| |
141 box := FileSelectionBox new. |
152 box := FileSelectionBox new. |
142 box title:'Which file ?'. |
153 box title:'Which file ?'. |
143 box listView ignoreDirectories:true. |
154 box listView ignoreDirectories:true. |
144 box open |
155 box open |
145 |
156 |
146 dont show any directory or hidden file: |
157 dont show any directory or hidden file: |
147 (notice the basename extraction - we are not interrested in the full pathName) |
158 (notice the basename extraction - we are not interrested in the full pathName) |
148 |
159 |
149 |box| |
160 |box| |
150 box := FileSelectionBox new. |
161 box := FileSelectionBox new. |
151 box title:'Which file ?'. |
162 box title:'Which file ?'. |
152 box listView ignoreDirectories:true. |
163 box listView ignoreDirectories:true. |
153 box matchBlock:[:name | (name asFilename baseName startsWith:'.') not]. |
164 box matchBlock:[:name | (name asFilename baseName startsWith:'.') not]. |
154 box open |
165 box open |
155 |
166 |
156 dont allow direct filename entry: |
167 dont allow direct filename entry: |
157 (i.e. avoid the user choosing files from other directories) |
168 (i.e. avoid the user choosing files from other directories) |
158 |
169 |
159 |box| |
170 |box| |
160 box := FileSelectionBox new. |
171 box := FileSelectionBox new. |
161 box title:'Which one ?'. |
172 box title:'Which one ?'. |
162 box enterField beInvisible. |
173 box enterField beInvisible. |
163 box open. |
174 box open. |
164 box accepted ifTrue:[ |
175 box accepted ifTrue:[ |
165 Transcript showCr:'path is ' , box pathName |
176 Transcript showCr:'path is ' , box pathName |
166 ]. |
177 ]. |
167 |
178 |
168 combined with above directory ignoring, |
179 combined with above directory ignoring, |
169 this limits selection of files from a single directory: |
180 this limits selection of files from a single directory: |
170 |
181 |
171 |box| |
182 |box| |
172 box := FileSelectionBox new. |
183 box := FileSelectionBox new. |
173 box title:'Which file ?'. |
184 box title:'Which file ?'. |
174 box enterField beInvisible. |
185 box enterField beInvisible. |
175 box listView ignoreDirectories:true. |
186 box listView ignoreDirectories:true. |
176 box open. |
187 box open. |
177 box accepted ifTrue:[ |
188 box accepted ifTrue:[ |
178 Transcript showCr:'path is ' , box pathName |
189 Transcript showCr:'path is ' , box pathName |
179 ]. |
190 ]. |
180 |
191 |
181 finally, an action: |
192 finally, an action: |
182 |
193 |
183 |box| |
194 |box| |
184 box := FileSelectionBox new. |
195 box := FileSelectionBox new. |
185 box title:'Which directory ?'. |
196 box title:'Which directory ?'. |
186 box pattern:'l*'. |
197 box pattern:'l*'. |
187 box matchBlock:[:name | OperatingSystem isDirectory:name]. |
198 box matchBlock:[:name | OperatingSystem isDirectory:name]. |
188 box action:[:name | Transcript showCr:name]. |
199 box action:[:name | Transcript showCr:name]. |
189 box open |
200 box open |
190 |
201 |
191 concrete examples: |
202 concrete examples: |
192 |
203 |
193 only show files beginning with lowercase characters |
204 only show files beginning with lowercase characters |
194 and ending in '.c': |
205 and ending in '.c': |
195 |
206 |
196 |box| |
207 |box| |
197 box := FileSelectionBox new. |
208 box := FileSelectionBox new. |
198 box title:'Which directory ?'. |
209 box title:'Which directory ?'. |
199 box matchBlock:[:name | |
210 box matchBlock:[:name | |
200 box pathName asFilename isDirectory |
211 box pathName asFilename isDirectory |
201 or:[name first isLowercase |
212 or:[name first isLowercase |
202 and:[name endsWith:'.c']] |
213 and:[name endsWith:'.c']] |
203 ]. |
214 ]. |
204 box open. |
215 box open. |
205 box accepted ifTrue:[ |
216 box accepted ifTrue:[ |
206 Transcript showCr:'full path: ' , box pathName. |
217 Transcript showCr:'full path: ' , box pathName. |
207 Transcript showCr:'files name: ' , box fileName. |
218 Transcript showCr:'files name: ' , box fileName. |
208 Transcript showCr:'directory : ' , box directory. |
219 Transcript showCr:'directory : ' , box directory. |
209 ] |
220 ] |
210 |
221 |
211 somewhat wierd example: |
222 somewhat wierd example: |
212 only show files, if the directory we are in begins with 'lib': |
223 only show files, if the directory we are in begins with 'lib': |
213 |
224 |
214 |box| |
225 |box| |
215 box := FileSelectionBox new. |
226 box := FileSelectionBox new. |
216 box title:'Which directory ?'. |
227 box title:'Which directory ?'. |
217 box pattern:'l*'. |
228 box pattern:'l*'. |
218 box matchBlock:[:name | |
229 box matchBlock:[:name | |
219 box directory asString beginsWith:'lib' |
230 box directory asString beginsWith:'lib' |
220 ]. |
231 ]. |
221 box open |
232 box open |
222 box accepted ifTrue:[ |
233 box accepted ifTrue:[ |
223 Transcript showCr:'full path: ' , box pathName. |
234 Transcript showCr:'full path: ' , box pathName. |
224 Transcript showCr:'files name: ' , box fileName. |
235 Transcript showCr:'files name: ' , box fileName. |
225 Transcript showCr:'directory : ' , box directory. |
236 Transcript showCr:'directory : ' , box directory. |
226 ] |
237 ] |
227 |
238 |
228 " |
239 " |
229 ! ! |
240 ! ! |
230 |
241 |
231 !FileSelectionBox class methodsFor:'defaults'! |
242 !FileSelectionBox class methodsFor:'defaults'! |
302 ^ FileSelectionList |
313 ^ FileSelectionList |
303 ! ! |
314 ! ! |
304 |
315 |
305 !FileSelectionBox methodsFor:'accessing'! |
316 !FileSelectionBox methodsFor:'accessing'! |
306 |
317 |
307 pathName |
318 contents |
308 "same as contents - return the full pathname of the selected file, |
319 "return the current entered value (i.e. the enterFields string). |
309 or the pathname of the directory if nothing has been entered" |
320 redefined to return the full pathname." |
310 |
321 |
311 ^ self contents |
322 |string sep| |
323 |
|
324 string := super contents. |
|
325 string isNil ifTrue:[ |
|
326 ^ selectionList directory pathName |
|
327 ]. |
|
328 sep := Filename separator. |
|
329 (string startsWith:sep) ifTrue:[ |
|
330 ^ string |
|
331 ]. |
|
332 ^ (selectionList directory pathName asFilename construct:string) asString |
|
333 ! |
|
334 |
|
335 directory |
|
336 "return the directory which is currently shown" |
|
337 |
|
338 ^ selectionList directory |
|
339 ! |
|
340 |
|
341 directory:directoryName |
|
342 "change the directory shown in the list." |
|
343 |
|
344 selectionList directory:directoryName |
|
312 ! |
345 ! |
313 |
346 |
314 fileName |
347 fileName |
315 "if some filename has been entered, return it (without the directory path) |
348 "if some filename has been entered, return it (without the directory path) |
316 otherwise, return nil" |
349 otherwise, return nil" |
318 |string| |
351 |string| |
319 |
352 |
320 string := super contents. |
353 string := super contents. |
321 string isNil ifTrue:[^ nil]. |
354 string isNil ifTrue:[^ nil]. |
322 ^ self pathName |
355 ^ self pathName |
323 ! |
|
324 |
|
325 contents |
|
326 "return the current entered value (i.e. the enterFields string). |
|
327 redefined to return the full pathname." |
|
328 |
|
329 |string sep| |
|
330 |
|
331 string := super contents. |
|
332 string isNil ifTrue:[ |
|
333 ^ selectionList directory pathName |
|
334 ]. |
|
335 sep := Filename separator. |
|
336 (string startsWith:sep) ifTrue:[ |
|
337 ^ string |
|
338 ]. |
|
339 ^ (selectionList directory pathName asFilename construct:string) asString |
|
340 ! |
|
341 |
|
342 directory |
|
343 "return the directory which is currently shown" |
|
344 |
|
345 ^ selectionList directory |
|
346 ! |
|
347 |
|
348 directory:directoryName |
|
349 "change the directory shown in the list." |
|
350 |
|
351 selectionList directory:directoryName |
|
352 ! |
356 ! |
353 |
357 |
354 matchBlock:aBlock |
358 matchBlock:aBlock |
355 "set the matchBlock (in the selectionList). Only files |
359 "set the matchBlock (in the selectionList). Only files |
356 for which the block returns true are shown. |
360 for which the block returns true are shown. |
363 "open the box showing files in aPath. |
367 "open the box showing files in aPath. |
364 This is only a shortcut message - no new functionality." |
368 This is only a shortcut message - no new functionality." |
365 |
369 |
366 self directory:aPath. |
370 self directory:aPath. |
367 self showAtPointer |
371 self showAtPointer |
372 ! |
|
373 |
|
374 pathName |
|
375 "same as contents - return the full pathname of the selected file, |
|
376 or the pathname of the directory if nothing has been entered" |
|
377 |
|
378 ^ self contents |
|
368 ! |
379 ! |
369 |
380 |
370 pattern:aPattern |
381 pattern:aPattern |
371 "set the pattern - this also enables the PatternField |
382 "set the pattern - this also enables the PatternField |
372 (if the pattern is non-nil) or hides it (if nil)." |
383 (if the pattern is non-nil) or hides it (if nil)." |
400 |
411 |
401 patternField hiddenOnRealize:hidePatternField. |
412 patternField hiddenOnRealize:hidePatternField. |
402 windowGroup notNil ifTrue:[ |
413 windowGroup notNil ifTrue:[ |
403 windowGroup focusSequence:focusSequence |
414 windowGroup focusSequence:focusSequence |
404 ]. |
415 ]. |
416 ! |
|
417 |
|
418 selectingDirectory:aBoolean |
|
419 selectingDirectory := aBoolean |
|
405 ! ! |
420 ! ! |
406 |
421 |
407 !FileSelectionBox methodsFor:'change & update'! |
422 !FileSelectionBox methodsFor:'change & update'! |
408 |
423 |
409 update:something with:argument from:changedObject |
424 update:something with:argument from:changedObject |
456 |
471 |
457 initialize |
472 initialize |
458 |corner| |
473 |corner| |
459 |
474 |
460 super initialize. |
475 super initialize. |
476 selectingDirectory := false. |
|
461 |
477 |
462 label := resources string:'File dialog'. |
478 label := resources string:'File dialog'. |
463 |
479 |
464 labelField extent:(0.7 @ labelField height). |
480 labelField extent:(0.7 @ labelField height). |
465 labelField label:(resources string:'select a file:'). |
481 labelField label:(resources string:'select a file:'). |
466 labelField adjust:#left. |
482 labelField adjust:#left. |
467 |
483 |
468 patternField := EditField in:self. |
484 patternField := EditField in:self. |
469 self is3D ifTrue:[ |
485 self is3D ifTrue:[ |
470 corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)). |
486 corner := (1.0 @ (labelField origin y+patternField heightIncludingBorder)). |
471 ] ifFalse:[ |
487 ] ifFalse:[ |
472 corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")]. |
488 corner := [(width - ViewSpacing - (patternField borderWidth * 2)) @ (labelField origin y+patternField height"IncludingBorder")]. |
473 ]. |
489 ]. |
474 patternField origin:(0.7 @ labelField origin y) corner:corner. |
490 patternField origin:(0.7 @ labelField origin y) corner:corner. |
475 patternField rightInset:ViewSpacing. |
491 patternField rightInset:ViewSpacing. |
476 patternField initialText:'*'. |
492 patternField initialText:'*'. |
477 patternField leaveAction:[:reason | |
493 patternField leaveAction:[:reason | |
478 selectionList pattern:patternField contents. |
494 selectionList pattern:patternField contents. |
479 self updateList |
495 self updateList |
480 ]. |
496 ]. |
481 patternField hiddenOnRealize:true. "delay showing, until a pattern is defined" |
497 patternField hiddenOnRealize:true. "delay showing, until a pattern is defined" |
482 |
498 |
483 enterField addDependent:self. |
499 enterField addDependent:self. |
484 |
500 |
554 "called for both on ok-press and on return-key" |
570 "called for both on ok-press and on return-key" |
555 |
571 |
556 |dir string fname| |
572 |dir string fname| |
557 |
573 |
558 string := enterField contents. |
574 string := enterField contents. |
559 string notNil ifTrue:[ |
575 (string notNil and:[string notEmpty]) ifTrue:[ |
560 string := string withoutSeparators. |
576 string := string withoutSeparators. |
561 string asFilename isAbsolute ifTrue:[ |
577 string asFilename isAbsolute ifTrue:[ |
562 fname := string asFilename |
578 fname := string asFilename |
563 ] ifFalse:[ |
579 ] ifFalse:[ |
564 dir := selectionList directory pathName asFilename. |
580 dir := selectionList directory pathName asFilename. |
565 fname := dir construct:string |
581 fname := dir construct:string |
566 ]. |
582 ]. |
567 fname isDirectory ifTrue:[ |
583 fname isDirectory ifTrue:[ |
568 selectionList directory:fname asString. |
584 selectingDirectory ifFalse:[ |
569 self updateList. |
585 selectionList directory:fname asString. |
570 ^ self |
586 self updateList. |
571 ] |
587 ^ self |
572 ]. |
588 ] |
589 ] |
|
590 ] ifFalse:[ |
|
591 selectingDirectory ifTrue:[ |
|
592 enterField contents:(selectionList directory pathName). |
|
593 ]. |
|
594 ]. |
|
595 |
|
573 super okPressed |
596 super okPressed |
597 |
|
574 ! |
598 ! |
575 |
599 |
576 selectionChanged |
600 selectionChanged |
577 |entry| |
601 |entry| |
578 |
602 |
581 ! ! |
605 ! ! |
582 |
606 |
583 !FileSelectionBox class methodsFor:'documentation'! |
607 !FileSelectionBox class methodsFor:'documentation'! |
584 |
608 |
585 version |
609 version |
586 ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.27 1996-01-18 21:28:46 cg Exp $' |
610 ^ '$Header: /cvs/stx/stx/libwidg/FileSelectionBox.st,v 1.28 1996-02-10 09:36:47 ca Exp $' |
587 ! ! |
611 ! ! |