304 Transcript showCr:'value2: ' , value2. |
304 Transcript showCr:'value2: ' , value2. |
305 Transcript showCr:'value3: ' , value3. |
305 Transcript showCr:'value3: ' , value3. |
306 " |
306 " |
307 ! ! |
307 ! ! |
308 |
308 |
309 !EnterFieldGroup class methodsFor:'instance creation'! |
|
310 |
|
311 new |
|
312 ^ self basicNew wrap:false |
|
313 ! ! |
|
314 |
|
315 !EnterFieldGroup methodsFor:'accessing'! |
309 !EnterFieldGroup methodsFor:'accessing'! |
|
310 |
|
311 fields |
|
312 "return a collection of the inputFields contained in the group." |
|
313 |
|
314 ^ fields |
|
315 ! |
316 |
316 |
317 leaveAction:aBlock |
317 leaveAction:aBlock |
318 "set the action to perform when the last field is left. |
318 "set the action to perform when the last field is left. |
319 Usually, this is to accept the values of all fields and perform |
319 Usually, this is to accept the values of all fields and perform |
320 some additional processing (such as closing a dialog)." |
320 some additional processing (such as closing a dialog)." |
321 |
321 |
322 leaveAction := aBlock |
322 leaveAction := aBlock |
323 ! |
323 ! |
324 |
324 |
325 wrap:aBoolean |
325 wrap:aBoolean |
326 "specifies if leaveing the last field via non-Return |
326 "specifies if leaving the last field via non-Return |
327 should wrap back to the first, or leave the group" |
327 should wrap back to the first, or leave the group. |
|
328 The default is to stay in the input sequence and wrap back to |
|
329 the first field." |
328 |
330 |
329 wrap := aBoolean |
331 wrap := aBoolean |
330 ! ! |
332 ! ! |
331 |
333 |
332 !EnterFieldGroup methodsFor:'adding / removing'! |
334 !EnterFieldGroup methodsFor:'adding / removing'! |
333 |
335 |
334 add:aField |
336 add:aField |
335 |thisIndex next action| |
337 |thisIndex next action| |
336 |
338 |
337 fields isNil ifTrue:[ |
339 fields isNil ifTrue:[ |
338 fields := OrderedCollection new |
340 fields := OrderedCollection new |
339 ]. |
341 ]. |
340 fields add:aField. |
342 fields add:aField. |
341 thisIndex := fields size. |
343 thisIndex := fields size. |
342 |
344 |
343 aField delegate:self. |
345 aField delegate:self. |
350 "/ Transcript showCr:'enable field with: ' , aField editValue. |
352 "/ Transcript showCr:'enable field with: ' , aField editValue. |
351 "/ currentField notNil ifTrue:[ |
353 "/ currentField notNil ifTrue:[ |
352 "/ currentField disable |
354 "/ currentField disable |
353 "/ ]. |
355 "/ ]. |
354 "/ currentField := aField |
356 "/ currentField := aField |
355 self makeActive:aField |
357 self makeActive:aField |
356 ]. |
358 ]. |
357 |
359 |
358 "set the fields leaveAction to enable next field" |
360 "set the fields leaveAction to enable next field" |
359 |
361 |
360 aField leaveAction:[:key | |
362 aField leaveAction:[:key | |
361 "/ Transcript showCr:'left field with: ' , aField editValue. |
363 "/ Transcript showCr:'left field with: ' , aField editValue. |
362 currentField notNil ifTrue:[ |
364 currentField notNil ifTrue:[ |
363 currentField disable. |
365 currentField disable. |
364 currentField hideCursor. |
366 currentField hideCursor. |
365 ]. |
367 ]. |
366 |
368 |
367 action := key. |
369 action := key. |
368 ((key == #CursorUp) or:[key == #PreviousField]) ifTrue:[ |
370 ((key == #CursorUp) or:[key == #PreviousField]) ifTrue:[ |
369 (thisIndex == 1) ifTrue:[ |
371 (thisIndex == 1) ifTrue:[ |
370 next := fields size |
372 next := fields size |
371 ] ifFalse:[ |
373 ] ifFalse:[ |
372 next := thisIndex - 1 |
374 next := thisIndex - 1 |
373 ] |
375 ] |
374 ]. |
376 ]. |
375 ((key == #CursorDown) |
377 ((key == #CursorDown) |
376 or:[key == #NextField |
378 or:[key == #NextField |
377 or:[key == #Tab]]) ifTrue:[ |
379 or:[key == #Tab]]) ifTrue:[ |
378 (thisIndex == (fields size)) ifTrue:[ |
380 (thisIndex == (fields size)) ifTrue:[ |
379 wrap ifFalse:[ |
381 next := 1. |
380 action := #Return. |
382 wrap == false ifTrue:[ |
381 ] ifTrue:[ |
383 action := #Return. |
382 next := 1 |
384 ]. |
383 ]. |
385 ] ifFalse:[ |
384 ] ifFalse:[ |
386 next := thisIndex + 1 |
385 next := thisIndex + 1 |
387 ] |
386 ] |
388 ]. |
387 ]. |
389 (action == #Return) ifTrue:[ |
388 (action == #Return) ifTrue:[ |
390 (thisIndex == (fields size)) ifTrue:[ |
389 (thisIndex == (fields size)) ifTrue:[ |
391 leaveAction notNil ifTrue:[ |
390 leaveAction notNil ifTrue:[ |
392 currentField := nil. |
391 leaveAction value. |
393 leaveAction value. |
392 currentField := nil |
394 next := nil |
393 ] ifFalse:[ |
395 ] ifFalse:[ |
394 next := 1 |
396 next := 1 |
395 ] |
397 ] |
396 ] ifFalse:[ |
398 ] ifFalse:[ |
397 next := thisIndex + 1 |
399 next := thisIndex + 1 |
398 ] |
400 ] |
399 ]. |
401 ]. |
400 next notNil ifTrue:[ |
402 next notNil ifTrue:[ |
401 self makeActive:(fields at:next) |
403 self makeActive:(fields at:next) |
402 ] |
404 ] |
403 ]. |
405 ]. |
404 |
406 |
405 fields size == 1 ifTrue:[ |
407 fields size == 1 ifTrue:[ |
406 "the first one" |
408 "the first one" |
407 self makeActive:aField |
409 self makeActive:aField |
408 ] |
410 ] |
409 ! ! |
411 ! ! |
410 |
412 |
411 !EnterFieldGroup methodsFor:'event forwarding'! |
413 !EnterFieldGroup methodsFor:'event forwarding'! |
412 |
414 |
456 "key-press in any field - forward the key to the active field |
458 "key-press in any field - forward the key to the active field |
457 (with -1/-1 as coordinate to indicate that the key was pressed |
459 (with -1/-1 as coordinate to indicate that the key was pressed |
458 outside. However, this info is not used by any view currently)" |
460 outside. However, this info is not used by any view currently)" |
459 |
461 |
460 currentField notNil ifTrue:[ |
462 currentField notNil ifTrue:[ |
461 currentField keyPress:key x:-1 y:-1 |
463 currentField keyPress:key x:-1 y:-1 |
462 ] |
464 ] |
463 ! |
465 ! |
464 |
466 |
465 keyRelease:key x:x y:y view:aView |
467 keyRelease:key x:x y:y view:aView |
466 "key-release in any field - forward the key to the active field. |
468 "key-release in any field - forward the key to the active field. |