class: Object
authorClaus Gittinger <cg@exept.de>
Fri, 10 Jan 2020 21:44:15 +0100
changeset 19406 7248d8fd0b95
parent 19405 26e3e5c20b52
child 19407 3475480396e2
class: Object changed: #inspector2TabJSON #printStringLimitedTo:
extensions.st
--- a/extensions.st	Fri Jan 10 21:41:43 2020 +0100
+++ b/extensions.st	Fri Jan 10 21:44:15 2020 +0100
@@ -2414,35 +2414,42 @@
 inspector2TabJSON
     <inspector2Tab>
 
-    |jsonPrinter jsonString countRecursive|
+    |holder jsonPrinter jsonString countRecursive v|
 
     (jsonPrinter := Smalltalk classNamed:'JSONPrinter') isNil ifTrue:[^ nil].
 
-    countRecursive := 0.
-    [
-        jsonString := jsonPrinter encodePrettyPrinted:self printLimit:(JSONPrinter defaultPrettyPrintLimit).
-    ] on:Error do:[:ex |
-        (ex isKindOf:RecursionError) ifTrue:[
-            ex originator == JSONPrinter ifTrue:[
-                countRecursive := countRecursive + 1.
-                countRecursive < 10 ifTrue:[
-                    ex proceed.
+    "/ because JSON generation takes a ong time, only do it when the tab's view is mapped.
+    holder := 
+        [
+            jsonString isNil ifTrue:[
+                countRecursive := 0.
+                [
+                    jsonString := jsonPrinter encodePrettyPrinted:self printLimit:(JSONPrinter defaultPrettyPrintLimit).
+                ] on:Error do:[:ex |
+                    (ex isKindOf:RecursionError) ifTrue:[
+                        ex originator == JSONPrinter ifTrue:[
+                            countRecursive := countRecursive + 1.
+                            countRecursive < 10 ifTrue:[
+                                ex proceed.
+                            ].
+                        ].
+                    ].
+                    jsonString := '%1\(an instance of %2)\cannot be represented as JSON because:\\%3' withCRs
+                                    bindWith:self displayString
+                                    with:self class className
+                                    with:ex description
                 ].
             ].
+            jsonString
         ].
-        jsonString := '%1\(an instance of %2)\cannot be represented as JSON because:\\%3' withCRs
-                        bindWith:self displayString
-                        with:self class className
-                        with:ex description
-    ].
-
+
+    v := HVScrollableView for:TextView.
+    v autoHideScrollBars:true.
+    v scrolledView onChange:#visibility evaluate:[v scrolledView model isNil ifTrue:[self halt. v scrolledView model: holder]].
     ^ self newInspector2Tab
         label: 'JSON';
         priority: 15;
-        view: ((HVScrollableView for:TextView) 
-                autoHideScrollBars:true;        
-                contents: jsonString; 
-                yourself)
+        view: v
 
     "Created: / 17-02-2008 / 10:13:07 / janfrog"
     "Modified: / 11-11-2018 / 12:16:07 / Claus Gittinger"