[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 | ; |
---|
[277] | 8 | ; @param TEXTIN {in}{required} {type=scalar string or arrays of string} |
---|
| 9 | ; If TEXTIN is a scalar string, we look for the line feed character "!C". |
---|
| 10 | ; If TEXTIN 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 | ; |
---|
[277] | 63 | FUNCTION report, textin, 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... |
---|
[277] | 69 | if n_elements(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin |
---|
| 70 | ; we get the line, routine name ad revision version |
---|
| 71 | IF NOT keyword_set(simple) THEN BEGIN |
---|
| 72 | ; Look for the revsion in the code of the procedure/function calling this |
---|
| 73 | ; report function (ie the one where an problem was detected) in the first |
---|
| 74 | ; occurence of the form : |
---|
| 75 | ; "; $Id$" |
---|
| 76 | prefix = routine_name(1) |
---|
| 77 | split = STRSPLIT(prefix, ' ', /EXTRACT) |
---|
| 78 | coderoutine = getfile(split[1]) |
---|
| 79 | idline = (where(stregex(coderoutine, '^; \$Id: .* .* .* .* \$', /boolean) EQ 1))[0] |
---|
| 80 | IF (idline GT 0) THEN BEGIN |
---|
| 81 | split = STRSPLIT(coderoutine[idline], ' ', /EXTRACT) |
---|
| 82 | prefix = '% '+prefix+ ' rev. ' + split[3] + ': ' |
---|
| 83 | ENDIF ELSE BEGIN |
---|
| 84 | prefix = '% '+prefix+': ' |
---|
| 85 | ENDELSE |
---|
| 86 | text = [prefix, text] |
---|
| 87 | ENDIF |
---|
[133] | 88 | ; there is some widgets activated, it is easy, we call dialog_massage |
---|
[239] | 89 | if (widget_info(/managed))[0] NE 0 then BEGIN |
---|
| 90 | res = dialog_message(text, dialog_parent = parent, QUESTION = question $ |
---|
| 91 | , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex) |
---|
| 92 | if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1 |
---|
| 93 | ENDIF ELSE BEGIN |
---|
[133] | 94 | ; there is not any widget activated |
---|
| 95 | ; do we ask a question ? |
---|
[277] | 96 | IF keyword_set(question) THEN BEGIN |
---|
[266] | 97 | ; what is the answer by default ? |
---|
[239] | 98 | if keyword_set(default_no) then answer = 'n' ELSE answer = 'y' |
---|
| 99 | default_answer = answer |
---|
| 100 | if n_elements(text) GT 1 THEN $ |
---|
[277] | 101 | for i = 0, n_elements(text)-2 do print, text[i] |
---|
[239] | 102 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer |
---|
| 103 | answer = strlowcase(answer) ; |
---|
[133] | 104 | ; if the answer is not appropriated |
---|
[239] | 105 | while answer NE '' and answer NE 'y' and answer NE 'n' do begin |
---|
| 106 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer |
---|
| 107 | answer = strlowcase(answer) |
---|
| 108 | ENDWHILE ; |
---|
[266] | 109 | ; we adjust res in function of the answer |
---|
[239] | 110 | case answer of |
---|
| 111 | '':res = default_answer EQ 'y' |
---|
| 112 | 'y':res = 1 |
---|
| 113 | 'n':res = 0 |
---|
| 114 | endcase |
---|
| 115 | ENDIF |
---|
| 116 | ENDELSE |
---|
[133] | 117 | ; If we do not ask any question, we just make a print |
---|
[239] | 118 | IF NOT keyword_set(question) THEN BEGIN |
---|
[277] | 119 | FOR i = 0, n_elements(text)-1 do print, text[i] |
---|
| 120 | ENDIF |
---|
[2] | 121 | |
---|
[277] | 122 | return, res |
---|
[2] | 123 | end |
---|