Helios-Browser.st 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. Smalltalk current createPackage: 'Helios-Browser'!
  2. HLWidget subclass: #HLBrowser
  3. instanceVariableNames: 'model packagesListWidget classesListWidget protocolsListWidget methodsListWidget sourceWidget'
  4. package: 'Helios-Browser'!
  5. !HLBrowser methodsFor: 'accessing'!
  6. announcer
  7. ^ self model announcer
  8. !
  9. environment
  10. ^ self model environment
  11. !
  12. model
  13. ^ model ifNil: [ model := HLBrowserModel new ]
  14. !
  15. model: aModel
  16. model := aModel
  17. ! !
  18. !HLBrowser methodsFor: 'keybindings'!
  19. registerBindingsOn: aBindingGroup
  20. aBindingGroup
  21. addGroupKey: 66 labelled: 'Browse';
  22. addGroupKey: 71 labelled: 'Go to';
  23. addGroupKey: 84 labelled: 'Toggle'.
  24. HLBrowserCommand withAllSubclasses do: [ :each |
  25. each key ifNotNil: [
  26. (aBindingGroup at: each bindingGroup)
  27. add: (each on: self model) asBinding ] ]
  28. ! !
  29. !HLBrowser methodsFor: 'rendering'!
  30. renderContentOn: html
  31. html with: (HLContainer with: (HLHorizontalSplitter
  32. with: (HLVerticalSplitter
  33. with: (HLVerticalSplitter
  34. with: self packagesListWidget
  35. with: self classesListWidget)
  36. with: (HLVerticalSplitter
  37. with: self protocolsListWidget
  38. with: self methodsListWidget))
  39. with: self sourceWidget))
  40. ! !
  41. !HLBrowser methodsFor: 'widgets'!
  42. classesListWidget
  43. ^ classesListWidget ifNil: [
  44. classesListWidget := HLClassesListWidget on: self model.
  45. classesListWidget next: self protocolsListWidget ]
  46. !
  47. methodsListWidget
  48. ^ methodsListWidget ifNil: [
  49. methodsListWidget := HLMethodsListWidget on: self model ]
  50. !
  51. packagesListWidget
  52. ^ packagesListWidget ifNil: [
  53. packagesListWidget := HLPackagesListWidget on: self model.
  54. packagesListWidget next: self classesListWidget ]
  55. !
  56. protocolsListWidget
  57. ^ protocolsListWidget ifNil: [
  58. protocolsListWidget := HLProtocolsListWidget on: self model.
  59. protocolsListWidget next: self methodsListWidget ]
  60. !
  61. sourceWidget
  62. ^ sourceWidget ifNil: [
  63. sourceWidget := HLBrowserSourceWidget on: self model ]
  64. ! !
  65. HLBrowser class instanceVariableNames: 'nextId'!
  66. !HLBrowser class methodsFor: 'accessing'!
  67. nextId
  68. nextId ifNil: [ nextId := 0 ].
  69. ^ 'browser_', (nextId + 1) asString
  70. !
  71. tabLabel
  72. ^ 'Browser'
  73. !
  74. tabPriority
  75. ^ 0
  76. ! !
  77. !HLBrowser class methodsFor: 'testing'!
  78. canBeOpenAsTab
  79. ^ true
  80. ! !
  81. HLNavigationListWidget subclass: #HLBrowserListWidget
  82. instanceVariableNames: 'model'
  83. package: 'Helios-Browser'!
  84. !HLBrowserListWidget methodsFor: 'accessing'!
  85. model
  86. ^ model
  87. !
  88. model: aBrowserModel
  89. model := aBrowserModel.
  90. self observeModel
  91. ! !
  92. !HLBrowserListWidget methodsFor: 'actions'!
  93. observeModel
  94. !
  95. observeSystem
  96. ! !
  97. !HLBrowserListWidget methodsFor: 'initialization'!
  98. initialize
  99. super initialize.
  100. self observeSystem
  101. ! !
  102. !HLBrowserListWidget class methodsFor: 'instance creation'!
  103. on: aModel
  104. ^ self new
  105. model: aModel;
  106. yourself
  107. ! !
  108. HLBrowserListWidget subclass: #HLClassesListWidget
  109. instanceVariableNames: ''
  110. package: 'Helios-Browser'!
  111. !HLClassesListWidget methodsFor: 'accessing'!
  112. getChildrenOf: aClass
  113. ^ self items select: [ :each | each superclass = aClass ]
  114. !
  115. getRootClassesOf: aCollection
  116. ^ aCollection select: [ :each |
  117. (aCollection includes: each superclass) not ]
  118. !
  119. iconForItem: aClass
  120. ^ aClass theNonMetaClass comment isEmpty
  121. ifFalse: [ 'icon-none' ]
  122. ifTrue: [ 'icon-question-sign' ]
  123. !
  124. showInstance
  125. ^ self model showInstance
  126. ! !
  127. !HLClassesListWidget methodsFor: 'actions'!
  128. focusMethodsListWidget
  129. self model announcer announce: HLMethodsListFocus new
  130. !
  131. focusProtocolsListWidget
  132. self model announcer announce: HLProtocolsListFocus new
  133. !
  134. observeModel
  135. self model announcer
  136. on: HLPackageSelected do: [ :ann | self onPackageSelected: ann item ];
  137. on: HLShowInstanceToggled do: [ :ann | self onShowInstanceToggled ];
  138. on: HLClassSelected do: [ :ann | self onClassSelected: ann item ];
  139. on: HLClassesFocusRequested do: [ :ann | self onClassesFocusRequested ]
  140. !
  141. observeSystem
  142. SystemAnnouncer current
  143. on: ClassAdded
  144. do: [ :ann | self onClassAdded: ann theClass ];
  145. on: ClassRemoved
  146. do: [ :ann | self onClassRemoved: ann theClass ]
  147. !
  148. selectItem: aClass
  149. self model selectedClass: aClass
  150. !
  151. showInstance: aBoolean
  152. self model showInstance: aBoolean
  153. ! !
  154. !HLClassesListWidget methodsFor: 'private'!
  155. setItemsForPackage: aPackage
  156. self items: (aPackage
  157. ifNil: [ #() ]
  158. ifNotNil: [ ((aPackage classes
  159. collect: [ :each | each theNonMetaClass ]) asSet asArray)
  160. sort: [:a :b | a name < b name ] ]).
  161. !
  162. setItemsForSelectedPackage
  163. self setItemsForPackage: self model selectedPackage
  164. ! !
  165. !HLClassesListWidget methodsFor: 'reactions'!
  166. onClassAdded: aClass
  167. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  168. self setItemsForSelectedPackage.
  169. self refresh
  170. !
  171. onClassRemoved: aClass
  172. aClass package = self model selectedPackage ifFalse: [ ^ self ].
  173. aClass = self model selectedClass ifTrue: [ self selectItem: nil ].
  174. self setItemsForSelectedPackage.
  175. self refresh
  176. !
  177. onClassSelected: aClass
  178. self selectedItem: aClass.
  179. aClass ifNil: [ ^ self ].
  180. self focus
  181. !
  182. onClassesFocusRequested
  183. self focus
  184. !
  185. onPackageSelected: aPackage
  186. self selectedItem: nil.
  187. self setItemsForSelectedPackage.
  188. self refresh
  189. !
  190. onShowInstanceToggled
  191. self refresh
  192. ! !
  193. !HLClassesListWidget methodsFor: 'rendering'!
  194. renderButtonsOn: html
  195. html div
  196. class: 'btn-group';
  197. at: 'data-toggle' put: 'buttons-radio';
  198. with: [
  199. html button
  200. class: (String streamContents: [ :str |
  201. str nextPutAll: 'btn'.
  202. self showInstance ifTrue: [
  203. str nextPutAll: ' active'] ]);
  204. with: 'Instance';
  205. onClick: [ self showInstance: true ].
  206. html button
  207. class: (String streamContents: [ :str |
  208. str nextPutAll: 'btn'.
  209. self model showInstance ifFalse: [
  210. str nextPutAll: ' active'] ]);
  211. with: 'Class';
  212. onClick: [ self model showInstance: false ] ].
  213. html button
  214. class: 'btn';
  215. at: 'data-toggle' put: 'button';
  216. with: 'Comment'
  217. !
  218. renderItem: aClass level: anInteger on: html
  219. | li |
  220. li := html li.
  221. li
  222. at: 'list-data' put: (self items indexOf: aClass);
  223. class: (self cssClassForItem: aClass);
  224. with: [
  225. html a
  226. with: [
  227. (html tag: 'i') class: (self iconForItem: aClass).
  228. self renderItemLabel: aClass level: anInteger on: html ];
  229. onClick: [
  230. self activateListItem: li asJQuery ] ].
  231. (self getChildrenOf: aClass) do: [ :each |
  232. self renderItem: each level: anInteger + 1 on: html ]
  233. !
  234. renderItem: aClass on: html
  235. super renderItem: aClass on: html.
  236. (self getChildrenOf: aClass) do: [ :each |
  237. self renderItem: each level: 1 on: html ]
  238. !
  239. renderItemLabel: aClass level: anInteger on: html
  240. html span asJQuery html: (String streamContents: [ :str |
  241. anInteger timesRepeat: [
  242. str nextPutAll: '&nbsp;&nbsp;&nbsp;&nbsp;'].
  243. str nextPutAll: aClass name ])
  244. !
  245. renderItemLabel: aClass on: html
  246. self renderItemLabel: aClass level: 0 on: html
  247. !
  248. renderListOn: html
  249. (self getRootClassesOf: self items)
  250. do: [ :each | self renderItem: each on: html ]
  251. ! !
  252. HLBrowserListWidget subclass: #HLMethodsListWidget
  253. instanceVariableNames: ''
  254. package: 'Helios-Browser'!
  255. !HLMethodsListWidget methodsFor: 'accessing'!
  256. allProtocol
  257. ^ self model allProtocol
  258. !
  259. iconForItem: aSelector
  260. | override overriden method |
  261. method := self methodForSelector: aSelector.
  262. override := self isOverride: method.
  263. overriden := self isOverridden: method.
  264. ^ override
  265. ifTrue: [ overriden
  266. ifTrue: [ 'icon-resize-vertical' ]
  267. ifFalse: [ 'icon-arrow-up' ] ]
  268. ifFalse: [
  269. overriden
  270. ifTrue: [ 'icon-arrow-down' ]
  271. ifFalse: [ 'icon-none' ] ]
  272. !
  273. methodForSelector: aSelector
  274. ^ self model selectedClass
  275. methodDictionary at: aSelector
  276. !
  277. methodsInProtocol: aString
  278. self model selectedClass ifNil: [ ^ #() ].
  279. ^ aString = self allProtocol
  280. ifTrue: [ self model selectedClass methods ]
  281. ifFalse: [ self model selectedClass methodsInProtocol: aString ]
  282. !
  283. overrideSelectors
  284. ^ self selectorsCache
  285. at: 'override'
  286. ifAbsentPut: [
  287. self model selectedClass allSuperclasses
  288. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  289. !
  290. overridenSelectors
  291. ^ self selectorsCache
  292. at: 'overriden'
  293. ifAbsentPut: [
  294. self model selectedClass allSubclasses
  295. inject: Set new into: [ :acc :each | acc addAll: each selectors; yourself ] ]
  296. !
  297. selectorsCache
  298. ^ self class selectorsCache
  299. !
  300. selectorsInProtocol: aString
  301. ^ (self methodsInProtocol: aString)
  302. collect: [ :each | each selector ]
  303. ! !
  304. !HLMethodsListWidget methodsFor: 'actions'!
  305. observeModel
  306. self model announcer
  307. on: HLProtocolSelected
  308. do: [ :ann | self onProtocolSelected: ann item ];
  309. on: HLShowInstanceToggled
  310. do: [ :ann | self onProtocolSelected: nil ];
  311. on: HLMethodSelected
  312. do: [ :ann | self onMethodSelected: ann item ];
  313. on: HLMethodsFocusRequested
  314. do: [ :ann | self onMethodsFocusRequested ]
  315. !
  316. observeSystem
  317. SystemAnnouncer current
  318. on: MethodAdded
  319. do: [ :ann | self onMethodAdded: ann method ];
  320. on: MethodRemoved
  321. do: [ :ann | self onMethodRemoved: ann method ]
  322. !
  323. selectItem: aSelector
  324. aSelector ifNil: [ ^ self model selectedMethod: nil ].
  325. self model selectedMethod: (self methodForSelector: aSelector)
  326. ! !
  327. !HLMethodsListWidget methodsFor: 'cache'!
  328. flushSelectorsCache
  329. selectorsCache := Dictionary new
  330. ! !
  331. !HLMethodsListWidget methodsFor: 'initialization'!
  332. initialize
  333. super initialize.
  334. self flushSelectorsCache
  335. ! !
  336. !HLMethodsListWidget methodsFor: 'private'!
  337. setItemsForProtocol: aString
  338. ^ self items: (aString
  339. ifNil: [ #() ]
  340. ifNotNil: [ self selectorsInProtocol: aString ])
  341. !
  342. setItemsForSelectedProtocol
  343. self setItemsForProtocol: self model selectedProtocol
  344. ! !
  345. !HLMethodsListWidget methodsFor: 'reactions'!
  346. onMethodAdded: aMethod
  347. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  348. self setItemsForSelectedProtocol.
  349. self refresh
  350. !
  351. onMethodRemoved: aMethod
  352. self items detect: [ :each | each = aMethod selector ] ifNone: [ ^ self ].
  353. self selectedItem ifNotNil: [
  354. (aMethod methodClass = self model selectedClass and: [ aMethod selector = self selectedItem selector ])
  355. ifTrue: [ self selectItem: nil ] ].
  356. self setItemsForSelectedProtocol.
  357. self refresh
  358. !
  359. onMethodSelected: aMethod
  360. self selectedItem: aMethod.
  361. aMethod ifNil: [ ^ self ].
  362. self focus
  363. !
  364. onMethodsFocusRequested
  365. self focus
  366. !
  367. onProtocolSelected: aString
  368. self selectedItem: nil.
  369. self setItemsForSelectedProtocol.
  370. self refresh
  371. ! !
  372. !HLMethodsListWidget methodsFor: 'rendering'!
  373. renderContentOn: html
  374. self model showInstance
  375. ifFalse: [ html div
  376. class: 'class_side';
  377. with: [ super renderContentOn: html ] ]
  378. ifTrue: [ super renderContentOn: html ]
  379. !
  380. renderItemLabel: aSelector on: html
  381. html with: aSelector
  382. ! !
  383. !HLMethodsListWidget methodsFor: 'testing'!
  384. isOverridden: aMethod
  385. ^ self selectorsCache isOverridden: aMethod
  386. !
  387. isOverride: aMethod
  388. ^ self selectorsCache isOverride: aMethod
  389. ! !
  390. HLMethodsListWidget class instanceVariableNames: 'selectorsCache'!
  391. !HLMethodsListWidget class methodsFor: 'accessing'!
  392. selectorsCache
  393. ^ HLSelectorsCache current
  394. ! !
  395. HLBrowserListWidget subclass: #HLPackagesListWidget
  396. instanceVariableNames: ''
  397. package: 'Helios-Browser'!
  398. !HLPackagesListWidget methodsFor: 'accessing'!
  399. initializeItems
  400. ^ items := self model packages sort:[:a :b|
  401. a name < b name]
  402. !
  403. items
  404. ^ items ifNil: [self initializeItems]
  405. ! !
  406. !HLPackagesListWidget methodsFor: 'actions'!
  407. focusClassesListWidget
  408. self model announcer announce: HLClassesListFocus new
  409. !
  410. observeModel
  411. self model announcer
  412. on: HLPackageSelected
  413. do: [ :ann | self onPackageSelected: ann item ];
  414. on: HLPackagesFocusRequested
  415. do: [ :ann | self onPackagesFocusRequested ]
  416. !
  417. selectItem: aPackage
  418. self model selectedPackage: aPackage
  419. ! !
  420. !HLPackagesListWidget methodsFor: 'reactions'!
  421. onPackageSelected: aPackage
  422. self selectedItem: aPackage.
  423. self focus
  424. !
  425. onPackagesFocusRequested
  426. self focus
  427. ! !
  428. !HLPackagesListWidget methodsFor: 'rendering'!
  429. renderButtonsOn: html
  430. html span class: 'info'; with: 'Auto commit'.
  431. html div
  432. class: 'btn-group switch';
  433. at: 'data-toggle' put: 'buttons-radio';
  434. with: [
  435. html button
  436. class: (String streamContents: [ :str |
  437. str nextPutAll: 'btn' ]);
  438. with: 'On'.
  439. html button
  440. class: (String streamContents: [ :str |
  441. str nextPutAll: 'btn active' ]);
  442. with: 'Off' ].
  443. html a
  444. class: 'btn';
  445. with: 'Commit'.
  446. ! !
  447. HLBrowserListWidget subclass: #HLProtocolsListWidget
  448. instanceVariableNames: ''
  449. package: 'Helios-Browser'!
  450. !HLProtocolsListWidget methodsFor: 'accessing'!
  451. allProtocol
  452. ^ self model allProtocol
  453. !
  454. selectedItem
  455. ^ super selectedItem" ifNil: [ self allProtocol ]"
  456. ! !
  457. !HLProtocolsListWidget methodsFor: 'actions'!
  458. observeModel
  459. self model announcer
  460. on: HLClassSelected
  461. do: [ :ann | self onClassSelected: ann item ];
  462. on: HLShowInstanceToggled
  463. do: [ :ann | self onClassSelected: self model selectedClass ];
  464. on: HLProtocolSelected
  465. do: [ :ann | self onProtocolSelected: ann item ];
  466. on: HLProtocolsFocusRequested
  467. do: [ :ann | self onProtocolsFocusRequested ]
  468. !
  469. observeSystem
  470. SystemAnnouncer current
  471. on: ProtocolAdded
  472. do: [ :ann | self onProtocolAdded: ann protocol to: ann theClass ];
  473. on: ProtocolRemoved
  474. do: [ :ann | self onProtocolRemoved: ann protocol from: ann theClass ]
  475. !
  476. selectItem: aString
  477. self model selectedProtocol: aString
  478. ! !
  479. !HLProtocolsListWidget methodsFor: 'private'!
  480. setItemsForClass: aClass
  481. self items: (aClass
  482. ifNil: [ Array with: self allProtocol ]
  483. ifNotNil: [
  484. (Array with: self allProtocol)
  485. addAll: aClass protocols;
  486. yourself ])
  487. !
  488. setItemsForSelectedClass
  489. self setItemsForClass: self model selectedClass
  490. ! !
  491. !HLProtocolsListWidget methodsFor: 'reactions'!
  492. onClassSelected: aClass
  493. self selectedItem: nil.
  494. self setItemsForSelectedClass.
  495. self refresh
  496. !
  497. onProtocolAdded: aString to: aClass
  498. aClass = self model selectedClass ifFalse: [ ^ self ].
  499. self setItemsForSelectedClass.
  500. self refresh
  501. !
  502. onProtocolRemoved: aString from: aClass
  503. aClass = self model selectedClass ifFalse: [ ^ self ].
  504. self model selectedProtocol = aString
  505. ifTrue: [ self selectItem: nil ].
  506. self setItemsForSelectedClass.
  507. self refresh
  508. !
  509. onProtocolSelected: aString
  510. self selectedItem: aString.
  511. aString ifNil: [ ^ self ].
  512. self focus
  513. !
  514. onProtocolsFocusRequested
  515. self focus
  516. ! !
  517. !HLProtocolsListWidget methodsFor: 'rendering'!
  518. renderContentOn: html
  519. self model showInstance
  520. ifFalse: [ html div
  521. class: 'class_side';
  522. with: [ super renderContentOn: html ] ]
  523. ifTrue: [ super renderContentOn: html ]
  524. ! !
  525. Object subclass: #HLBrowserModel
  526. instanceVariableNames: 'announcer environment selectedPackage selectedClass selectedProtocol selectedSelector showInstance showComment'
  527. package: 'Helios-Browser'!
  528. !HLBrowserModel methodsFor: 'accessing'!
  529. allProtocol
  530. ^ '-- All --'
  531. !
  532. announcer
  533. ^ announcer ifNil: [ announcer := Announcer new ]
  534. !
  535. environment
  536. ^ environment ifNil: [ HLManager current environment ]
  537. !
  538. environment: anEnvironment
  539. environment := anEnvironment
  540. !
  541. packages
  542. ^ self environment packages
  543. !
  544. selectedClass
  545. ^ selectedClass
  546. !
  547. selectedClass: aClass
  548. selectedClass = aClass ifTrue: [ ^ self ].
  549. aClass
  550. ifNil: [ selectedClass := nil ]
  551. ifNotNil: [
  552. self showInstance
  553. ifTrue: [ selectedClass := aClass theNonMetaClass ]
  554. ifFalse: [ selectedClass := aClass theMetaClass ] ].
  555. self selectedProtocol: nil.
  556. self announcer announce: (HLClassSelected on: self selectedClass)
  557. !
  558. selectedMethod
  559. ^ self selectedClass
  560. ifNotNil: [ self selectedClass methodDictionary at: selectedSelector ]
  561. !
  562. selectedMethod: aCompiledMethod
  563. selectedSelector = aCompiledMethod ifTrue: [ ^ self ].
  564. aCompiledMethod
  565. ifNil: [ selectedSelector := nil ]
  566. ifNotNil: [
  567. selectedSelector = aCompiledMethod selector ifTrue: [ ^ self ].
  568. selectedSelector := aCompiledMethod selector ].
  569. self announcer announce: (HLMethodSelected on: aCompiledMethod)
  570. !
  571. selectedPackage
  572. ^ selectedPackage
  573. !
  574. selectedPackage: aPackage
  575. selectedPackage = aPackage ifTrue: [ ^ self ].
  576. selectedPackage := aPackage.
  577. self selectedClass: nil.
  578. self announcer announce: (HLPackageSelected on: aPackage)
  579. !
  580. selectedProtocol
  581. ^ selectedProtocol
  582. !
  583. selectedProtocol: aString
  584. selectedProtocol = aString ifTrue: [ ^ self ].
  585. selectedProtocol := aString.
  586. self selectedMethod: nil.
  587. self announcer announce: (HLProtocolSelected on: aString)
  588. !
  589. showComment
  590. ^ showComment ifNil: [ false ]
  591. !
  592. showComment: aBoolean
  593. showComment := aBoolean.
  594. self announcer announce: HLShowCommentToggled new
  595. !
  596. showInstance
  597. ^ showInstance ifNil: [ true ]
  598. !
  599. showInstance: aBoolean
  600. showInstance := aBoolean.
  601. self selectedClass ifNotNil: [
  602. self selectedClass: (aBoolean
  603. ifTrue: [self selectedClass theNonMetaClass ]
  604. ifFalse: [ self selectedClass theMetaClass ]) ].
  605. self announcer announce: HLShowInstanceToggled new
  606. ! !
  607. !HLBrowserModel methodsFor: 'actions'!
  608. focusOnClasses
  609. self announcer announce: HLClassesFocusRequested new
  610. !
  611. focusOnMethods
  612. self announcer announce: HLMethodsFocusRequested new
  613. !
  614. focusOnPackages
  615. self announcer announce: HLPackagesFocusRequested new
  616. !
  617. focusOnProtocols
  618. self announcer announce: HLProtocolsFocusRequested new
  619. !
  620. focusOnSourceCode
  621. self announcer announce: HLSourceCodeFocusRequested new
  622. ! !
  623. !HLBrowserModel class methodsFor: 'actions'!
  624. on: anEnvironment
  625. ^ self new
  626. environment: anEnvironment;
  627. yourself
  628. ! !
  629. HLWidget subclass: #HLBrowserSourceWidget
  630. instanceVariableNames: 'model methodContents codeWidget'
  631. package: 'Helios-Browser'!
  632. !HLBrowserSourceWidget methodsFor: 'accessing'!
  633. codeWidget
  634. ^ codeWidget ifNil: [ codeWidget := HLCodeWidget new ]
  635. !
  636. contents
  637. ^ self codeWidget contents
  638. !
  639. contents: aString
  640. self methodContents: aString.
  641. self codeWidget contents: aString
  642. !
  643. methodContents
  644. ^ methodContents ifNil: [ methodContents := '' ]
  645. !
  646. methodContents: aString
  647. methodContents := aString
  648. !
  649. model
  650. ^ model
  651. !
  652. model: aBrowserModel
  653. model := aBrowserModel.
  654. self observeModel
  655. ! !
  656. !HLBrowserSourceWidget methodsFor: 'actions'!
  657. focus
  658. self codeWidget focus
  659. !
  660. observeModel
  661. self model announcer
  662. on: HLMethodSelected
  663. do: [ :ann | self onMethodSelected: ann item ];
  664. on: HLClassSelected
  665. do: [ :ann | self onClassSelected: ann item ];
  666. on: HLProtocolSelected
  667. do: [ :ann | self onProtocolSelected: ann item ];
  668. on: HLSourceCodeFocusRequested
  669. do: [ :ann | self onSourceCodeFocusRequested ]
  670. !
  671. observeSystem
  672. SystemAnnouncer current
  673. on: MethodModified
  674. do: [ :ann | self onMethodModified: ann method ]
  675. ! !
  676. !HLBrowserSourceWidget methodsFor: 'initialization'!
  677. initialize
  678. super initialize.
  679. self observeSystem
  680. ! !
  681. !HLBrowserSourceWidget methodsFor: 'reactions'!
  682. onClassSelected: aClass
  683. aClass ifNil: [ ^ self contents: '' ].
  684. self contents: aClass definition
  685. !
  686. onMethodModified: aMethod
  687. self model selectedClass = aMethod methodClass ifFalse: [ ^ self ].
  688. self model selectedMethod selector = aMethod selector ifFalse: [ ^ self ].
  689. self refresh
  690. !
  691. onMethodSelected: aCompiledMethod
  692. aCompiledMethod ifNil: [ ^ self contents: '' ].
  693. self contents: aCompiledMethod source
  694. !
  695. onProtocolSelected: aString
  696. self model selectedClass ifNil: [ ^ self contents: '' ].
  697. self contents: self model selectedClass definition
  698. !
  699. onSourceCodeFocusRequested
  700. self focus
  701. ! !
  702. !HLBrowserSourceWidget methodsFor: 'rendering'!
  703. renderContentOn: html
  704. self codeWidget renderOn: html
  705. ! !
  706. !HLBrowserSourceWidget methodsFor: 'testing'!
  707. hasModification
  708. ^ (self methodContents = self contents) not
  709. ! !
  710. !HLBrowserSourceWidget methodsFor: 'updating'!
  711. refresh
  712. self hasModification ifTrue: [ ^ self ].
  713. self contents: self model selectedMethod source.
  714. super refresh
  715. ! !
  716. !HLBrowserSourceWidget class methodsFor: 'instance creation'!
  717. on: aBrowserModel
  718. ^ self new
  719. model: aBrowserModel;
  720. yourself
  721. ! !
  722. Object subclass: #HLClassCache
  723. instanceVariableNames: 'class selectorsCache overrideCache overriddenCache'
  724. package: 'Helios-Browser'!
  725. !HLClassCache methodsFor: 'accessing'!
  726. overriddenCache
  727. ^ overriddenCache ifNil: [ overriddenCache := HashedCollection new ]
  728. !
  729. overrideCache
  730. ^ overrideCache ifNil: [ overrideCache := HashedCollection new ]
  731. !
  732. selectorsCache
  733. ^ selectorsCache
  734. !
  735. selectorsCache: aCache
  736. selectorsCache := aCache
  737. !
  738. theClass
  739. ^ class
  740. !
  741. theClass: aClass
  742. class := aClass
  743. ! !
  744. !HLClassCache methodsFor: 'actions'!
  745. invalidateChildrenSelector: aSelector
  746. self theClass subclasses do: [ :each |
  747. (self selectorsCache cacheFor: each)
  748. removeSelector: aSelector;
  749. invalidateChildrenSelector: aSelector ]
  750. !
  751. invalidateParentSelector: aSelector
  752. self theClass superclass ifNotNil: [
  753. (self selectorsCache cacheFor: self theClass superclass)
  754. removeSelector: aSelector;
  755. invalidateParentSelector: aSelector ]
  756. !
  757. invalidateSelector: aSelector
  758. self
  759. invalidateParentSelector: aSelector;
  760. invalidateChildrenSelector: aSelector;
  761. removeSelector: aSelector
  762. ! !
  763. !HLClassCache methodsFor: 'private'!
  764. removeSelector: aSelector
  765. self overriddenCache
  766. removeKey: aSelector
  767. ifAbsent: [ ].
  768. self overrideCache
  769. removeKey: aSelector
  770. ifAbsent: [ ]
  771. ! !
  772. !HLClassCache methodsFor: 'testing'!
  773. isOverridden: aMethod
  774. ^ self overriddenCache
  775. at: aMethod selector
  776. ifAbsentPut: [ aMethod isOverridden ]
  777. !
  778. isOverride: aMethod
  779. ^ self overrideCache
  780. at: aMethod selector
  781. ifAbsentPut: [ aMethod isOverride ]
  782. ! !
  783. !HLClassCache class methodsFor: 'instance creation'!
  784. on: aClass selectorsCache: aSelectorsCache
  785. ^ self new
  786. theClass: aClass;
  787. selectorsCache: aSelectorsCache;
  788. yourself
  789. ! !
  790. Object subclass: #HLSelectorsCache
  791. instanceVariableNames: 'classesCache'
  792. package: 'Helios-Browser'!
  793. !HLSelectorsCache methodsFor: 'accessing'!
  794. cacheFor: aClass
  795. aClass ifNil: [ ^ nil ].
  796. ^ self classesCache
  797. at: aClass name
  798. ifAbsentPut: [ self newCacheFor: aClass ]
  799. !
  800. classesCache
  801. ^ classesCache ifNil: [ classesCache := HashedCollection new ]
  802. ! !
  803. !HLSelectorsCache methodsFor: 'actions'!
  804. observeSystem
  805. SystemAnnouncer current
  806. on: MethodAdded
  807. do: [ :ann | self onMethodAdded: ann method ];
  808. on: MethodRemoved
  809. do: [ :ann | self onMethodRemoved: ann method ]
  810. ! !
  811. !HLSelectorsCache methodsFor: 'factory'!
  812. newCacheFor: aClass
  813. ^ HLClassCache
  814. on: aClass
  815. selectorsCache: self
  816. ! !
  817. !HLSelectorsCache methodsFor: 'initialization'!
  818. initialize
  819. super initialize.
  820. self observeSystem
  821. ! !
  822. !HLSelectorsCache methodsFor: 'private'!
  823. invalidateCacheFor: aMethod
  824. (self cacheFor: aMethod methodClass)
  825. invalidateSelector: aMethod selector
  826. ! !
  827. !HLSelectorsCache methodsFor: 'reactions'!
  828. onMethodAdded: aMethod
  829. self invalidateCacheFor: aMethod
  830. !
  831. onMethodRemoved: aMethod
  832. self invalidateCacheFor: aMethod
  833. ! !
  834. !HLSelectorsCache methodsFor: 'testing'!
  835. isOverridden: aMethod
  836. ^ (self cacheFor: aMethod methodClass)
  837. isOverridden: aMethod
  838. !
  839. isOverride: aMethod
  840. ^ (self cacheFor: aMethod methodClass)
  841. isOverride: aMethod
  842. ! !
  843. HLSelectorsCache class instanceVariableNames: 'current'!
  844. !HLSelectorsCache class methodsFor: 'accessing'!
  845. current
  846. ^ current ifNil: [ current := super new ]
  847. !
  848. flush
  849. current := nil
  850. ! !
  851. !HLSelectorsCache class methodsFor: 'instance creation'!
  852. new
  853. self shouldNotImplement
  854. ! !
  855. !CompiledMethod methodsFor: '*Helios-Browser'!
  856. isOverridden
  857. | selector |
  858. selector := self selector.
  859. self methodClass allSubclassesDo: [ :each |
  860. (each includesSelector: selector)
  861. ifTrue: [ ^ true ] ].
  862. ^ false
  863. !
  864. isOverride
  865. | superclass |
  866. superclass := self methodClass superclass.
  867. superclass ifNil: [ ^ false ].
  868. ^ (self methodClass superclass lookupSelector: self selector) notNil
  869. ! !