author | Claus Gittinger <cg@exept.de> |
Fri, 23 May 2003 12:10:18 +0200 | |
changeset 2517 | a5323c17b767 |
parent 2516 | 9f022f76308d |
child 2553 | 9925f0aca022 |
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 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
61 |
|prefix suffix lastNewSize lastOldSize| |
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:[ |
|
113 |
suffix := lastNewName copyLast:(lastNewSize - lastOldSize). |
|
114 |
^ (oldName , suffix). |
|
115 |
]. |
|
116 |
(lastOldName startsWith:lastNewName) ifTrue:[ |
|
117 |
suffix := lastOldName copyLast:(lastOldSize - lastNewSize). |
|
118 |
(oldName endsWith:suffix) ifTrue:[ |
|
119 |
^ (oldName copyWithoutLast:suffix size). |
|
120 |
] |
|
121 |
]. |
|
122 |
||
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
123 |
^ nil |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
124 |
! |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
125 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
126 |
goodRenameDefaultForFile:oldName lastOld:lastOldName lastNew:lastNewName |
2513 | 127 |
"generate a reasonable default for a file rename operation. |
128 |
(Try to rename multiple files in the new fileBrowser, |
|
129 |
to see what this is doing)" |
|
2468 | 130 |
|
2382
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
131 |
|prefix suffix t |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
132 |
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
|
133 |
lastRemoved lastInserted default| |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
134 |
|
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
135 |
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
|
136 |
default notNil ifTrue:[ ^ default]. |
d89d86edaae4
separated default for arbitrary renames and deault for files.
Claus Gittinger <cg@exept.de>
parents:
2376
diff
changeset
|
137 |
|
2376 | 138 |
lastOldWOSuffix := lastOldName asFilename withoutSuffix name. |
139 |
lastNewWOSuffix := lastNewName asFilename withoutSuffix name. |
|
140 |
oldWOSuffix := oldName asFilename withoutSuffix name. |
|
141 |
||
2434 | 142 |
"/ suffix change ? |
143 |
lastOldWOSuffix = lastNewWOSuffix ifTrue:[ |
|
144 |
lastOldName asFilename suffix ~= lastNewName asFilename suffix ifTrue:[ |
|
145 |
^ (oldName asFilename withSuffix:(lastNewName asFilename suffix)) pathName |
|
146 |
]. |
|
147 |
]. |
|
148 |
||
2376 | 149 |
prefix := lastOldWOSuffix commonPrefixWith:oldWOSuffix. |
150 |
(lastNewWOSuffix startsWith:prefix) ifTrue:[ |
|
151 |
lastOldRest := lastOldWOSuffix copyFrom:prefix size + 1. |
|
152 |
lastNewRest := lastNewWOSuffix copyFrom:prefix size + 1. |
|
153 |
oldRest := oldWOSuffix copyFrom:prefix size + 1. |
|
154 |
||
155 |
(lastNewRest endsWith:lastOldRest) ifTrue:[ |
|
156 |
t := lastNewRest copyWithoutLast:lastOldRest size. |
|
157 |
^ ((prefix , t , oldRest) asFilename withSuffix:oldName asFilename suffix) name |
|
158 |
]. |
|
159 |
]. |
|
160 |
||
161 |
suffix := lastOldWOSuffix commonSuffixWith:lastNewWOSuffix. |
|
162 |
suffix size > 0 ifTrue:[ |
|
163 |
"/ last change changed something at the beginning |
|
164 |
prefix := oldWOSuffix commonPrefixWith:lastOldWOSuffix. |
|
165 |
prefix size > 0 ifTrue:[ |
|
166 |
"/ this name starts with the same characters |
|
167 |
lastRemoved := lastOldWOSuffix copyWithoutLast:suffix size. |
|
168 |
lastInserted := lastNewWOSuffix copyWithoutLast:suffix size. |
|
169 |
(lastRemoved startsWith:lastInserted) ifTrue:[ |
|
170 |
oldWOSuffix size >= lastInserted size ifTrue:[ |
|
171 |
^ (oldWOSuffix copyTo:lastInserted size) , (oldName copyFrom:lastRemoved size + 1) |
|
172 |
] |
|
173 |
]. |
|
174 |
^ lastInserted , (oldName copyFrom:lastRemoved size + 1) |
|
175 |
]. |
|
176 |
]. |
|
177 |
||
178 |
^ nil |
|
179 |
! ! |
|
180 |
||
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
181 |
!DoWhatIMeanSupport class methodsFor:'typing distance'! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
182 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
183 |
isKey:k1 nextTo:k2 |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
184 |
"return true, if k1 and k2 are adjacent keys on the keybaord. |
2516 | 185 |
CAVEAT: hard coded us-keyboard here." |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
186 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
187 |
|keys| |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
188 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
189 |
"/ for now: hardcoded US keyboard (should be language dependent) |
2516 | 190 |
"/ (i.e. ask userPreferences ...) |
191 |
||
2517 | 192 |
keys := #( |
193 |
'1234567890-' |
|
194 |
'*qwertyuiop' |
|
195 |
'**asdfghjkl:' |
|
196 |
'***zxcvbnm' ). |
|
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
197 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
198 |
^ self isKey:k1 nextTo:k2 onKeyboard:keys |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
199 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
200 |
" |
2517 | 201 |
self isKey:$a nextTo:$a |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
202 |
self isKey:$a nextTo:$s |
2517 | 203 |
self isKey:$a nextTo:$s |
204 |
self isKey:$a nextTo:$q |
|
205 |
self isKey:$a nextTo:$w |
|
206 |
self isKey:$a nextTo:$z |
|
207 |
self isKey:$a nextTo:$x |
|
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
208 |
" |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
209 |
! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
210 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
211 |
isKey:k1 nextTo:k2 onKeyboard:keys |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
212 |
"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
|
213 |
CAVEAT: hard coded us-keyboard here" |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
214 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
215 |
|row1 row2 col1 col2| |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
216 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
217 |
row1 := keys findFirst:[:row | row includes:k1]. |
2517 | 218 |
row1 == 0 ifTrue:[^ false]. |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
219 |
row2 := keys findFirst:[:row | row includes:k2]. |
2517 | 220 |
row2 == 0 ifTrue:[^ false]. |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
221 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
222 |
(row1-row2) abs <= 1 ifFalse:[^ false]. |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
223 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
224 |
col1 := (keys at:row1) indexOf:k1. |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
225 |
col2 := (keys at:row2) indexOf:k2. |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
226 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
227 |
^ (col1-col2) abs <= 1 |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
228 |
|
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
229 |
" |
2517 | 230 |
self isKey:$a nextTo:$x |
2515
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
231 |
" |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
232 |
! ! |
69cbb89c127e
+isKey:nextTo: for simple typo detection
Claus Gittinger <cg@exept.de>
parents:
2514
diff
changeset
|
233 |
|
2376 | 234 |
!DoWhatIMeanSupport class methodsFor:'documentation'! |
235 |
||
236 |
version |
|
2517 | 237 |
^ '$Header: /cvs/stx/stx/libwidg2/DoWhatIMeanSupport.st,v 1.9 2003-05-23 10:10:18 cg Exp $' |
2376 | 238 |
! ! |