;+ ; ; @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. ; ; @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, textin, 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(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin ; we get the line, routine name ad revision version IF NOT keyword_set(simple) THEN BEGIN ; Look for the revsion in the code of the procedure/function calling this ; report function (ie the one where an problem was detected) in the first ; occurence of the form : ; "; $Id$" prefix = routine_name(1) split = STRSPLIT(prefix, ' ', /EXTRACT) 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 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] 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 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