accessCharacter for LabelAndIcon support
authorca
Fri, 04 Feb 2000 11:08:39 +0100
changeset 1677 f5a30ef6a195
parent 1676 d01663a2356d
child 1678 db691e5dba83
accessCharacter for LabelAndIcon support
NoteBookView.st
--- a/NoteBookView.st	Thu Feb 03 19:45:12 2000 +0100
+++ b/NoteBookView.st	Fri Feb 04 11:08:39 2000 +0100
@@ -725,6 +725,10 @@
     ]
 !
 
+processShortcutKeyEvent:event
+    ^ self processShortcutKey:(event key)
+!
+
 sizeChanged:how
     "size of view changed 
     "
@@ -1399,50 +1403,21 @@
 label:aLabel on:aGC
     "initialize attributes
     "
-    |i string size rest ipos|
-
-    label := aLabel.
-    model := (aLabel isKindOf:TabItem) ifTrue:[aLabel] ifFalse:[nil].
+    label           := aLabel.
+    model           := (aLabel isKindOf:TabItem) ifTrue:[aLabel] ifFalse:[nil].
     accessCharacter := nil.
-
-    printableLabel := model notNil ifTrue:[model rawLabel]
-                                  ifFalse:[aLabel].
+    printableLabel  := model notNil ifTrue:[model rawLabel] ifFalse:[aLabel].
 
     printableLabel notNil ifTrue:[
         printableLabel isImageOrForm ifTrue:[
             printableLabel := printableLabel onDevice:(aGC device)
         ] ifFalse:[
             printableLabel isString ifTrue:[
-                ipos := 0.
-                size := printableLabel size.
-
-                size > 1 ifTrue:[
-                    model notNil ifTrue:[
-                        ipos := model accessCharacterPosition.
-                        ipos > size ifTrue:[ipos := 0].
-                    ].
-                    i := 1.
-
-                    [((i := printableLabel indexOf:$& startingAt:i) ~~ 0 
-                    and:[i < size])] whileTrue:[
-                        rest := printableLabel copyFrom:(i+1).
-
-                        i == 1 ifTrue:[printableLabel := rest]
-                              ifFalse:[printableLabel := (printableLabel copyFrom:1 to:(i-1)), rest].
-
-                        (printableLabel at:i) == $& ifTrue:[i := i + 1]
-                                                   ifFalse:[ipos := i].
-                        size := size - 1.
-                    ].
-                    ipos ~~ 0 ifTrue:[
-                        printableLabel isText ifFalse:[
-                            printableLabel := Text string:printableLabel
-                        ].
-                        printableLabel emphasisAt:ipos add:#underline.
-                    ]
-                ].
-                accessCharacter := printableLabel at:(ipos max:1) ifAbsent:nil.
-                accessCharacter := accessCharacter asLowercase.
+                printableLabel := self resolveDisplayStringFor:printableLabel
+            ] ifFalse:[
+                printableLabel class == LabelAndIcon ifTrue:[
+                    printableLabel string:(self resolveDisplayStringFor:(printableLabel string))
+                ]
             ].
         ]
     ] ifFalse:[
@@ -1801,6 +1776,49 @@
 
 ! !
 
+!NoteBookView::Tab methodsFor:'private'!
+
+resolveDisplayStringFor:aString
+    |string size rest pos idx|
+
+    size   := aString size.
+    string := aString.
+    pos    := 0.
+
+    size > 1 ifTrue:[
+        (model notNil and:[(pos := model accessCharacterPosition) ~~ 0]) ifTrue:[
+            pos > size ifTrue:[pos := 0]
+        ] ifFalse:[
+            idx := 1.
+
+            [((idx := string indexOf:$& startingAt:idx) ~~ 0 and:[idx < size])] whileTrue:[
+                rest := string copyFrom:(idx+1).
+
+                idx == 1 ifTrue:[string := rest]
+                        ifFalse:[string := (string copyFrom:1 to:(idx-1)), rest].
+
+                (string at:idx) == $& ifTrue:[idx := idx + 1]
+                                     ifFalse:[pos := idx].
+                size := size - 1.
+            ]
+        ]
+    ].
+    size ~~ 0 ifTrue:[
+        pos == 0 ifTrue:[
+            pos := 1
+        ] ifFalse:[
+            string isText ifFalse:[
+                string := Text string:string
+            ].
+            string emphasisAt:pos add:#underline
+        ].
+        accessCharacter := (string at:pos) asLowercase
+    ] ifFalse:[
+        accessCharacter := nil
+    ].
+    ^ string
+! !
+
 !NoteBookView::Tab methodsFor:'testing'!
 
 containsPointX:x y:y
@@ -1833,5 +1851,5 @@
 !NoteBookView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.27 2000-02-03 09:38:28 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.28 2000-02-04 10:08:39 ca Exp $'
 ! !