Helios-Inspector.st 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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 includesKey: 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. ^ self model variables keys
  130. ! !
  131. !HLInspectorVariablesWidget methodsFor: 'actions'!
  132. refresh
  133. self variables = self items ifFalse: [
  134. self resetItems.
  135. super refresh ]
  136. !
  137. resetItems
  138. items := nil
  139. ! !
  140. !HLInspectorVariablesWidget methodsFor: 'defaults'!
  141. defaultItems
  142. ^ self variables
  143. ! !
  144. !HLInspectorVariablesWidget methodsFor: 'reactions'!
  145. selectItem: anObject
  146. super selectItem: anObject.
  147. self model selectedInstVar: anObject
  148. ! !
  149. !HLInspectorVariablesWidget methodsFor: 'rendering'!
  150. renderButtonsOn: html
  151. diveButton := html button
  152. class: 'btn';
  153. with: 'Dive';
  154. onClick: [ self announcer announce: HLDiveRequested new ]
  155. !
  156. renderContentOn: html
  157. self renderHeadOn: html.
  158. super renderContentOn: html
  159. !
  160. renderHeadOn: html
  161. html div
  162. class: 'list-label';
  163. with: self label
  164. ! !
  165. HLWidget subclass: #HLInspectorWidget
  166. instanceVariableNames: 'model variablesWidget displayWidget codeWidget'
  167. package: 'Helios-Inspector'!
  168. !HLInspectorWidget methodsFor: 'accessing'!
  169. codeWidget
  170. ^ codeWidget ifNil: [
  171. codeWidget := HLCodeWidget new
  172. model: model code;
  173. receiver: model inspectee;
  174. yourself ]
  175. !
  176. displayWidget
  177. ^ displayWidget ifNil: [
  178. displayWidget := HLInspectorDisplayWidget new
  179. model: self model;
  180. yourself ]
  181. !
  182. initialize
  183. super initialize.
  184. self register
  185. !
  186. inspectee
  187. ^ self model inspectee
  188. !
  189. inspectee: anObject
  190. self model inspectee: anObject
  191. !
  192. label
  193. ^ self model label
  194. !
  195. model
  196. ^ model ifNil: [
  197. self model: HLInspectorModel new.
  198. model ]
  199. !
  200. model: aModel
  201. model := aModel.
  202. self codeWidget model: aModel code.
  203. self
  204. observeCodeWidget;
  205. observeVariablesWidget;
  206. observeModel
  207. !
  208. tabLabel
  209. ^ 'Inspector'
  210. !
  211. variablesWidget
  212. ^ variablesWidget ifNil: [
  213. variablesWidget := HLInspectorVariablesWidget new
  214. model: self model;
  215. yourself ]
  216. ! !
  217. !HLInspectorWidget methodsFor: 'actions'!
  218. inspect: anObject
  219. self model inspect: anObject on: self.
  220. self
  221. refreshVariablesWidget;
  222. refreshDisplayWidget
  223. !
  224. observeCodeWidget
  225. self codeWidget announcer
  226. on: HLDoItExecuted
  227. do: [ self onDoneIt ]
  228. !
  229. observeModel
  230. self model announcer
  231. on: HLInstanceVariableSelected
  232. send: #onInstanceVariableSelected
  233. to: self
  234. !
  235. observeVariablesWidget
  236. self variablesWidget announcer
  237. on: HLDiveRequested do:[ self onDive ]
  238. !
  239. refresh
  240. self inspect: self inspectee
  241. !
  242. refreshDisplayWidget
  243. self displayWidget refresh
  244. !
  245. refreshVariablesWidget
  246. self variablesWidget refresh
  247. !
  248. setLabel: aString
  249. self model label: aString
  250. !
  251. setVariables: aDictionary
  252. self model variables: aDictionary
  253. ! !
  254. !HLInspectorWidget methodsFor: 'reactions'!
  255. onDive
  256. HLInspector new
  257. inspect: self model selectedInstVarObject;
  258. openAsTab
  259. !
  260. onDoneIt
  261. self refresh
  262. !
  263. onInspectIt
  264. !
  265. onInstanceVariableSelected
  266. self codeWidget receiver: self model selectedInstVarObject.
  267. self refreshDisplayWidget
  268. !
  269. onPrintIt
  270. ! !
  271. !HLInspectorWidget methodsFor: 'registration'!
  272. register
  273. HLInspector register: self
  274. !
  275. unregister
  276. super unregister.
  277. HLInspector unregister: self
  278. ! !
  279. !HLInspectorWidget methodsFor: 'rendering'!
  280. renderContentOn: html
  281. html with: (HLHorizontalSplitter
  282. with: (HLVerticalSplitter
  283. with: self variablesWidget
  284. with: self displayWidget)
  285. with: self codeWidget)
  286. ! !
  287. HLInspectorWidget subclass: #HLInspector
  288. instanceVariableNames: ''
  289. package: 'Helios-Inspector'!
  290. !HLInspector methodsFor: 'rendering'!
  291. renderContentOn: html
  292. html with: (HLContainer with: (HLHorizontalSplitter
  293. with: (HLVerticalSplitter
  294. with: self variablesWidget
  295. with: self displayWidget)
  296. with: self codeWidget)).
  297. self variablesWidget focus
  298. ! !
  299. HLInspector class instanceVariableNames: 'inspectors'!
  300. !HLInspector class methodsFor: 'accessing'!
  301. inspectors
  302. ^ inspectors ifNil: [ inspectors := OrderedCollection new ]
  303. !
  304. tabClass
  305. ^ 'inspector'
  306. !
  307. tabLabel
  308. ^ 'Inspector'
  309. !
  310. tabPriority
  311. ^ 10
  312. ! !
  313. !HLInspector class methodsFor: 'actions'!
  314. inspect: anObject
  315. self new
  316. openAsTab;
  317. inspect: anObject
  318. ! !
  319. !HLInspector class methodsFor: 'initialization'!
  320. initialize
  321. super initialize.
  322. self watchChanges
  323. !
  324. watchChanges
  325. [ self inspectors do: [ :each | each refresh ] ]
  326. valueWithInterval: 500
  327. ! !
  328. !HLInspector class methodsFor: 'registration'!
  329. register: anInspector
  330. self inspectors add: anInspector
  331. !
  332. unregister: anInspector
  333. self inspectors remove: anInspector
  334. ! !
  335. !HLInspector class methodsFor: 'testing'!
  336. canBeOpenAsTab
  337. ^ false
  338. ! !