Helios-Inspector.st 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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: model selectedInstVarObject printString
  154. ! !
  155. Object subclass: #HLInspectorModel
  156. instanceVariableNames: 'announcer environment inspectee code variables selection'
  157. package: 'Helios-Inspector'!
  158. !HLInspectorModel methodsFor: 'accessing'!
  159. announcer
  160. ^ announcer ifNil: [ self initializeAnnouncer ]
  161. !
  162. code
  163. "Answers the code model working for this workspace model"
  164. ^ code ifNil:[self initializeCode]
  165. !
  166. environment
  167. ^ environment ifNil: [ self initializeEnvironment]
  168. !
  169. environment: anEnvironment
  170. environment := anEnvironment
  171. !
  172. inspectee
  173. ^ inspectee
  174. !
  175. inspectee: anObject
  176. inspectee := anObject
  177. !
  178. selectedInstVarObject
  179. ^ self instVarObjectAt: self selection
  180. !
  181. selection
  182. ^ selection ifNil:[self initializeSelection]
  183. !
  184. selection: anObject
  185. selection := anObject.
  186. self announcer announce: (HLInstanceVariableSelected on: selection)
  187. !
  188. variables
  189. ^ variables
  190. !
  191. variables: aCollection
  192. variables := aCollection
  193. ! !
  194. !HLInspectorModel methodsFor: 'actions'!
  195. beLocal
  196. self initializeEnvironment
  197. !
  198. beRemoteOn: anIPAddress port: aPort
  199. "to-do"
  200. "environment := HLRemoteEnvironment on: anIPAddress port: aPort
  201. ...kind of stuff"
  202. !
  203. inspect: anObject on: anInspector
  204. inspectee := anObject.
  205. variables := #().
  206. inspectee inspectOn: anInspector
  207. !
  208. instVarObjectAt: anInstVarName
  209. ^ self variables at: anInstVarName
  210. !
  211. selectedInstVar: anInstVarObject
  212. self halt.
  213. self selection: (self variables keyAtValue: anInstVarObject)
  214. !
  215. subscribe: aWidget
  216. aWidget subscribeTo: self announcer
  217. ! !
  218. !HLInspectorModel methodsFor: 'initialization'!
  219. initializeAnnouncer
  220. ^ announcer := Announcer new
  221. !
  222. initializeCode
  223. ^ code := HLCodeModel on: self environment
  224. !
  225. initializeEnvironment
  226. ^ environment := HLLocalEnvironment new
  227. !
  228. initializeSelection
  229. ^ selection := self inspectee
  230. ! !
  231. !HLInspectorModel methodsFor: 'reactions'!
  232. onKeyDown: anEvent
  233. <if(anEvent.ctrlKey) {
  234. if(anEvent.keyCode === 80) { //ctrl+p
  235. self._printIt();
  236. anEvent.preventDefault();
  237. return false;
  238. }
  239. if(anEvent.keyCode === 68) { //ctrl+d
  240. self._doIt();
  241. anEvent.preventDefault();
  242. return false;
  243. }
  244. if(anEvent.keyCode === 73) { //ctrl+i
  245. self._inspectIt();
  246. anEvent.preventDefault();
  247. return false;
  248. }
  249. }>
  250. ! !
  251. !HLInspectorModel class methodsFor: 'actions'!
  252. on: anEnvironment
  253. ^ self new
  254. environment: anEnvironment;
  255. yourself
  256. ! !
  257. HLNavigationListWidget subclass: #HLInspectorVariables
  258. instanceVariableNames: 'announcer model list diveButton'
  259. package: 'Helios-Inspector'!
  260. !HLInspectorVariables methodsFor: 'accessing'!
  261. announcer
  262. ^ announcer ifNil:[self initializeAnnouncer]
  263. !
  264. model
  265. ^ model
  266. !
  267. model: aModel
  268. model := aModel
  269. !
  270. selection
  271. ^ model selection
  272. !
  273. variables
  274. ^ model variables
  275. ! !
  276. !HLInspectorVariables methodsFor: 'actions'!
  277. refresh
  278. self resetItems.
  279. super refresh
  280. !
  281. resetItems
  282. items := nil
  283. ! !
  284. !HLInspectorVariables methodsFor: 'initialization'!
  285. initializeAnnouncer
  286. ^ announcer := Announcer new
  287. !
  288. initializeItems
  289. ^ items := self model variables keys
  290. ! !
  291. !HLInspectorVariables methodsFor: 'reactions'!
  292. selectItem: anObject
  293. super selectItem: anObject.
  294. self model selectedInstVar: anObject
  295. ! !
  296. !HLInspectorVariables methodsFor: 'rendering'!
  297. renderButtonsOn: html
  298. html button
  299. class: 'btn';
  300. with: 'Refresh';
  301. onClick: [self announcer announce: HLRefreshRequested new].
  302. diveButton := html button
  303. class: 'btn';
  304. with: 'Dive';
  305. onClick: [self announcer announce: HLDiveRequested new]
  306. ! !