show JSON in inspector
authorClaus Gittinger <cg@exept.de>
Thu, 11 Jul 2019 20:16:05 +0200
changeset 18888 6be9100c0568
parent 18887 6ae95bd5f0b3
child 18889 a2d98d4dfeae
show JSON in inspector
extensions.st
--- a/extensions.st	Thu Jul 11 19:28:27 2019 +0200
+++ b/extensions.st	Thu Jul 11 20:16:05 2019 +0200
@@ -2219,7 +2219,9 @@
 
     <inspector2Tab>
 
-    ^ Tools::Inspector2Tab toBrowseClass:(self class theNonMetaclass) selector:nil label:'Class'
+    ^ Tools::Inspector2Tab 
+        toBrowseClass:(self class theNonMetaclass) selector:nil 
+        label:'Class'
     
 "/    |makeView|
 "/
@@ -2322,6 +2324,36 @@
 
 !Object methodsFor:'inspecting'!
 
+inspector2TabJSON
+    <inspector2Tab>
+
+    |jsonPrinter jsonString|
+
+    (jsonPrinter := Smalltalk classNamed:'JSONPrinter') isNil ifTrue:[^ nil].
+
+    [
+        jsonString := jsonPrinter toJSON:self.
+    ] on:Error do:[:ex |
+        jsonString := '%1 (an instance of %2) cannot be represented as JSON:\\%3' withCRs
+                        bindWith:self displayString
+                        with:self class className
+                        with:ex description
+    ].
+
+    ^self newInspector2Tab
+        label: 'JSON';
+        priority: 15;
+        view: ((HVScrollableView for:TextView) 
+                autoHideScrollBars:true;        
+                contents: jsonString; 
+                yourself)
+
+    "Created: / 17-02-2008 / 10:13:07 / janfrog"
+    "Modified: / 11-11-2018 / 12:16:07 / Claus Gittinger"
+! !
+
+!Object methodsFor:'inspecting'!
+
 inspector2TabLabel
     "label of the main tab"