SimpleView.st
changeset 4492 17759f9ff27d
parent 4484 97096c51797d
child 4494 5f811173a85b
equal deleted inserted replaced
4491:c011e738596f 4492:17759f9ff27d
  6385     self shortcutKey:(i at:1).
  6385     self shortcutKey:(i at:1).
  6386     ^ i at:2.
  6386     ^ i at:2.
  6387 !
  6387 !
  6388 
  6388 
  6389 mnemonicKey
  6389 mnemonicKey
  6390     "get the mnemonic key or nil if undefined
  6390     "get the mnemonic key or nil if undefined"
  6391     "
  6391     
  6392     ^ self objectAttributeAt:#mnemonicKey
  6392     ^ self objectAttributeAt:#mnemonicKey
  6393 !
  6393 !
  6394 
  6394 
  6395 mnemonicKey:aSymbolOrNil
  6395 mnemonicKey:aSymbolOrNil 
  6396     "set or clear the mnemonic key
  6396     "set or clear the mnemonic key"
  6397     "
  6397     
  6398     aSymbolOrNil isSymbol ifTrue:[
  6398     aSymbolOrNil isSymbol ifTrue:[
  6399 	self objectAttributeAt:#mnemonicKey put:aSymbolOrNil
  6399         self objectAttributeAt:#mnemonicKey put:aSymbolOrNil
  6400     ] ifFalse:[
  6400     ] ifFalse:[
  6401 	self removeObjectAttribute:#mnemonicKey
  6401         self removeObjectAttribute:#mnemonicKey
  6402     ].
  6402     ].
  6403 !
  6403 !
  6404 
  6404 
  6405 mnemonicViewNext:aKeyEvent
  6405 mnemonicViewNext:aKeyEvent 
  6406     "a  mnemonicKey event as forwarded from the keyboardProcessor - if there
  6406     "a  mnemonicKey event as forwarded from the keyboardProcessor - if there
  6407      is the mnemonic-key defined for a subView return the view otherwise nil.
  6407      is the mnemonic-key defined for a subView return the view otherwise nil."
  6408     "
  6408     
  6409     |key rawKey mnemonic view|
  6409     |key rawKey mnemonic view|
  6410 
  6410 
  6411     key    := aKeyEvent key.
  6411     key := aKeyEvent key.
  6412     rawKey := aKeyEvent rawKey.
  6412     rawKey := aKeyEvent rawKey.
  6413 
  6413     (shown and:[ subViews notNil ]) ifTrue:[
  6414     (shown and:[subViews notNil]) ifTrue:[
  6414         subViews do:[:aSubView | 
  6415 
  6415             aSubView shown ifTrue:[
  6416 	subViews do:[:aSubView|
  6416                 (aSubView enabled 
  6417 	    aSubView shown ifTrue:[
  6417                     and:[
  6418 		(     aSubView enabled
  6418                         (mnemonic := aSubView mnemonicKey) notNil 
  6419 		 and:[(mnemonic := aSubView mnemonicKey) notNil
  6419                             and:[ (mnemonic == rawKey or:[ mnemonic == key ]) ]
  6420 		 and:[(mnemonic == rawKey or:[mnemonic == key])]]
  6420                     ]) 
  6421 		) ifTrue:[
  6421                         ifTrue:[ ^ aSubView ].
  6422 		    ^ aSubView
  6422                 (view := aSubView mnemonicViewNext:aKeyEvent) notNil ifTrue:[
  6423 		].
  6423                     ^ view
  6424 
  6424                 ].
  6425 		(view := aSubView mnemonicViewNext:aKeyEvent) notNil ifTrue:[
  6425             ]
  6426 		    ^ view
  6426         ]
  6427 		].
       
  6428 	    ]
       
  6429 	]
       
  6430     ].
  6427     ].
  6431     ^ nil
  6428     ^ nil
  6432 !
  6429 !
  6433 
  6430 
  6434 performShortcutAction
  6431 performShortcutAction
  6435     "perform my shortcutKey action.
  6432     "perform my shortcutKey action.
  6436     "
  6433     "
  6437     "/ intentionally left blank here
  6434     "/ intentionally left blank here
  6438 !
  6435 !
  6439 
  6436 
  6440 processShortcut:aKeyEvent
  6437 processShortcut:aKeyEvent 
  6441     "a  shortcutKey event as forwarded from the keyboardProcessor - if there is the
  6438     "a  shortcutKey event as forwarded from the keyboardProcessor - if there is the
  6442      shortcut-key defined process the shortcut and return true otherwise false.
  6439      shortcut-key defined process the shortcut and return true otherwise false."
  6443     "
  6440     
  6444     |key|
  6441     |key|
  6445 
  6442 
  6446     shown ifTrue:[
  6443     shown ifTrue:[
  6447 	self enabled ifTrue:[
  6444         self enabled ifTrue:[
  6448 	    (key := self shortcutKey) notNil ifTrue:[
  6445             (key := self shortcutKey) notNil ifTrue:[
  6449 		(key == aKeyEvent key or:[key == aKeyEvent rawKey]) ifTrue:[
  6446                 (key == aKeyEvent key or:[ key == aKeyEvent rawKey ]) ifTrue:[
  6450 		    self requestFocus.
  6447                     self requestFocus.
  6451 		    (controller ? self) performShortcutAction.
  6448                     (controller ? self) performShortcutAction.
  6452 		    ^ true
  6449                     ^ true
  6453 		]
  6450                 ]
  6454 	    ].
  6451             ].
  6455 	].
  6452         ].
  6456 
  6453         subViews notNil ifTrue:[
  6457 	subViews notNil ifTrue:[
  6454             subViews do:[:aSubView | 
  6458 	    subViews do:[:aSubView|
  6455                 (aSubView processShortcut:aKeyEvent) ifTrue:[
  6459 		(aSubView processShortcut:aKeyEvent) ifTrue:[
  6456                     ^ true
  6460 		    ^ true
  6457                 ]
  6461 		]
  6458             ]
  6462 	    ]
  6459         ]
  6463 	]
       
  6464     ].
  6460     ].
  6465     ^ false
  6461     ^ false
  6466 !
  6462 !
  6467 
  6463 
  6468 shortcutAndTranslatedStringFrom:aString
  6464 shortcutAndTranslatedStringFrom:aString
  6516      Transcript showCR:(self basicNew shortcutAndTranslatedStringFrom:'hello &&'     ) last
  6512      Transcript showCR:(self basicNew shortcutAndTranslatedStringFrom:'hello &&'     ) last
  6517     "
  6513     "
  6518 !
  6514 !
  6519 
  6515 
  6520 shortcutKey
  6516 shortcutKey
  6521     "get the shortcut key
  6517     "get the shortcut key"
  6522     "
  6518     
  6523     ^ self objectAttributeAt:#shortcutKey
  6519     ^ self objectAttributeAt:#shortcutKey
  6524 !
  6520 !
  6525 
  6521 
  6526 shortcutKey:aSymbolOrNil
  6522 shortcutKey:aSymbolOrNil 
  6527     "set or clear the shortcut key
  6523     "set or clear the shortcut key"
  6528     "
  6524     
  6529     aSymbolOrNil isSymbol ifTrue:[
  6525     aSymbolOrNil notNil ifTrue:[
  6530 	self objectAttributeAt:#shortcutKey put:aSymbolOrNil
  6526         self objectAttributeAt:#shortcutKey put:aSymbolOrNil
  6531     ] ifFalse:[
  6527     ] ifFalse:[
  6532 	self removeObjectAttribute:#shortcutKey
  6528         self removeObjectAttribute:#shortcutKey
  6533     ].
  6529     ].
  6534 ! !
  6530 ! !
  6535 
  6531 
  6536 !SimpleView methodsFor:'menu handling'!
  6532 !SimpleView methodsFor:'menu handling'!
  6537 
  6533 
  9695 ! !
  9691 ! !
  9696 
  9692 
  9697 !SimpleView class methodsFor:'documentation'!
  9693 !SimpleView class methodsFor:'documentation'!
  9698 
  9694 
  9699 version
  9695 version
  9700     ^ '$Header: /cvs/stx/stx/libview/SimpleView.st,v 1.539 2006-02-15 21:01:54 cg Exp $'
  9696     ^ '$Header: /cvs/stx/stx/libview/SimpleView.st,v 1.540 2006-02-23 21:05:15 cg Exp $'
  9701 ! !
  9697 ! !
  9702 
  9698 
  9703 SimpleView initialize!
  9699 SimpleView initialize!