1
0

Helios-Inspector.st 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. open
  240. HLManager current addTab: (HLTab on: self labelled: self tabLabel)
  241. !
  242. refresh
  243. self
  244. refreshVariablesWidget;
  245. refreshDisplayWidget
  246. !
  247. refreshDisplayWidget
  248. self displayWidget refresh
  249. !
  250. refreshVariablesWidget
  251. self variablesWidget refresh
  252. !
  253. setLabel: aString
  254. self model label: aString
  255. !
  256. setVariables: aDictionary
  257. self model variables: aDictionary
  258. ! !
  259. !HLInspectorWidget methodsFor: 'reactions'!
  260. onDive
  261. HLInspector new
  262. inspect: self model selectedInstVarObject;
  263. open
  264. !
  265. onDoneIt
  266. self refresh
  267. !
  268. onInspectIt
  269. !
  270. onInstanceVariableSelected
  271. self codeWidget receiver: self model selectedInstVarObject.
  272. self refreshDisplayWidget
  273. !
  274. onPrintIt
  275. ! !
  276. !HLInspectorWidget methodsFor: 'registration'!
  277. register
  278. HLInspector register: self
  279. !
  280. unregister
  281. super unregister.
  282. HLInspector unregister: self
  283. ! !
  284. !HLInspectorWidget methodsFor: 'rendering'!
  285. renderContentOn: html
  286. html with: (HLHorizontalSplitter
  287. with: (HLVerticalSplitter
  288. with: self variablesWidget
  289. with: self displayWidget)
  290. with: self codeWidget)
  291. ! !
  292. HLInspectorWidget subclass: #HLInspector
  293. instanceVariableNames: ''
  294. package: 'Helios-Inspector'!
  295. !HLInspector methodsFor: 'rendering'!
  296. renderContentOn: html
  297. html with: (HLContainer with: (HLHorizontalSplitter
  298. with: (HLVerticalSplitter
  299. with: self variablesWidget
  300. with: self displayWidget)
  301. with: self codeWidget)).
  302. self variablesWidget focus
  303. ! !
  304. HLInspector class instanceVariableNames: 'inspectors'!
  305. !HLInspector class methodsFor: 'accessing'!
  306. inspectors
  307. ^ inspectors ifNil: [ inspectors := OrderedCollection new ]
  308. !
  309. tabClass
  310. ^ 'inspector'
  311. !
  312. tabLabel
  313. ^ 'Inspector'
  314. !
  315. tabPriority
  316. ^ 10
  317. ! !
  318. !HLInspector class methodsFor: 'actions'!
  319. inspect: anObject
  320. self new
  321. inspect: anObject;
  322. open
  323. ! !
  324. !HLInspector class methodsFor: 'initialization'!
  325. initialize
  326. super initialize.
  327. self watchChanges
  328. !
  329. watchChanges
  330. [ self inspectors do: [ :each | each refresh ] ]
  331. valueWithInterval: 500
  332. ! !
  333. !HLInspector class methodsFor: 'registration'!
  334. register: anInspector
  335. self inspectors add: anInspector
  336. !
  337. unregister: anInspector
  338. self inspectors remove: anInspector
  339. ! !
  340. !HLInspector class methodsFor: 'testing'!
  341. canBeOpenAsTab
  342. ^ false
  343. ! !