;+
;
; @file_comments
; Like dialog_message if there is already some widget
; active or like message if there is not any widget active.
; To ask a question whose answer is not yes/no,use xquestion.
;
; @param TEXT {in}{required}
; one string or one vector of string. Si le string ne
; comporte qu''un element, on cherche les eventuels caracteres de
; retour a la ligne: '!C'. If text is set to an array of strings, each
; array element is displayed as a separate line of text.
;
; @keyword SIMPLE
; activate to print only the message without the name
; and the line of the routine (defined by calling routine_name)
;
; @keyword _EXTRA
; Used to pass keywords to dialog_message and message
;
; @keyword PARENT
; same as DIALOG_PARENT of dialog_message
;
; @keyword QUESTION {default="Warning"}
; Set this keyword to create a "Question" dialog.
;
; @keyword DEFAULT_NO {default="Yes"}
; Set this keyword to make the "No" button the default selection for
; "Question" dialog.
;
; @keyword SIMPLE
; Activate to print the error message without printing the routine name with
; its full path.
;
; @returns
; -1 if the keyword QUESTION is not activated
; If the keyword QUESTION is activated, return 1 for yes and 0 for no.
;
; @examples
; If there is not any widget activated:
;
; IDL> help, report('toto tata')
; % $MAIN$: toto tata
; INT = -1
; IDL> help, report('does it works ?',/question)
; does it works ? y/n (default answer is y)
; BYTE = 1
; IDL> help, report('question1: !C does it works ?',/question)
; question1:
; does it works ? y/n (default answer is y)
; BYTE = 1
;
; If widgets are already activated, it is the same thing but with widgets!
;
; @history
; Sebastien Masson (smasson\@lodyc.jussieu.fr)
; 21/10/1999
;
; @version
; $Id$
;
;-
;
FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _extra = ex
;
compile_opt idl2, strictarrsubs
;
res = -1 ;
; we separate the text in different lines (separated by !C) if it is not already done...
if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim)
; there is some widgets activated, it is easy, we call dialog_massage
if (widget_info(/managed))[0] NE 0 then BEGIN
res = dialog_message(text, dialog_parent = parent, QUESTION = question $
, title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
ENDIF ELSE BEGIN
; there is not any widget activated
; do we ask a question ?
if keyword_set(question) then BEGIN
; what i sthe answer by default ?
if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
default_answer = answer
if n_elements(text) GT 1 THEN $
for i = 0, n_elements(text)-2 do print,text[i]
read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer
answer = strlowcase(answer) ;
; if the answer is not appropriated
while answer NE '' and answer NE 'y' and answer NE 'n' do begin
read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer
answer = strlowcase(answer)
ENDWHILE ;
; we adjust res in function of th answer
case answer of
'':res = default_answer EQ 'y'
'y':res = 1
'n':res = 0
endcase
endif ELSE BEGIN
; If we do not ask any question, we just make a print
IF keyword_set(simple) THEN prefix = '' ELSE prefix = '% '+routine_name(1)+': '
if n_elements(text) GT 1 THEN $
for i = 0, n_elements(text)-2 do print, prefix+text[i]
print, prefix+text[n_elements(text)-1]
ENDELSE
ENDELSE
return, res
end