1
0

Helios-Inspector.st 6.8 KB

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