;+
;
; @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 textin {in}{required} {type=scalar string or arrays of string}
; If textin is a scalar string, we look for the line feed character "!C".
;
; If textin 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)
; or++
; Activate to print the error message without printing the routine name with
; its full path.
;
; @keyword PARENT
; same as DIALOG_PARENT of DIALOG_MESSAGE
;
; @keyword QUESTION {default="Warning"}
; Set this keyword to create a "Question" dialog.
; If batch mode is detected, answer to be given is ANSWER_BATCH if exists or
; the default one (see DEFAULT_NO keyword).
;
; @keyword ANSWER_BATCH
; Answer to be given to replace human being when running in non interactive
; session. Only used when QUESTION keyword is set.
;
; @keyword DEFAULT_NO {default="Yes"}
; Set this keyword to make the "No" button the default selection for
; "Question" dialog.
;
; @keyword _EXTRA
; Used to pass keywords to DIALOG_MESSAGE and
; MESSAGE
;
; @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
;
; To simulated non interactive session :
;
; IDL> set_default_device
; IDL> key_batch = 1
; IDL> help, report('question1: !C does it works ?',/question, answer_batch='y')
; question1:
; does it works ? y/n (default answer is y)
; BYTE = 1
;
; Like in determineminmax.pro:
;
; set_default_device
; key_batch = 1
; vraimin = 0.d0
; question = ['Warning: constant filed, same value everywhere : ' + strtrim(vraimin, 2) +'!', 'Shall we make the plot?']
; answer = report(question, /default_no, /question)
;
; If widgets are already activated, it is the same thing but with widgets!
;
; @history
;
; - fplod 20130802T123116Z cratos.locean-ipsl.upmc.fr (Linux)
;
; * add ANSWER_BATCH keyword and handle key_batch
;
; - Sebastien Masson (smasson\@lodyc.jussieu.fr) 21/10/1999
;
; @version
; $Id$
;
;-
FUNCTION report, textin, DEFAULT_NO=default_no, PARENT=parent $
, QUESTION=question, SIMPLE=simple $
, ANSWER_BATCH=answer_batch $
, _EXTRA=ex
;
compile_opt idl2, strictarrsubs
@cm_general
;
res = -1 ;
; check parameter and keywords
if keyword_set(default_no) then default_answer = 'n' ELSE default_answer = 'y'
; if QUESTION keyword is set, ANSWER_BATCH must be also set with value in '', 'y' or 'n'
IF keyword_set(QUESTION) THEN BEGIN
IF NOT keyword_set(ANSWER_BATCH) THEN BEGIN
print, 'www : ANSWER_BATCH is not set, default answer while be used'
answer_batch = default_answer
ENDIF ELSE BEGIN
IF answer_batch NE '' and answer_batch NE 'y' and answer_batch NE 'n' THEN BEGIN
answer_batch = default_answer
ENDIF
ENDELSE
ENDIF
; we separate the text in different lines (separated by !C) if it is not already done...
if n_elements(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin
; we get the line, routine name and revision version
IF NOT keyword_set(simple) THEN BEGIN
; Look for the revision in the code of the procedure/function calling this
; report function (ie the one where an problem was detected) in the first
; occurrence of the form :
; "; $Id$"
prefix = routine_name(1)
split = STRSPLIT(prefix, ' ', /EXTRACT, count = cnt)
IF cnt GT 1 THEN BEGIN
coderoutine = getfile(split[1])
idline = (where(stregex(coderoutine, '^; \$Id: .* .* .* .* \$', /boolean) EQ 1))[0]
IF (idline GT 0) THEN BEGIN
split = STRSPLIT(coderoutine[idline], ' ', /EXTRACT)
prefix = '% '+prefix+ ' rev. ' + split[3] + ': '
ENDIF ELSE BEGIN
prefix = '% '+prefix+': '
ENDELSE
ENDIF
text = [prefix, text]
ENDIF
; 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 is the 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]
;
; if non interactive mode has not yet have been tested, do it
IF NOT testvar(var = key_batch) THEN BEGIN
set_default_device
ENDIF
if key_batch EQ 0 THEN BEGIN
; if interactive mode is the current one, wait for human being answer ...
read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
ENDIF ELSE BEGIN
; if not, answer with ANSWER_BATCH keyword or the default answer if not set
IF testvar(var = answer_batch) THEN BEGIN
print, 'batch answer with answer_batch ', answer_batch
answer = answer_batch
ENDIF ELSE BEGIN
print, 'batch answer with default_answer ', default_answer
answer = default_answer
ENDELSE
ENDELSE
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 the answer
case answer of
'':res = default_answer EQ 'y'
'y':res = 1
'n':res = 0
endcase
ENDIF
ENDELSE
; If we do not ask any question, we just make a print
IF NOT keyword_set(question) THEN BEGIN
FOR i = 0, n_elements(text)-1 do print, text[i]
ENDIF
return, res
end