Helios-Inspector.st 6.9 KB

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