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