Helios-Inspector.st 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. Smalltalk current createPackage: 'Helios-Inspector'!
  2. HLNavigationListWidget subclass: #HLInspectorDisplayWidget
  3. instanceVariableNames: 'model'
  4. package: 'Helios-Inspector'!
  5. !HLInspectorDisplayWidget methodsFor: 'accessing'!
  6. model
  7. ^ model
  8. !
  9. model: aModel
  10. model := aModel
  11. ! !
  12. !HLInspectorDisplayWidget methodsFor: 'rendering'!
  13. renderContentOn: html
  14. html div with: self selectionDisplayString
  15. !
  16. selectionDisplayString
  17. |selection|
  18. selection := model selection.
  19. ^ (model variables keys includes: selection)
  20. ifTrue:[(model instVarObjectAt: selection) printString]
  21. ifFalse:['']
  22. ! !
  23. Object subclass: #HLInspectorModel
  24. instanceVariableNames: 'announcer environment inspectee code variables label selection'
  25. package: 'Helios-Inspector'!
  26. !HLInspectorModel methodsFor: 'accessing'!
  27. announcer
  28. ^ announcer ifNil: [announcer := Announcer new ]
  29. !
  30. code
  31. "Answers the code model working for this workspace model"
  32. ^ code ifNil:[ code := HLCodeModel on: self environment ]
  33. !
  34. environment
  35. ^ environment ifNil: [ HLManager current environment ]
  36. !
  37. environment: anEnvironment
  38. environment := anEnvironment
  39. !
  40. inspectee
  41. ^ inspectee
  42. !
  43. inspectee: anObject
  44. inspectee := anObject
  45. !
  46. label
  47. ^ label ifNil: [ self inspectee printString ]
  48. !
  49. label: aString
  50. label := aString
  51. !
  52. selectedInstVarObject
  53. ^ self instVarObjectAt: self selection
  54. !
  55. selection
  56. ^ selection ifNil:[ '' ]
  57. !
  58. selection: anObject
  59. selection := anObject.
  60. self announcer announce: (HLInstanceVariableSelected on: selection)
  61. !
  62. variables
  63. ^ variables ifNil: [ Dictionary new ]
  64. !
  65. variables: aCollection
  66. variables := aCollection
  67. ! !
  68. !HLInspectorModel methodsFor: 'actions'!
  69. inspect: anObject on: anInspector
  70. inspectee := anObject.
  71. variables := #().
  72. inspectee inspectOn: anInspector
  73. !
  74. instVarObjectAt: anInstVarName
  75. ^ self variables at: anInstVarName
  76. !
  77. selectedInstVar: anInstVarName
  78. self selection: anInstVarName
  79. !
  80. subscribe: aWidget
  81. aWidget subscribeTo: self announcer
  82. ! !
  83. !HLInspectorModel methodsFor: 'reactions'!
  84. onKeyDown: anEvent
  85. <if(anEvent.ctrlKey) {
  86. if(anEvent.keyCode === 80) { //ctrl+p
  87. self._printIt();
  88. anEvent.preventDefault();
  89. return false;
  90. }
  91. if(anEvent.keyCode === 68) { //ctrl+d
  92. self._doIt();
  93. anEvent.preventDefault();
  94. return false;
  95. }
  96. if(anEvent.keyCode === 73) { //ctrl+i
  97. self._inspectIt();
  98. anEvent.preventDefault();
  99. return false;
  100. }
  101. }>
  102. ! !
  103. !HLInspectorModel class methodsFor: 'actions'!
  104. on: anEnvironment
  105. ^ self new
  106. environment: anEnvironment;
  107. yourself
  108. ! !
  109. HLNavigationListWidget subclass: #HLInspectorVariablesWidget
  110. instanceVariableNames: 'announcer model list diveButton'
  111. package: 'Helios-Inspector'!
  112. !HLInspectorVariablesWidget methodsFor: 'accessing'!
  113. announcer
  114. ^ announcer ifNil:[ announcer := Announcer new ]
  115. !
  116. label
  117. ^ self model label
  118. !
  119. model
  120. ^ model
  121. !
  122. model: aModel
  123. model := aModel
  124. !
  125. selection
  126. ^ model selection
  127. !
  128. variables
  129. ^ model variables
  130. ! !
  131. !HLInspectorVariablesWidget methodsFor: 'actions'!
  132. refresh
  133. self resetItems.
  134. super refresh
  135. !
  136. resetItems
  137. items := nil
  138. ! !
  139. !HLInspectorVariablesWidget methodsFor: 'defaults'!
  140. defaultItems
  141. ^ self model variables keys
  142. ! !
  143. !HLInspectorVariablesWidget methodsFor: 'reactions'!
  144. selectItem: anObject
  145. super selectItem: anObject.
  146. self model selectedInstVar: anObject
  147. ! !
  148. !HLInspectorVariablesWidget methodsFor: 'rendering'!
  149. renderButtonsOn: html
  150. diveButton := html button
  151. class: 'btn';
  152. with: 'Dive';
  153. onClick: [ self announcer announce: HLDiveRequested new ]
  154. !
  155. renderContentOn: html
  156. self renderHeadOn: html.
  157. super renderContentOn: html
  158. !
  159. renderHeadOn: html
  160. html div
  161. class: 'list-label';
  162. with: self label
  163. ! !
  164. HLWidget subclass: #HLInspectorWidget
  165. instanceVariableNames: 'model variablesWidget displayWidget codeWidget'
  166. package: 'Helios-Inspector'!
  167. !HLInspectorWidget methodsFor: 'accessing'!
  168. codeWidget
  169. ^ codeWidget ifNil: [
  170. codeWidget := HLCodeWidget new
  171. model: model code;
  172. receiver: model inspectee;
  173. yourself ]
  174. !
  175. displayWidget
  176. ^ displayWidget ifNil: [
  177. displayWidget := HLInspectorDisplayWidget new
  178. model: self model;
  179. yourself ]
  180. !
  181. initialize
  182. super initialize.
  183. self register
  184. !
  185. inspectee
  186. ^ self model inspectee
  187. !
  188. inspectee: anObject
  189. self model inspectee: anObject
  190. !
  191. label
  192. ^ self model label
  193. !
  194. model
  195. ^ model ifNil: [
  196. self model: HLInspectorModel new.
  197. model ]
  198. !
  199. model: aModel
  200. model := aModel.
  201. self codeWidget model: aModel code.
  202. self
  203. observeCodeWidget;
  204. observeVariablesWidget;
  205. observeModel
  206. !
  207. tabLabel
  208. ^ 'Inspector'
  209. !
  210. variablesWidget
  211. ^ variablesWidget ifNil: [
  212. variablesWidget := HLInspectorVariablesWidget new
  213. model: self model;
  214. yourself ]
  215. ! !
  216. !HLInspectorWidget methodsFor: 'actions'!
  217. inspect: anObject
  218. self model inspect: anObject on: self.
  219. self
  220. refreshVariablesWidget;
  221. refreshDisplayWidget
  222. !
  223. observeCodeWidget
  224. self codeWidget announcer
  225. on: HLDoItExecuted
  226. do: [ self onDoneIt ]
  227. !
  228. observeModel
  229. self model announcer
  230. on: HLInstanceVariableSelected
  231. send: #onInstanceVariableSelected
  232. to: self
  233. !
  234. observeVariablesWidget
  235. self variablesWidget announcer
  236. on: HLDiveRequested do:[ self onDive ]
  237. !
  238. open
  239. HLManager current addTab: (HLTab on: self labelled: self tabLabel)
  240. !
  241. refresh
  242. self inspect: self inspectee
  243. !
  244. refreshDisplayWidget
  245. self displayWidget refresh
  246. !
  247. refreshVariablesWidget
  248. self variablesWidget refresh
  249. !
  250. setLabel: aString
  251. self model label: aString
  252. !
  253. setVariables: aDictionary
  254. self model variables: aDictionary
  255. ! !
  256. !HLInspectorWidget methodsFor: 'reactions'!
  257. onDive
  258. HLInspector new
  259. inspect: self model selectedInstVarObject;
  260. open
  261. !
  262. onDoneIt
  263. self refresh
  264. !
  265. onInspectIt
  266. !
  267. onInstanceVariableSelected
  268. self codeWidget receiver: self model selectedInstVarObject.
  269. self refreshDisplayWidget
  270. !
  271. onPrintIt
  272. ! !
  273. !HLInspectorWidget methodsFor: 'registration'!
  274. register
  275. HLInspector register: self
  276. !
  277. unregister
  278. super unregister.
  279. HLInspector unregister: self
  280. ! !
  281. !HLInspectorWidget methodsFor: 'rendering'!
  282. renderContentOn: html
  283. html with: (HLHorizontalSplitter
  284. with: (HLVerticalSplitter
  285. with: self variablesWidget
  286. with: self displayWidget)
  287. with: self codeWidget)
  288. ! !
  289. HLInspectorWidget subclass: #HLInspector
  290. instanceVariableNames: ''
  291. package: 'Helios-Inspector'!
  292. !HLInspector methodsFor: 'rendering'!
  293. renderContentOn: html
  294. html with: (HLContainer with: (HLHorizontalSplitter
  295. with: (HLVerticalSplitter
  296. with: self variablesWidget
  297. with: self displayWidget)
  298. with: self codeWidget)).
  299. self variablesWidget focus
  300. ! !
  301. HLInspector class instanceVariableNames: 'inspectors'!
  302. !HLInspector class methodsFor: 'accessing'!
  303. inspectors
  304. ^ inspectors ifNil: [ inspectors := OrderedCollection new ]
  305. !
  306. tabClass
  307. ^ 'inspector'
  308. !
  309. tabLabel
  310. ^ 'Inspector'
  311. !
  312. tabPriority
  313. ^ 10
  314. ! !
  315. !HLInspector class methodsFor: 'actions'!
  316. inspect: anObject
  317. self new
  318. inspect: anObject;
  319. open
  320. ! !
  321. !HLInspector class methodsFor: 'initialization'!
  322. initialize
  323. super initialize.
  324. self watchChanges
  325. !
  326. watchChanges
  327. [ self inspectors do: [ :each | each refresh ] ]
  328. valueWithInterval: 500
  329. ! !
  330. !HLInspector class methodsFor: 'registration'!
  331. register: anInspector
  332. self inspectors add: anInspector
  333. !
  334. unregister: anInspector
  335. self inspectors remove: anInspector
  336. ! !
  337. !HLInspector class methodsFor: 'testing'!
  338. canBeOpenAsTab
  339. ^ false
  340. ! !