1 "{ Package: 'stx:libtool2' }" |
|
2 |
|
3 FileOperations subclass:#Move |
|
4 instanceVariableNames:'colOfMovedFiles' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'Interface-Support' |
|
8 ! |
|
9 |
|
10 |
|
11 !Move class methodsFor:'actions'! |
|
12 |
|
13 moveFile:aSourceFile to:aDestFile |
|
14 "delete current selected files/directories |
|
15 " |
|
16 |
|
17 |instance| |
|
18 |
|
19 instance := self new. |
|
20 instance moveFile:aSourceFile to:aDestFile. |
|
21 ^ instance |
|
22 ! |
|
23 |
|
24 moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
25 "delete current selected files/directories |
|
26 " |
|
27 |
|
28 |instance| |
|
29 |
|
30 instance := self new. |
|
31 instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning. |
|
32 ^ instance |
|
33 ! |
|
34 |
|
35 moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
36 "delete current selected files/directories |
|
37 " |
|
38 |
|
39 |instance| |
|
40 |
|
41 instance := self new. |
|
42 instance moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move. |
|
43 ^ instance |
|
44 ! |
|
45 |
|
46 moveFiles:aColOfSourceFiles to:aDirectory |
|
47 "delete current selected files/directories |
|
48 " |
|
49 |
|
50 |instance| |
|
51 |
|
52 instance := self new. |
|
53 instance moveFiles:aColOfSourceFiles to:aDirectory. |
|
54 ^ instance |
|
55 ! |
|
56 |
|
57 moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
58 "delete current selected files/directories |
|
59 " |
|
60 |
|
61 |instance| |
|
62 |
|
63 instance := self new. |
|
64 instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning. |
|
65 ^ instance |
|
66 ! |
|
67 |
|
68 moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
69 "delete current selected files/directories |
|
70 " |
|
71 |
|
72 |instance| |
|
73 |
|
74 instance := self new. |
|
75 instance moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move. |
|
76 ^ instance |
|
77 ! ! |
|
78 |
|
79 !Move methodsFor:'accessing'! |
|
80 |
|
81 colOfMovedFiles |
|
82 "return the value of the instance variable 'colOfMovedFiles' (automatically generated)" |
|
83 |
|
84 colOfMovedFiles isNil ifTrue:[ |
|
85 colOfMovedFiles := OrderedCollection new. |
|
86 ]. |
|
87 ^ colOfMovedFiles |
|
88 ! ! |
|
89 |
|
90 !Move methodsFor:'actions'! |
|
91 |
|
92 moveFile:aSourceFile to:aDestFile |
|
93 |
|
94 ^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:true. |
|
95 ! |
|
96 |
|
97 moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning |
|
98 |
|
99 ^ self moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:true |
|
100 ! |
|
101 |
|
102 moveFile:aSourceFile to:aDestFile withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
103 |
|
104 |newFile fileString targetDirectory targetIsDirectory suffix| |
|
105 |
|
106 targetIsDirectory := aDestFile isDirectory. |
|
107 targetIsDirectory ifTrue:[ |
|
108 targetDirectory := aDestFile. |
|
109 newFile := aDestFile construct:(aSourceFile baseName). |
|
110 ] ifFalse:[ |
|
111 targetDirectory := aDestFile directory. |
|
112 newFile := aDestFile. |
|
113 ]. |
|
114 "/ do not copy if destination directory doest exist. |
|
115 (targetDirectory exists not) ifTrue:[ |
|
116 DialogBox warn:'cant move to not existing directory ', targetDirectory asString. |
|
117 result := false. |
|
118 ^ self |
|
119 ]. |
|
120 (newFile exists) ifTrue:[ |
|
121 ((newFile asString = aSourceFile asString) and:[move]) ifTrue:[ |
|
122 [newFile exists] whileTrue:[ |
|
123 suffix := newFile suffix. |
|
124 fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix. |
|
125 newFile := targetDirectory construct:fileString. |
|
126 ]. |
|
127 ] ifFalse:[ |
|
128 overWriteWarning ifTrue:[ |
|
129 (self fileExistDialogFor:newFile) ifFalse:[ |
|
130 result := false. |
|
131 ^ self. |
|
132 ] |
|
133 ] ifFalse:[ |
|
134 result := false. |
|
135 ^ self. |
|
136 ] |
|
137 ]. |
|
138 ]. |
|
139 Error handle:[:ex| |
|
140 "was not able to copy it" |
|
141 WarningBox warn:'on copy file - ', ex errorString. |
|
142 self errorString:('on copy file - ', ex description asString). |
|
143 result := false. |
|
144 ] do:[ |
|
145 aSourceFile moveTo:newFile. |
|
146 DirectoryContents flushCachedDirectory:(aSourceFile directory). |
|
147 result := true. |
|
148 ]. |
|
149 ! |
|
150 |
|
151 moveFiles:aColOfSourceFiles to:aDirectory |
|
152 |
|
153 ^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:true |
|
154 ! |
|
155 |
|
156 moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning |
|
157 |
|
158 ^ self moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:true |
|
159 ! |
|
160 |
|
161 moveFiles:aColOfSourceFiles to:aDirectory withOverWriteWarning:overWriteWarning moveFileIfSame:move |
|
162 |
|
163 |newFile suffix fileString askResult| |
|
164 |
|
165 (aDirectory exists not) ifTrue:[ |
|
166 DialogBox warn:'cant move to not existing directory ', aDirectory asString. |
|
167 result := false. |
|
168 ^ self |
|
169 ]. |
|
170 (aDirectory isDirectory not) ifTrue:[ |
|
171 DialogBox warn:'destination ', aDirectory asString, ' is not a directory'. |
|
172 result := false. |
|
173 ^ self |
|
174 ]. |
|
175 aColOfSourceFiles do:[: filename | |
|
176 newFile := aDirectory construct:filename baseName. |
|
177 (newFile exists) ifTrue:[ |
|
178 askResult := true. |
|
179 ((newFile asString = filename asString) and:[move]) ifTrue:[ |
|
180 [newFile exists] whileTrue:[ |
|
181 suffix := newFile suffix. |
|
182 fileString := newFile baseName withoutSuffix, self class copyMoveIfExistSuffixString, '.', suffix. |
|
183 newFile := aDirectory construct:fileString. |
|
184 ]. |
|
185 ] ifFalse:[ |
|
186 overWriteWarning ifTrue:[ |
|
187 askResult := (self fileExistDialogFor:newFile withCancel:true). |
|
188 askResult isNil ifTrue:[ |
|
189 result := false. |
|
190 ^ self. |
|
191 ] |
|
192 ] |
|
193 ]. |
|
194 ]. |
|
195 askResult ifTrue:[ |
|
196 Error handle:[:ex| |
|
197 "was not able to copy it" |
|
198 result := false. |
|
199 self errorString:('on move file - ', ex description asString). |
|
200 ( Dialog |
|
201 confirm:('error on move file - ', ex description asString) |
|
202 title:'Move' |
|
203 yesLabel:'Continue' |
|
204 noLabel:'Abort') ifFalse:[ |
|
205 ^ self. |
|
206 ]. |
|
207 ] do:[ |
|
208 filename moveTo:newFile. |
|
209 ]. |
|
210 self colOfMovedFiles add:filename |
|
211 ] |
|
212 ]. |
|
213 DirectoryContents flushCachedDirectory:aDirectory. |
|
214 result := true. |
|
215 ! ! |
|
216 |
|
217 !Move class methodsFor:'documentation'! |
|
218 |
|
219 version |
|
220 ^ '$Header$' |
|
221 ! ! |
|