author | Claus Gittinger <cg@exept.de> |
Thu, 28 Aug 2003 17:40:52 +0200 | |
changeset 2560 | cc5ba9cf02b8 |
parent 2559 | f9f489baf23f |
child 2661 | f68913f2facf |
permissions | -rw-r--r-- |
2376 | 1 |
" |
2 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
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 |
"{ Package: 'stx:libwidg2' }" |
|
14 |
||
15 |
Object subclass:#DoWhatIMeanSupport |
|
16 |
instanceVariableNames:'' |
|
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'System-Support' |
|
20 |
! |
|
21 |
||
22 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 2002 by eXept Software AG |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
misc collected UI support (functional) |
|
41 |
||
42 |
||
43 |
[author:] |
|
44 |
Claus Gittinger (cg@exept.de) |
|
45 |
||
46 |
[instance variables:] |
|
47 |
||
48 |
[class variables:] |
|
49 |
||
50 |
[see also:] |
|
51 |
||
52 |
" |
|
53 |
! ! |
|
54 |
||
55 |
!DoWhatIMeanSupport class methodsFor:'rename support'! |
|
56 |
||
57 |
goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName |
|
2513 | 58 |
"generate a reasonable default for a rename operation. |
59 |
(used for rename category etc.)" |
|
2468 | 60 |
|
2559 | 61 |
|prefix suffix lastNewSize lastOldSize left right inserted deleted| |
2376 | 62 |
|
63 |
lastNewName isNil ifTrue:[ ^ nil]. |
|
64 |
||
65 |
lastNewSize := lastNewName size. |
|
66 |
lastOldSize := lastOldName size. |
|
67 |
||
68 |
(lastNewName endsWith:lastOldName) ifTrue:[ |
|
2514 | 69 |
"last rename was |
70 |
'foo' -> 'Xfoo' |
|
71 |
then, a good default for |
|
72 |
'bar' would be 'Xbar' |
|
73 |
" |
|
2376 | 74 |
prefix := lastNewName copyTo:(lastNewSize - lastOldSize). |
75 |
^ (prefix , oldName). |
|
76 |
]. |
|
77 |
(lastOldName endsWith:lastNewName) ifTrue:[ |
|
2514 | 78 |
"last rename was |
79 |
'Xfoo' -> 'foo' |
|
80 |
then, a good default for |
|
81 |
'Xbar' would be 'bar' |
|
82 |
" |
|
2376 | 83 |
prefix := lastOldName copyTo:(lastOldSize - lastNewSize). |
2514 | 84 |
(oldName startsWith:prefix) ifTrue:[ |
85 |
^ (oldName copyFrom:prefix size+1). |
|
86 |
] |
|
87 |
]. |
|
88 |
(lastOldName asLowercase = lastNewName asLowercase) ifTrue:[ |
|
89 |
(lastOldName first ~= lastNewName first) ifTrue:[ |
|
90 |
(lastOldName first isLowercase = oldName first isLowercase) ifTrue:[ |
|
91 |
"last rename was |
|
92 |
'xfoo' -> 'Xfoo' |
|
93 |
then, a good default for |
|
94 |
'xbar' would be 'Xbar' |
|
95 |
" |
|
96 |
lastOldName first isLowercase ifTrue:[ |
|
97 |
^ oldName first asUppercase asString , (oldName copyFrom:2). |
|
98 |
] ifFalse:[ |
|
99 |
^ oldName first asLowercase asString , (oldName copyFrom:2). |
|
100 |
] |
|
101 |
] |
|
102 |
]. |
|
2376 | 103 |
]. |
104 |
(lastOldName withoutSeparators = lastNewName) ifTrue:[ |
|
2514 | 105 |
"last rename was |
106 |
' foo ' -> 'foo' |
|
107 |
then, a good default for |
|
108 |
' bar ' would be 'bar' |
|
109 |
" |
|
2376 | 110 |
^ oldName withoutSeparators. |
111 |
]. |
|
112 |
(lastNewName startsWith:lastOldName) ifTrue:[ |
|
2557 | 113 |
"last rename was |
114 |
'foo' -> 'fooX' |
|
115 |
then, a good default for |
|
116 |
'bar' would be 'barX' |
|
117 |
" |
|
2376 | 118 |
suffix := lastNewName copyLast:(lastNewSize - lastOldSize). |
119 |
^ (oldName , suffix). |
|
120 |
]. |
|
121 |
(lastOldName startsWith:lastNewName) ifTrue:[ |
|
2557 | 122 |
"last rename was |
123 |
'fooX' -> 'foo' |
|
124 |
then, a good default for |
|
125 |
'barX' would be 'bar' |
|
126 |
" |
|
2376 | 127 |
suffix := lastOldName copyLast:(lastOldSize - lastNewSize). |
128 |
(oldName endsWith:suffix) ifTrue:[ |
|
129 |
^ (oldName copyWithoutLast:suffix size). |
|
130 |
] |
|
131 |
]. |
|
2558 | 132 |
|
2557 | 133 |
prefix := lastOldName commonPrefixWith:lastNewName. |
134 |
suffix := lastOldName commonSuffixWith:lastNewName. |
|
2559 | 135 |
|
2558 | 136 |
(prefix size > 0) ifTrue:[ |
137 |
(suffix size > 0) ifTrue:[ |
|
2559 | 138 |
|
139 |
prefix := prefix copyTo:(((lastNewName size - suffix size) min:(lastOldName size - suffix size)) min:prefix size). |
|
140 |
||
2558 | 141 |
"last rename was |
142 |
'fooR' -> 'fooXR' |
|
143 |
then, a good default for |
|
144 |
'barR' would be 'barXR' |
|
145 |
" |
|
146 |
left := lastOldName copyTo:prefix size. |
|
147 |
right := lastOldName copyLast:suffix size. |
|
2559 | 148 |
lastNewSize > lastOldSize ifTrue:[ |
149 |
inserted := (lastNewName copyFrom:(left size + 1)) copyWithoutLast:(right size). |
|
150 |
inserted size > 0 ifTrue:[ |
|
2560 | 151 |
^ (oldName copyTo:prefix size) , inserted , (oldName copyFrom:prefix size + 1) |
2559 | 152 |
]. |
153 |
]. |
|
154 |
(oldName endsWith:suffix) ifTrue:[ |
|
155 |
deleted := (lastOldName copyFrom:(prefix size + 1)) copyWithoutLast:(suffix size). |
|
156 |
((oldName copyFrom:oldName size-suffix size-deleted size + 1) copyTo:deleted size) = deleted ifTrue:[ |
|
157 |
"last rename was |
|
158 |
'fooXR' -> 'fooR' |
|
159 |
then, a good default for |
|
160 |
'barXS' would be 'barS' |
|
161 |
" |
|
162 |
^ (oldName copyTo:oldName size-suffix size-deleted size) , suffix |
|
163 |
] |
|
164 |
] |
|
2558 | 165 |
]. |
166 |
||
167 |
(oldName endsWith:(lastOldName copyFrom:prefix size+1)) ifTrue:[ |
|
168 |
"last rename was |
|
169 |
'fooX' -> 'fooY' |
|
170 |
then, a good default for |
|
171 |
'barX' would be 'barY' |
|
172 |
" |
|
173 |
left := oldName copyWithoutLast:(lastOldName copyFrom:prefix size+1) size. |
|
174 |
right := lastNewName copyFrom:prefix size+1. |
|
175 |
^ left , right |
|
176 |
] |
|
2557 | 177 |
]. |
2376 | 178 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
179 |
^ nil |
2557 | 180 |
|
181 |
" |
|
2558 | 182 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fooXX' |
183 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'XXfoo' |
|
184 |
||
185 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'foo' |
|
186 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
|
187 |
||
188 |
self goodRenameDefaultFor:'barXX' lastOld:'fooXX' lastNew:'fooYY' |
|
189 |
self goodRenameDefaultFor:'XXbar' lastOld:'XXfoo' lastNew:'foo' |
|
190 |
||
2559 | 191 |
self goodRenameDefaultFor:'bar2' lastOld:'foo1' lastNew:'foo01' |
192 |
self goodRenameDefaultFor:'barXY' lastOld:'fooXY' lastNew:'fooY' |
|
2560 | 193 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXoo' |
194 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'fXXXoo' |
|
2559 | 195 |
self goodRenameDefaultFor:'bar' lastOld:'foo' lastNew:'foXXXo' |
196 |
||
197 |
self goodRenameDefaultFor:'bar001' lastOld:'foo001' lastNew:'foo002_001' |
|
2560 | 198 |
self goodRenameDefaultFor:'CoastCore-CSFoo' lastOld:'CoastCore-CSBar' lastNew:'Coast-Core-CSBar' |
2557 | 199 |
" |
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
200 |
! |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
201 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
202 |
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName |
2513 | 203 |
"generate a reasonable default for a file rename operation. |
204 |
(Try to rename multiple files in the new fileBrowser, |
|
205 |
to see what this is doing)" |
|
2468 | 206 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
207 |
|prefix suffix t |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
208 |
lastOldWOSuffix lastNewWOSuffix oldWOSuffix lastOldRest oldRest lastNewRest |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
209 |
lastRemoved lastInserted default| |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
210 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
211 |
default := self goodRenameDefaultFor:oldName lastOld:lastOldName lastNew:lastNewName. |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
212 |
default notNil ifTrue:[ ^ default]. |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
213 |
|
2376 | 214 |
lastOldWOSuffix := lastOldName asFilename withoutSuffix name. |
215 |
lastNewWOSuffix := lastNewName asFilename withoutSuffix name. |
|
216 |
oldWOSuffix := oldName asFilename withoutSuffix name. |
|
217 |
||
2434 | 218 |
"/ suffix change ? |
219 |
lastOldWOSuffix = lastNewWOSuffix ifTrue:[ |
|
220 |
lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[ |
|
221 |
^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName |
|
222 |
]. |
|
223 |
]. |
|
224 |
||
2553 | 225 |
default := self goodRenameDefaultFor:oldWOSuffix lastOld:lastOldWOSuffix lastNew:lastNewWOSuffix. |
226 |
default notNil ifTrue:[ |
|
227 |
lastOldRest := lastOldName copyFrom:lastOldWOSuffix size + 1. |
|
228 |
lastNewRest := lastNewName copyFrom:lastNewWOSuffix size + 1. |
|
229 |
oldRest := oldName copyFrom:oldWOSuffix size + 1. |
|
230 |
||
231 |
^ default , lastNewRest |
|
232 |
]. |
|
233 |
||
2376 | 234 |
prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix. |
235 |
(lastNewWOSuffix startsWith:prefix) ifTrue:[ |
|
236 |
lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1. |
|
237 |
lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1. |
|
238 |
oldRest := oldWOSuffix copyFrom:prefix size + 1. |
|
239 |
||
240 |
(lastNewRest endsWith:lastOldRest) ifTrue:[ |
|
241 |
t := lastNewRest copyWithoutLast:lastOldRest size. |
|
242 |
^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name |
|
243 |
]. |
|
244 |
]. |
|
245 |
||
246 |
suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix. |
|
247 |
suffix size > 0 ifTrue:[ |
|
248 |
"/ last change changed something at the beginning |
|
249 |
prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix. |
|
250 |
prefix size > 0 ifTrue:[ |
|
251 |
"/ this name starts with the same characters |
|
252 |
lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size. |
|
253 |
lastInserted := lastNewWOSuffix copyWithoutLast:suffix size. |
|
254 |
(lastRemoved startsWith:lastInserted) ifTrue:[ |
|
255 |
oldWOSuffix size >= lastInserted size ifTrue:[ |
|
256 |
^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1) |
|
257 |
] |
|
258 |
]. |
|
259 |
^ lastInserted , (oldName copyFrom:lastRemoved size + 1) |
|
260 |
]. |
|
261 |
]. |
|
262 |
||
263 |
^ nil |
|
264 |
! ! |
|
265 |
||
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
266 |
!DoWhatIMeanSupport class methodsFor:'typing distance'! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
267 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
268 |
isKey:k1 nextTo:k2 |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
269 |
"return true, if k1 and k2 are adjacent keys on the keybaord. |
2516 | 270 |
CAVEAT: hard coded us-keyboard here." |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
271 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
272 |
|keys| |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
273 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
274 |
"/ for now: hardcoded US keyboard (should be language dependent) |
2516 | 275 |
"/ (i.e. ask userPreferences ...) |
276 |
||
2517 | 277 |
keys := #( |
278 |
'1234567890-' |
|
279 |
'*qwertyuiop' |
|
280 |
'**asdfghjkl:' |
|
281 |
'***zxcvbnm' ). |
|
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
282 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
283 |
^ self isKey:k1 nextTo:k2 onKeyboard:keys |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
284 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
285 |
" |
2517 | 286 |
self isKey:$a nextTo:$a |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
287 |
self isKey:$a nextTo:$s |
2517 | 288 |
self isKey:$a nextTo:$s |
289 |
self isKey:$a nextTo:$q |
|
290 |
self isKey:$a nextTo:$w |
|
291 |
self isKey:$a nextTo:$z |
|
292 |
self isKey:$a nextTo:$x |
|
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
293 |
" |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
294 |
! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
295 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
296 |
isKey:k1 nextTo:k2 onKeyboard:keys |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
297 |
"return true, if k1 and k2 are adjacent keys on the keybaord. |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
298 |
CAVEAT: hard coded us-keyboard here" |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
299 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
300 |
|row1 row2 col1 col2| |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
301 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
302 |
row1 := keys findFirst:[:row | row includes:k1]. |
2517 | 303 |
row1 == 0 ifTrue:[^ false]. |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
304 |
row2 := keys findFirst:[:row | row includes:k2]. |
2517 | 305 |
row2 == 0 ifTrue:[^ false]. |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
306 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
307 |
(row1-row2) abs <= 1 ifFalse:[^ false]. |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
308 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
309 |
col1 := (keys at:row1) indexOf:k1. |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
310 |
col2 := (keys at:row2) indexOf:k2. |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
311 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
312 |
^ (col1-col2) abs <= 1 |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
313 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
314 |
" |
2517 | 315 |
self isKey:$a nextTo:$x |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
316 |
" |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
317 |
! ! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
318 |
|
2376 | 319 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
320 |
||
321 |
version |
|
2560 | 322 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.14 2003-08-28 15:40:52 cg Exp $' |
2376 | 323 |
! ! |