EnterBox2.st
changeset 197 00927189c882
parent 174 d80a6cc3f9b2
child 355 a55f62047156
equal deleted inserted replaced
196:7e3c25063173 197:00927189c882
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 EnterBox subclass:#EnterBox2
    13 EnterBox subclass:#EnterBox2
    14        instanceVariableNames:'okButton2 okAction2'
    14 	 instanceVariableNames:'okButton2 okAction2'
    15        classVariableNames:''
    15 	 classVariableNames:''
    16        poolDictionaries:''
    16 	 poolDictionaries:''
    17        category:'Views-DialogBoxes'
    17 	 category:'Views-DialogBoxes'
    18 !
    18 !
       
    19 
       
    20 !EnterBox2 class methodsFor:'instance creation'!
       
    21 
       
    22 title:titleString okText1:text1 okText2:text2 abortText:abortText
       
    23 		  action1:block1 action2:block2
       
    24     "create and return a new EnterBox-with-2 buttons
       
    25      and define its text, button-labels and actions"
       
    26 
       
    27     ^ (super title:titleString 
       
    28 	    okText:text1 
       
    29 	 abortText:abortText
       
    30 	    action:block1) okText2:text2 action2:block2
       
    31 ! !
    19 
    32 
    20 !EnterBox2 class methodsFor:'documentation '!
    33 !EnterBox2 class methodsFor:'documentation '!
    21 
    34 
    22 copyright
    35 copyright
    23 "
    36 "
    31  other person.  No title to or ownership of the software is
    44  other person.  No title to or ownership of the software is
    32  hereby transferred.
    45  hereby transferred.
    33 "
    46 "
    34 !
    47 !
    35 
    48 
    36 version
       
    37     ^ '$Header: /cvs/stx/stx/libwidg/EnterBox2.st,v 1.12 1995-11-11 16:20:13 cg Exp $'
       
    38 !
       
    39 
       
    40 documentation
    49 documentation
    41 "
    50 "
    42     An EnterBox2 is like an EnterBox but with 2 action buttons.
    51     An EnterBox2 is like an EnterBox but with 2 action buttons.
    43     This is used (for example) in the search-boxes, where two ok-buttons
    52     This is used (for example) in the search-boxes, where two ok-buttons
    44     'find-previous' and 'find-next' are needed in addition to the abort button.
    53     'find-previous' and 'find-next' are needed in addition to the abort button.
    45     The protocol is like that of EnterBox, the additional buttons label
    54     The protocol is like that of EnterBox, the additional buttons label
    46     can be set with 'okText2:aString' and its action with 'action2:aBlock'.
    55     can be set with 'okText2:aString' and its action with 'action2:aBlock'.
    47 "
    56 "
       
    57 !
       
    58 
       
    59 version
       
    60     ^ '$Header: /cvs/stx/stx/libwidg/EnterBox2.st,v 1.13 1995-11-23 02:25:05 cg Exp $'
    48 ! !
    61 ! !
    49 
    62 
    50 !EnterBox2 class methodsFor:'instance creation'!
    63 !EnterBox2 methodsFor:'accessing'!
    51 
    64 
    52 title:titleString okText1:text1 okText2:text2 abortText:abortText
    65 action2:aBlock
    53 		  action1:block1 action2:block2
    66     "set the action to be performed when user presses the 2nd ok-button;
    54     "create and return a new EnterBox-with-2 buttons
    67      aBlock must be nil or a block with one argument "
    55      and define its text, button-labels and actions"
       
    56 
    68 
    57     ^ (super title:titleString 
    69     okAction2 := aBlock
    58 	    okText:text1 
    70 !
    59 	 abortText:abortText
    71 
    60 	    action:block1) okText2:text2 action2:block2
    72 okText2:aString
       
    73     "set the text to be displayed in the 2nd ok-button"
       
    74 
       
    75     aString ~= okButton2 label ifTrue:[
       
    76 	okButton2 label:aString.
       
    77 	okButton2 resize.
       
    78 	shown ifTrue:[self resize]
       
    79     ]
       
    80 !
       
    81 
       
    82 okText2:aString action2:aBlock
       
    83     "set the text to be displayed in the 2nd ok-button,
       
    84      and its action"
       
    85 
       
    86     self okText2:aString.
       
    87     okAction2 := aBlock
    61 ! !
    88 ! !
    62 
    89 
    63 !EnterBox2 methodsFor:'initialization'!
    90 !EnterBox2 methodsFor:'initialization'!
       
    91 
       
    92 focusSequence
       
    93     ^ Array with:enterField with:abortButton with:okButton with:okButton2 
       
    94 !
    64 
    95 
    65 initialize
    96 initialize
    66     super initialize.
    97     super initialize.
    67 
    98 
    68     "
    99     "
    75      the old (see superclass) ok-button is no longer a return-button
   106      the old (see superclass) ok-button is no longer a return-button
    76     "
   107     "
    77     okButton isReturnButton:false.
   108     okButton isReturnButton:false.
    78 
   109 
    79     enterField leaveAction:[:key | self ok2Pressed]
   110     enterField leaveAction:[:key | self ok2Pressed]
    80 !
       
    81 
       
    82 focusSequence
       
    83     ^ Array with:enterField with:abortButton with:okButton with:okButton2 
       
    84 ! !
   111 ! !
    85 
   112 
    86 !EnterBox2 methodsFor:'realization'!
   113 !EnterBox2 methodsFor:'realization'!
    87 
   114 
    88 positionOffset
   115 positionOffset
    92 
   119 
    93     buttonPanel setChildPositionsIfChanged.
   120     buttonPanel setChildPositionsIfChanged.
    94     ^ (okButton2 originRelativeTo:self) + (okButton2 extent // 2)
   121     ^ (okButton2 originRelativeTo:self) + (okButton2 extent // 2)
    95 ! !
   122 ! !
    96 
   123 
    97 !EnterBox2 methodsFor:'accessing'!
       
    98 
       
    99 okText2:aString action2:aBlock
       
   100     "set the text to be displayed in the 2nd ok-button,
       
   101      and its action"
       
   102 
       
   103     self okText2:aString.
       
   104     okAction2 := aBlock
       
   105 !
       
   106 
       
   107 okText2:aString
       
   108     "set the text to be displayed in the 2nd ok-button"
       
   109 
       
   110     aString ~= okButton2 label ifTrue:[
       
   111 	okButton2 label:aString.
       
   112 	okButton2 resize.
       
   113 	shown ifTrue:[self resize]
       
   114     ]
       
   115 !
       
   116 
       
   117 action2:aBlock
       
   118     "set the action to be performed when user presses the 2nd ok-button;
       
   119      aBlock must be nil or a block with one argument "
       
   120 
       
   121     okAction2 := aBlock
       
   122 ! !
       
   123 
       
   124 !EnterBox2 methodsFor:'user interaction'!
   124 !EnterBox2 methodsFor:'user interaction'!
   125 
       
   126 ok2Pressed
       
   127     "user pressed 2nd ok button - evaluate action"
       
   128 
       
   129     okButton2 turnOffWithoutRedraw.
       
   130     self hideAndEvaluate:okAction2
       
   131 !
       
   132 
   125 
   133 keyPress:aKey x:x y:y
   126 keyPress:aKey x:x y:y
   134     "return-key dublicates ok-function if acceptReturnAsOK is true"
   127     "return-key dublicates ok-function if acceptReturnAsOK is true"
   135 
   128 
   136     acceptReturnAsOK ifTrue:[
   129     acceptReturnAsOK ifTrue:[
   137 	(aKey == #Return) ifTrue:[^ self ok2Pressed]
   130 	(aKey == #Return) ifTrue:[^ self ok2Pressed]
   138     ].
   131     ].
   139     super keyPress:aKey x:x y:y
   132     super keyPress:aKey x:x y:y
       
   133 !
       
   134 
       
   135 ok2Pressed
       
   136     "user pressed 2nd ok button - evaluate action"
       
   137 
       
   138     okButton2 turnOffWithoutRedraw.
       
   139     self hideAndEvaluate:okAction2
   140 ! !
   140 ! !
       
   141