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