[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; |
---|
[224] | 6 | ; @file_comments |
---|
| 7 | ; Like dialog_message.pro if there is already some widget |
---|
| 8 | ; active or like message.pro if there is not any widget active. |
---|
[133] | 9 | ; To ask a question whose answer is not yes/no,use xquestion. |
---|
[2] | 10 | ; |
---|
[224] | 11 | ; @param TEXT {in}{required} |
---|
[136] | 12 | ; one string or one vector of string. Si le string ne |
---|
[226] | 13 | ; comporte qu''un element, on cherche les eventuels caracteres de |
---|
[2] | 14 | ; retour a la ligne: '!C'. If text is set to an array of strings, each |
---|
| 15 | ; array element is displayed as a separate line of text. |
---|
| 16 | ; |
---|
[224] | 17 | ; @keyword SIMPLE |
---|
[136] | 18 | ; activate to print only the message without the name |
---|
| 19 | ; and the line of the routine (defined by calling routine_name) |
---|
[11] | 20 | ; |
---|
[224] | 21 | ; @keyword _EXTRA |
---|
[136] | 22 | ; used to pass keywords from dialog_message.pro and message.pro |
---|
[2] | 23 | ; |
---|
[224] | 24 | ; @keyword PARENT |
---|
[136] | 25 | ; same as DIALOG_PARENT de dialog_message.pro |
---|
[2] | 26 | ; |
---|
[136] | 27 | ; @keyword QUESTION {default="Warning"} |
---|
| 28 | ; Set this keyword to create a "Question" dialog. |
---|
[2] | 29 | ; |
---|
[136] | 30 | ; @keyword DEFAULT_NO {default="Yes"} |
---|
[224] | 31 | ; Set this keyword to make the "No" button the default selection for |
---|
| 32 | ; "Question" dialog. |
---|
[2] | 33 | ; |
---|
[224] | 34 | ; @keyword SIMPLE |
---|
| 35 | ; Activate to print the error message without printing the routine name with |
---|
[136] | 36 | ; its full path. |
---|
[2] | 37 | ; |
---|
[224] | 38 | ; @returns |
---|
[136] | 39 | ; -1 if the keyword QUESTION is not activated |
---|
| 40 | ; If the keyword is activated, return 1 for yes and 0 for no. |
---|
[224] | 41 | ; |
---|
| 42 | ; @examples |
---|
[136] | 43 | ; If there is not any widget activated: |
---|
[2] | 44 | ; |
---|
[136] | 45 | ; IDL> help, report('toto tata') |
---|
| 46 | ; % $MAIN$: toto tata |
---|
| 47 | ; <Expression> INT = -1 |
---|
| 48 | ; IDL> help, report('does it works ?',/question) |
---|
| 49 | ; does it works ? y/n (default answer is y) |
---|
| 50 | ; <Expression> BYTE = 1 |
---|
| 51 | ; IDL> help, report('question1: !C does it works ?',/question) |
---|
| 52 | ; question1: |
---|
| 53 | ; does it works ? y/n (default answer is y) |
---|
| 54 | ; <Expression> BYTE = 1 |
---|
[2] | 55 | ; |
---|
[133] | 56 | ; If widgets are already activated, it is the same thing but with widgets! |
---|
[2] | 57 | ; |
---|
[224] | 58 | ; @history |
---|
| 59 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[2] | 60 | ; 21/10/1999 |
---|
[133] | 61 | ; |
---|
[224] | 62 | ; @version |
---|
| 63 | ; $Id$ |
---|
[133] | 64 | ; |
---|
[2] | 65 | ;- |
---|
| 66 | ;------------------------------------------------------------ |
---|
| 67 | ;------------------------------------------------------------ |
---|
| 68 | ;------------------------------------------------------------ |
---|
[11] | 69 | FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _extra = ex |
---|
[114] | 70 | ; |
---|
| 71 | compile_opt idl2, strictarrsubs |
---|
| 72 | ; |
---|
[133] | 73 | res = -1 ; |
---|
| 74 | ; we separate the text in different lines (separated by !C) if it is not already done... |
---|
[2] | 75 | if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim) |
---|
[133] | 76 | ; there is some widgets activated, it is easy, we call dialog_massage |
---|
[2] | 77 | if (widget_info(/managed))[0] NE 0 then BEGIN |
---|
| 78 | res = dialog_message(text, dialog_parent = parent, QUESTION = question $ |
---|
| 79 | , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex) |
---|
| 80 | if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1 |
---|
| 81 | ENDIF ELSE BEGIN |
---|
[133] | 82 | ; there is not any widget activated |
---|
| 83 | ; do we ask a question ? |
---|
[2] | 84 | if keyword_set(question) then BEGIN |
---|
[133] | 85 | ; what i sthe answer by default ? |
---|
[2] | 86 | if keyword_set(default_no) then answer = 'n' ELSE answer = 'y' |
---|
| 87 | default_answer = answer |
---|
| 88 | if n_elements(text) GT 1 THEN $ |
---|
[224] | 89 | for i = 0, n_elements(text)-2 do print,text[i] |
---|
[2] | 90 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer |
---|
| 91 | answer = strlowcase(answer) ; |
---|
[133] | 92 | ; if the answer is not appropriated |
---|
[2] | 93 | while answer NE '' and answer NE 'y' and answer NE 'n' do begin |
---|
| 94 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer |
---|
| 95 | answer = strlowcase(answer) |
---|
| 96 | ENDWHILE ; |
---|
[133] | 97 | ; we adjust res in function of th answer |
---|
[2] | 98 | case answer of |
---|
| 99 | '':res = default_answer EQ 'y' |
---|
| 100 | 'y':res = 1 |
---|
| 101 | 'n':res = 0 |
---|
| 102 | endcase |
---|
| 103 | endif ELSE BEGIN |
---|
[133] | 104 | ; If we do not ask any question, we just make a print |
---|
[11] | 105 | IF keyword_set(simple) THEN prefix = '' ELSE prefix = '% '+routine_name(1)+': ' |
---|
[2] | 106 | if n_elements(text) GT 1 THEN $ |
---|
[224] | 107 | for i = 0, n_elements(text)-2 do print, prefix+text[i] |
---|
[11] | 108 | print, prefix+text[n_elements(text)-1] |
---|
[2] | 109 | ENDELSE |
---|
| 110 | ENDELSE |
---|
| 111 | |
---|
| 112 | return, res |
---|
| 113 | end |
---|