|
1 " |
|
2 COPYRIGHT (c) 1990-93 by Claus Gittinger |
|
3 All Rights Reserved |
|
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 ListSelectionBox subclass:#FileSelectionBox |
|
14 instanceVariableNames:'patternField directory timeStamp directoryId' |
|
15 classVariableNames:'' |
|
16 poolDictionaries:'' |
|
17 category:'Views-Interactors' |
|
18 ! |
|
19 |
|
20 FileSelectionBox comment:' |
|
21 |
|
22 COPYRIGHT (c) 1990-93 by Claus Gittinger |
|
23 All Rights Reserved |
|
24 |
|
25 this class implements file selection boxes. They show a list of |
|
26 files, and perform an action block with the selected pathname as |
|
27 argument when ok is clicked. |
|
28 |
|
29 %W% %E% |
|
30 written Jan 90 by claus |
|
31 '! |
|
32 |
|
33 !FileSelectionBox methodsFor:'initialization'! |
|
34 |
|
35 initialize |
|
36 directory := FileDirectory currentDirectory. |
|
37 super initialize. |
|
38 |
|
39 "selections in list get forwarded to enterfield if not a directory; |
|
40 otherwise directory is changed" |
|
41 |
|
42 selectionList action:[:lineNr | |
|
43 |entry| |
|
44 |
|
45 entry := selectionList selectionValue. |
|
46 ((directory typeOf:entry) == #directory) ifTrue:[ |
|
47 self directory:(directory pathName , '/' , entry) |
|
48 ] ifFalse:[ |
|
49 enterField contents:entry |
|
50 ] |
|
51 ] |
|
52 |
|
53 "FileSelectionBox new show" |
|
54 ! |
|
55 |
|
56 reinitialize |
|
57 directory := FileDirectory currentDirectory. |
|
58 super reinitialize |
|
59 ! ! |
|
60 |
|
61 !FileSelectionBox methodsFor:'accessing'! |
|
62 |
|
63 directory:nameOrDirectory |
|
64 "set the lists contents to the filenames in the directory name" |
|
65 |
|
66 |oldPath name| |
|
67 |
|
68 (nameOrDirectory isKindOf:String) ifTrue:[ |
|
69 name := nameOrDirectory |
|
70 ] ifFalse:[ |
|
71 name := nameOrDirectory pathName |
|
72 ]. |
|
73 oldPath := directory pathName. |
|
74 directory pathName:name. |
|
75 (directory pathName = oldPath) ifFalse:[ |
|
76 self updateList |
|
77 ] |
|
78 ! ! |
|
79 |
|
80 !FileSelectionBox methodsFor:'private'! |
|
81 |
|
82 updateList |
|
83 "set the lists contents to the filenames in the directory" |
|
84 |
|
85 |oldCursor oldListCursor files| |
|
86 |
|
87 oldCursor := cursor. |
|
88 oldListCursor := selectionList cursor. |
|
89 self cursor:(Cursor read). |
|
90 selectionList cursor:(Cursor read). |
|
91 timeStamp := directory timeOfLastChange. |
|
92 directoryId := directory id. |
|
93 files := directory asText sort. |
|
94 ((files at:1) = '.') ifTrue:[ |
|
95 files removeIndex:1 |
|
96 ]. |
|
97 self list:files. |
|
98 self cursor:oldCursor. |
|
99 selectionList cursor:oldListCursor |
|
100 ! ! |
|
101 |
|
102 !FileSelectionBox methodsFor:'events'! |
|
103 |
|
104 show |
|
105 "make the box visible; redefined to check if directory is still |
|
106 valid (using timestamp and inode numbers) - reread if not" |
|
107 |
|
108 (timeStamp isNil |
|
109 or:[(directory timeOfLastChange > timeStamp) |
|
110 or:[(directoryId isNil) |
|
111 or:[directoryId ~~ directory id]]]) ifTrue:[ |
|
112 self updateList |
|
113 ]. |
|
114 super show |
|
115 ! ! |
|
116 |
|
117 !FileSelectionBox methodsFor:'user interaction'! |
|
118 |
|
119 okPressed |
|
120 "redefined, since action will be evaluated with full path as argument |
|
121 (instead of enterfields contents only as inherited by EnterBox" |
|
122 |
|
123 self hideAndEvaluate:[:string | |
|
124 okAction notNil ifTrue:[ |
|
125 okAction value:(directory pathName , '/' , string) |
|
126 ] |
|
127 ] |
|
128 ! ! |