UserConfirmation.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 31 Oct 2011 22:19:21 +0000
branchjv
changeset 17892 d86c8bd5ece3
parent 17869 9610c6c94e71
child 17910 8d796ca8bd1d
permissions -rw-r--r--
Merged with CVS
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10845
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     1
"
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     2
 COPYRIGHT (c) 2007 by eXept Software AG
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     3
              All Rights Reserved
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     4
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     5
 This software is furnished under a license and may be used
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     6
 only in accordance with the terms of that license and with the
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     8
 be provided or otherwise made available to, or used by, any
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
     9
 other person.  No title to or ownership of the software is
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    10
 hereby transferred.
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    11
"
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic' }"
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    13
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    14
UserNotification subclass:#UserConfirmation
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
    15
	instanceVariableNames:'canCancel defaultAnswerInDialog defaultAnswer'
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
11196
3e4114139cc9 category
Claus Gittinger <cg@exept.de>
parents: 10845
diff changeset
    18
	category:'Kernel-Exceptions-Notifications'
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    19
!
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    20
10845
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    21
!UserConfirmation class methodsFor:'documentation'!
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    22
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    23
copyright
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    24
"
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    25
 COPYRIGHT (c) 2007 by eXept Software AG
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    26
              All Rights Reserved
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    27
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    28
 This software is furnished under a license and may be used
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    29
 only in accordance with the terms of that license and with the
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    31
 be provided or otherwise made available to, or used by, any
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    32
 other person.  No title to or ownership of the software is
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    33
 hereby transferred.
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    34
"
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    35
!
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    36
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    37
documentation
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    38
"
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    39
    This confirmation query is used when a user confirmation is required
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    40
    somewhere within a model's operation (i.e. in non-GUI code).
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    41
    Instead of directly asking via Dialog confirm... messages,
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    42
    this should be raised. 
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    43
    Its default behavior is the same as the above dialog.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    44
    However, the query can be cought and answered by an exceoptn (a query-) handler,
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    45
    to suppress these GUI interactions in situations, where they are not wanted.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    46
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    47
    This is a much better approach to the alternatives:
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    48
        passing additional 'doConfirm' arguments down from the high level caller
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    49
        keeping the doConfirm settings in a passed down flag object
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    50
        keeping the flag in a global (very bad)
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    51
        keeping it in a class var (almost as bad)
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    52
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    53
    Notice: thats one of the nice consequences of proceedable exceptions.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    54
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    55
    [authors:]
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    56
        Stefan Vogel
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    57
        Claus Gittinger
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    58
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    59
    [see also:]
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    60
        Query Notification Exception    
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    61
"
10845
948ce25c5209 copyright
Claus Gittinger <cg@exept.de>
parents: 10518
diff changeset
    62
! !
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    63
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    64
!UserConfirmation methodsFor:'accessing'!
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    65
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    66
aspect
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    67
    "the aspect the user is asked. Set this to a symbol. 
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    68
     It can be used by a exception handler"
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    69
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    70
    ^ parameter
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    71
!
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    72
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    73
aspect:aSymbol
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    74
    "the aspect the user is asked. Set this to a symbol. 
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    75
     It can be used by a exception handler"
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    76
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    77
    parameter := aSymbol
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    78
!
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    79
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    80
canCancel
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    81
    "answer true, if the user is allowed to press the cancel button
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    82
     in a confirmation dialog"
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    83
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    84
    ^ canCancel ? false
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    85
!
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    86
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    87
canCancel:something
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    88
    canCancel := something.
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    89
!
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    90
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
    91
defaultAnswer
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    92
    "used to pass information from the raiser to the GUI dialog.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    93
     Specifies, which answer of the three (yes/no/cancel) should be the return-key-default.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    94
     If not specified, the cancel-key will be the default"
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    95
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
    96
    ^ defaultAnswer
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    97
!
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
    98
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
    99
defaultAnswer:aBooleanOrNil
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   100
    "used to pass information from the raiser to the GUI dialog.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   101
     Specifies, which answer of the three (yes/no/cancel) should be the return-key-default.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   102
     If not specified, the cancel-key will be the default"
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   103
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   104
    defaultAnswer := aBooleanOrNil
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   105
! !
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   106
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   107
!UserConfirmation methodsFor:'default actions'!
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   108
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   109
defaultAction
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   110
    "Default action for confirmations: open a info box with description.
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   111
     If no GUI present, assume that the user pressed 'yes'"
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   112
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   113
    |text retVal retValText|
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   114
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   115
    text := self description.
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   116
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   117
    self hasDialog ifTrue:[
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   118
        self canCancel ifTrue:[
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   119
            ^ Dialog confirmWithCancel:text default:defaultAnswer
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   120
        ] ifFalse:[
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   121
            ^ Dialog confirm:text default:defaultAnswer
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   122
        ].
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   123
    ].
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   124
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   125
    "
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   126
     on systems without GUI, simply show
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   127
     the message on the Transcript and assume, that he would have typed 'yes' (or the defaultAnswer).
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   128
    "
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   129
    retVal := defaultAnswer notNil 
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   130
                ifTrue:[ defaultAnswer ]
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   131
                ifFalse:[ 
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   132
                    self canCancel 
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   133
                        ifTrue:[ nil ]
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   134
                        ifFalse:[ true ]].
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   135
11365
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   136
    retValText := retVal isNil
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   137
                ifTrue:[ 'cancel' ]
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   138
                ifFalse:[
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   139
                    retVal 
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   140
                        ifTrue:[ 'yes' ] 
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   141
                        ifFalse:[ 'no' ]].
5b8d580b8df5 + defaultAnswer renamed
Claus Gittinger <cg@exept.de>
parents: 11364
diff changeset
   142
11364
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   143
    Transcript 
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   144
        show:('User confirmation requested (assuming %1): ' bindWith:retValText); 
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   145
        showCR:text.
217571ef0914 + defaultAnswerInDialog
Claus Gittinger <cg@exept.de>
parents: 11196
diff changeset
   146
    ^ retVal
10518
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   147
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   148
    "
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   149
      UserConfirmation raiseRequestErrorString:'Please click yes or no!!'
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   150
    "
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   151
! !
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   152
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   153
!UserConfirmation class methodsFor:'documentation'!
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   154
f2717d1ae95d initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   155
version
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
   156
    ^ '$Header: /cvs/stx/stx/libbasic/UserConfirmation.st,v 1.5 2008/11/22 10:53:08 cg Exp $'
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   157
!
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   158
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   159
version_SVN
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
   160
    ^ '$Id: UserConfirmation.st 10729 2011-10-31 22:19:21Z vranyj1 $'
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
   161
! !
17892
d86c8bd5ece3 Merged with CVS
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17869
diff changeset
   162