1
0

Helios-Inspector.st 6.7 KB

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