Helios-Inspector.st 6.6 KB

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