3030package org .scijava .ui .swing .script ;
3131
3232import java .awt .Color ;
33+ import java .awt .Dialog ;
3334import java .awt .Rectangle ;
35+ import java .awt .Window ;
3436import java .io .PrintWriter ;
3537import java .io .StringWriter ;
3638import java .util .Arrays ;
@@ -66,6 +68,7 @@ public class ErrorParser {
6668 private JTextAreaWriter writer ;
6769 private int lengthOfJTextAreaWriter ;
6870 private ErrorStripNotifyingParser notifyingParser ;
71+ private boolean parsingSucceeded ;
6972
7073 public ErrorParser (final EditorPane editorPane ) {
7174 this .editorPane = editorPane ;
@@ -148,8 +151,23 @@ public void parse(final Throwable t) {
148151 parse (sw .toString ());
149152 }
150153
154+ private boolean isIJ1Macro () {
155+ final ScriptLanguage lang = editorPane .getCurrentLanguage ();
156+ return lang != null && "IJ1 Macro" .equals (lang .getLanguageName ());
157+ }
158+
159+ public boolean isLogDetailed () {
160+ if (!isIJ1Macro ()) return parsingSucceeded ;
161+ for (final Window win : Window .getWindows ()) {
162+ if (win != null && win instanceof Dialog && "Macro Error" .equals (((Dialog )win ).getTitle ())) {
163+ return true ; // hopefully there is something in the console
164+ }
165+ }
166+ return parsingSucceeded ;
167+ }
168+
151169 private boolean isCaretMovable () {
152- if (errorLines == null || errorLines .isEmpty () || ! editorPane . isEditable () || ! editorPane . isEnabled () ) {
170+ if (errorLines == null || errorLines .isEmpty ()) {
153171 UIManager .getLookAndFeel ().provideErrorFeedback (editorPane );
154172 return false ;
155173 }
@@ -172,9 +190,15 @@ private void gotoLine(final int lineNumber) {
172190 private void parse (final String errorLog ) {
173191
174192 final ScriptLanguage lang = editorPane .getCurrentLanguage ();
175- if (lang == null )
193+ if (lang == null ) {
194+ abort ();
176195 return ;
177-
196+ }
197+ final boolean isIJM = isIJ1Macro ();
198+ if (isIJM ) {
199+ abort ("Execution errors handled by the Macro Interpreter. Use the Interpreter's Debug option for error tracking" , false );
200+ return ;
201+ }
178202 // Do nothing if disabled, or if only selected text was evaluated in the
179203 // script but we don't know where in the document such selection occurred
180204 if (!enabled ) {
@@ -188,8 +212,10 @@ private void parse(final String errorLog) {
188212
189213 final boolean isJava = "Java" .equals (lang .getLanguageName ());
190214 final String fileName = editorPane .getFileName ();
191- if (isJava && fileName == null )
215+ if (isJava && fileName == null ) {
216+ abort ();
192217 return ;
218+ }
193219
194220 // HACK scala code seems to always be pre-pended by some 10 lines of code(!?).
195221 if ("Scala" .equals (lang .getLanguageName ()))
@@ -209,14 +235,13 @@ else if ("R".equals(lang.getLanguageName()))
209235 parseNonJava (tokenizer .nextToken (), errorLines );
210236 }
211237 }
212- if (errorLines .isEmpty () && "IJ1 Macro" .equals (lang .getLanguageName ())) {
213- abort ("Execution errors handled by the Macro Interpreter. Use the Interpreter's Debug option for error tracking" , false );
214- } else if (!errorLines .isEmpty ()) {
238+ if (!errorLines .isEmpty ()) {
215239 notifyingParser = new ErrorStripNotifyingParser ();
216240 editorPane .addParser (notifyingParser );
217241 editorPane .forceReparsing (notifyingParser );
218242 gotoLine (errorLines .first ());
219243 }
244+ parsingSucceeded = true ;
220245 }
221246
222247 private void parseNonJava (final String lineText , final Collection <Integer > errorLines ) {
@@ -298,10 +323,16 @@ private void parseJava(final String filename, final String line, final Collectio
298323 }
299324 }
300325
326+ private void abort () {
327+ parsingSucceeded = false ;
328+ }
329+
301330 private void abort (final String msg , final boolean offsetNotice ) {
331+ abort ();
302332 if (writer != null ) {
303- String finalMsg = "[WARNING] " + msg + "\n " ;
304- finalMsg += "[WARNING] Reported error line(s) may not match line numbers in the editor\n " ;
333+ String finalMsg = "[INFO] " + msg + "\n " ;
334+ if (offsetNotice )
335+ finalMsg += "[INFO] Reported error line(s) may not match line numbers in the editor\n " ;
305336 writer .textArea .insert (finalMsg , lengthOfJTextAreaWriter );
306337 }
307338 errorLines = null ;
0 commit comments