402 containing items row-wise (i.e. elements are themself arrays, consisting of |
402 containing items row-wise (i.e. elements are themself arrays, consisting of |
403 label [selector [accelerator]] |
403 label [selector [accelerator]] |
404 if resources are non-nil, labels are translated using the translations found there. |
404 if resources are non-nil, labels are translated using the translations found there. |
405 " |
405 " |
406 |
406 |
407 |n labels selectors accelerators| |
|
408 |
|
409 n := itemList size. |
|
410 labels := Array new:n. |
|
411 selectors := Array new:n. |
|
412 accelerators := Array new:n. |
|
413 itemList keysAndValuesDo:[:idx :item | |
|
414 |label selector accelerator| |
|
415 |
|
416 label := item at:1. |
|
417 selector := item at:2 ifAbsent:nil. |
|
418 accelerator := item at:3 ifAbsent:nil. |
|
419 |
|
420 labels at:idx put:label. |
|
421 selectors at:idx put:selector. |
|
422 accelerators at:idx put:accelerator. |
|
423 ]. |
|
424 resources notNil ifTrue:[ |
|
425 labels := resources array:labels |
|
426 ]. |
|
427 ^ self |
407 ^ self |
428 labels:labels |
408 itemList:itemList resources:resources receiver:nil for:nil |
429 selectors:selectors |
|
430 accelerators:accelerators |
|
431 |
409 |
432 "the sometimes more convenient: |
410 "the sometimes more convenient: |
433 |p| |
411 |p| |
434 |
412 |
435 p := PopUpMenu |
413 p := PopUpMenu |
439 ('baz' doBaz CtrlZ)) |
417 ('baz' doBaz CtrlZ)) |
440 resources:nil. |
418 resources:nil. |
441 p showAtPointer |
419 p showAtPointer |
442 |
420 |
443 does the same as: |
421 does the same as: |
|
422 |p| |
|
423 |
|
424 p := PopUpMenu |
|
425 labels:#('foo' '-' 'bar' 'baz') |
|
426 selectors:#(doFoo nil doBar doBaz) |
|
427 accelerators:#(CtrlF nil CtrlB CtrlZ). |
|
428 p showAtPointer |
|
429 " |
|
430 |
|
431 ! |
|
432 |
|
433 itemList:itemList resources:resources receiver:anObject for:aView |
|
434 "like labels:selectors:... messages, but expects a single collection, |
|
435 containing items row-wise (i.e. elements are themself arrays, consisting of |
|
436 label [selector [accelerator [arg]]] |
|
437 if resources are non-nil, labels are translated using the translations found there. |
|
438 " |
|
439 |
|
440 |n labels selectors accelerators args anyArg| |
|
441 |
|
442 n := itemList size. |
|
443 labels := Array new:n. |
|
444 selectors := Array new:n. |
|
445 accelerators := Array new:n. |
|
446 anyArg := false. |
|
447 |
|
448 itemList keysAndValuesDo:[:idx :item | |
|
449 |label selector accelerator arg| |
|
450 |
|
451 label := item at:1. |
|
452 labels at:idx put:label. |
|
453 item size > 1 ifTrue:[ |
|
454 selector := item at:2. |
|
455 selectors at:idx put:selector. |
|
456 item size > 2 ifTrue:[ |
|
457 accelerator := item at:3. |
|
458 accelerators at:idx put:accelerator. |
|
459 item size > 3 ifTrue:[ |
|
460 arg := item at:4. |
|
461 anyArg ifFalse:[ |
|
462 anyArg := true. |
|
463 args := Array new:n. |
|
464 ]. |
|
465 args at:idx put:arg. |
|
466 ] |
|
467 ] |
|
468 ]. |
|
469 ]. |
|
470 |
|
471 resources notNil ifTrue:[ |
|
472 labels := resources array:labels |
|
473 ]. |
|
474 |
|
475 ^ self |
|
476 labels:labels |
|
477 selectors:selectors |
|
478 accelerators:accelerators |
|
479 args:args |
|
480 receiver:anObject |
|
481 for:aView |
|
482 |
|
483 "this is sometimes more convenient: |
|
484 |p| |
|
485 |
|
486 p := PopUpMenu |
|
487 itemList:#(('foo' doFoo CtrlF) |
|
488 ('-') |
|
489 ('bar' doBar CtrlB) |
|
490 ('baz' doBaz CtrlZ)) |
|
491 resources:nil. |
|
492 p showAtPointer |
|
493 |
|
494 and does the same as: |
444 |p| |
495 |p| |
445 |
496 |
446 p := PopUpMenu |
497 p := PopUpMenu |
447 labels:#('foo' '-' 'bar' 'baz') |
498 labels:#('foo' '-' 'bar' 'baz') |
448 selectors:#(doFoo nil doBar doBaz) |
499 selectors:#(doFoo nil doBar doBaz) |