;+ ; ; @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} {type=scalar string or arrays of string} ; If TEXT is a scalar string, we look for the line feed characters "!C" ; 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) ; 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. ; ; @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 ; ; 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 ENDELSE ; If we do not ask any question, we just make a print IF NOT keyword_set(question) THEN BEGIN 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] ENDIF return, res end