2
0

Helios-Inspector.st 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. ^ 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
  241. refreshVariablesWidget;
  242. refreshDisplayWidget
  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. openAsTab
  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. openAsTab
  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. ! !